Re-Init... try this again xD
This commit is contained in:
parent
0d76ded82a
commit
ecb94d1ca8
2
pom.xml
2
pom.xml
|
@ -4,7 +4,7 @@
|
|||
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>me.nvus.xprison</groupId>
|
||||
<groupId>dev.drawethree.xprison</groupId>
|
||||
<artifactId>X-Prison</artifactId>
|
||||
<version>1.12.16</version>
|
||||
|
||||
|
|
|
@ -1,466 +0,0 @@
|
|||
package me.nvus.xprison;
|
||||
|
||||
import com.github.lalyos.jfiglet.FigletFont;
|
||||
import me.nvus.xprison.autominer.XPrisonAutoMiner;
|
||||
import me.nvus.xprison.autosell.XPrisonAutoSell;
|
||||
import me.nvus.xprison.config.FileManager;
|
||||
import me.nvus.xprison.database.SQLDatabase;
|
||||
import me.nvus.xprison.database.impl.MySQLDatabase;
|
||||
import me.nvus.xprison.database.impl.SQLiteDatabase;
|
||||
import me.nvus.xprison.database.model.ConnectionProperties;
|
||||
import me.nvus.xprison.database.model.DatabaseCredentials;
|
||||
import me.nvus.xprison.enchants.XPrisonEnchants;
|
||||
import me.nvus.xprison.gangs.XPrisonGangs;
|
||||
import me.nvus.xprison.gems.XPrisonGems;
|
||||
import me.nvus.xprison.history.XPrisonHistory;
|
||||
import me.nvus.xprison.mainmenu.MainMenu;
|
||||
import me.nvus.xprison.mainmenu.help.HelpGui;
|
||||
import me.nvus.xprison.migrator.ItemMigrator;
|
||||
import me.nvus.xprison.mines.XPrisonMines;
|
||||
import me.nvus.xprison.multipliers.XPrisonMultipliers;
|
||||
import me.nvus.xprison.nicknames.repo.NicknameRepository;
|
||||
import me.nvus.xprison.nicknames.repo.impl.NicknameRepositoryImpl;
|
||||
import me.nvus.xprison.nicknames.service.NicknameService;
|
||||
import me.nvus.xprison.nicknames.service.impl.NicknameServiceImpl;
|
||||
import me.nvus.xprison.pickaxelevels.XPrisonPickaxeLevels;
|
||||
import me.nvus.xprison.placeholders.XPrisonMVdWPlaceholder;
|
||||
import me.nvus.xprison.placeholders.XPrisonPAPIPlaceholder;
|
||||
import me.nvus.xprison.prestiges.XPrisonPrestiges;
|
||||
import me.nvus.xprison.ranks.XPrisonRanks;
|
||||
import me.nvus.xprison.tokens.XPrisonTokens;
|
||||
import me.nvus.xprison.utils.Constants;
|
||||
import me.nvus.xprison.utils.compat.CompMaterial;
|
||||
import me.nvus.xprison.utils.misc.SkullUtils;
|
||||
import me.nvus.xprison.utils.text.TextUtils;
|
||||
import lombok.Getter;
|
||||
import me.lucko.helper.Commands;
|
||||
import me.lucko.helper.Events;
|
||||
import me.lucko.helper.plugin.ExtendedJavaPlugin;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import me.nvus.xprison.utils.Metrics;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.codemc.worldguardwrapper.WorldGuardWrapper;
|
||||
import org.codemc.worldguardwrapper.flag.WrappedState;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Getter
|
||||
public final class XPrison extends ExtendedJavaPlugin {
|
||||
|
||||
private static XPrison instance;
|
||||
|
||||
private boolean debugMode;
|
||||
private Map<String, XPrisonModule> modules;
|
||||
private SQLDatabase pluginDatabase;
|
||||
private Economy economy;
|
||||
private FileManager fileManager;
|
||||
private XPrisonTokens tokens;
|
||||
private XPrisonGems gems;
|
||||
private XPrisonRanks ranks;
|
||||
private XPrisonPrestiges prestiges;
|
||||
private XPrisonMultipliers multipliers;
|
||||
private XPrisonEnchants enchants;
|
||||
private XPrisonAutoSell autoSell;
|
||||
private XPrisonAutoMiner autoMiner;
|
||||
private XPrisonPickaxeLevels pickaxeLevels;
|
||||
private XPrisonGangs gangs;
|
||||
private XPrisonMines mines;
|
||||
private XPrisonHistory history;
|
||||
|
||||
private ItemMigrator itemMigrator;
|
||||
|
||||
private List<Material> supportedPickaxes;
|
||||
|
||||
private NicknameService nicknameService;
|
||||
|
||||
|
||||
@Override
|
||||
protected void load() {
|
||||
instance = this;
|
||||
registerWGFlag();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void enable() {
|
||||
|
||||
this.printOnEnableMessage();
|
||||
this.modules = new LinkedHashMap<>();
|
||||
this.fileManager = new FileManager(this);
|
||||
this.fileManager.getConfig("config.yml").copyDefaults(true).save();
|
||||
this.debugMode = this.getConfig().getBoolean("debug-mode", false);
|
||||
|
||||
// All you have to do is adding the following two lines in your onEnable method.
|
||||
// You can find the plugin ids of your plugins on the page https://bstats.org/what-is-my-plugin-id
|
||||
int pluginId = 10520; // <-- Replace with the id of your plugin!
|
||||
Metrics metrics = new Metrics(this, pluginId);
|
||||
|
||||
if (!this.initDatabase()) {
|
||||
this.getServer().getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.setupEconomy()) {
|
||||
this.getLogger().warning("Economy provider for Vault not found! Economy provider is strictly required. Disabling plugin...");
|
||||
this.getServer().getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
} else {
|
||||
this.getLogger().info("Economy provider for Vault found - " + this.getEconomy().getName());
|
||||
}
|
||||
|
||||
this.initVariables();
|
||||
this.initModules();
|
||||
this.loadModules();
|
||||
|
||||
this.itemMigrator = new ItemMigrator(this);
|
||||
this.itemMigrator.reload();
|
||||
|
||||
this.initNicknameService();
|
||||
|
||||
this.registerPlaceholders();
|
||||
|
||||
this.registerMainEvents();
|
||||
this.registerMainCommand();
|
||||
this.startMetrics();
|
||||
|
||||
SkullUtils.init();
|
||||
}
|
||||
|
||||
private void printOnEnableMessage() {
|
||||
try {
|
||||
this.getLogger().info(FigletFont.convertOneLine("X-PRISON"));
|
||||
this.getLogger().info(this.getDescription().getVersion());
|
||||
this.getLogger().info("By: " + this.getDescription().getAuthors());
|
||||
this.getLogger().info("Website: " + this.getDescription().getWebsite());
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
private void initNicknameService() {
|
||||
NicknameRepository nicknameRepository = new NicknameRepositoryImpl(this.getPluginDatabase());
|
||||
nicknameRepository.createTables();
|
||||
this.nicknameService = new NicknameServiceImpl(nicknameRepository);
|
||||
}
|
||||
|
||||
private void initVariables() {
|
||||
this.supportedPickaxes = this.getConfig().getStringList("supported-pickaxes").stream().map(CompMaterial::fromString).map(CompMaterial::getMaterial).collect(Collectors.toList());
|
||||
|
||||
for (Material m : this.supportedPickaxes) {
|
||||
this.getLogger().info("Added support for pickaxe: " + m);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadModules() {
|
||||
if (this.getConfig().getBoolean("modules.tokens")) {
|
||||
this.loadModule(tokens);
|
||||
}
|
||||
|
||||
if (this.getConfig().getBoolean("modules.gems")) {
|
||||
this.loadModule(gems);
|
||||
}
|
||||
|
||||
if (this.getConfig().getBoolean("modules.ranks")) {
|
||||
this.loadModule(ranks);
|
||||
}
|
||||
|
||||
if (this.getConfig().getBoolean("modules.prestiges")) {
|
||||
this.loadModule(prestiges);
|
||||
}
|
||||
|
||||
if (this.getConfig().getBoolean("modules.multipliers")) {
|
||||
this.loadModule(multipliers);
|
||||
}
|
||||
|
||||
if (this.getConfig().getBoolean("modules.autosell")) {
|
||||
if (isUltraBackpacksEnabled()) {
|
||||
this.getLogger().info("Module AutoSell will not be loaded because selling system is handled by UltraBackpacks.");
|
||||
} else {
|
||||
this.loadModule(autoSell);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.getConfig().getBoolean("modules.mines")) {
|
||||
this.loadModule(mines);
|
||||
}
|
||||
|
||||
if (this.getConfig().getBoolean("modules.enchants")) {
|
||||
this.loadModule(enchants);
|
||||
}
|
||||
if (this.getConfig().getBoolean("modules.autominer")) {
|
||||
this.loadModule(autoMiner);
|
||||
}
|
||||
if (this.getConfig().getBoolean("modules.gangs")) {
|
||||
this.loadModule(gangs);
|
||||
}
|
||||
if (this.getConfig().getBoolean("modules.pickaxe_levels")) {
|
||||
if (!this.isModuleEnabled("Enchants")) {
|
||||
this.getLogger().warning(TextUtils.applyColor("&cX-Prison - Module 'Pickaxe Levels' requires to have enchants module enabled."));
|
||||
} else {
|
||||
this.loadModule(pickaxeLevels);
|
||||
}
|
||||
}
|
||||
if (this.getConfig().getBoolean("modules.history")) {
|
||||
this.loadModule(history);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean initDatabase() {
|
||||
try {
|
||||
String databaseType = this.getConfig().getString("database_type");
|
||||
ConnectionProperties connectionProperties = ConnectionProperties.fromConfig(this.getConfig());
|
||||
|
||||
if ("sqlite".equalsIgnoreCase(databaseType)) {
|
||||
this.pluginDatabase = new SQLiteDatabase(this, connectionProperties);
|
||||
this.getLogger().info("Using SQLite (local) database.");
|
||||
} else if ("mysql".equalsIgnoreCase(databaseType)) {
|
||||
DatabaseCredentials credentials = DatabaseCredentials.fromConfig(this.getConfig());
|
||||
this.pluginDatabase = new MySQLDatabase(this, credentials, connectionProperties);
|
||||
this.getLogger().info("Using MySQL (remote) database.");
|
||||
} else {
|
||||
this.getLogger().warning(String.format("Error! Unknown database type: %s. Disabling plugin.", databaseType));
|
||||
this.getServer().getPluginManager().disablePlugin(this);
|
||||
return false;
|
||||
}
|
||||
|
||||
this.pluginDatabase.connect();
|
||||
} catch (Exception e) {
|
||||
this.getLogger().warning("Could not maintain Database Connection. Disabling plugin.");
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void initModules() {
|
||||
this.tokens = new XPrisonTokens(this);
|
||||
this.gems = new XPrisonGems(this);
|
||||
this.ranks = new XPrisonRanks(this);
|
||||
this.prestiges = new XPrisonPrestiges(this);
|
||||
this.multipliers = new XPrisonMultipliers(this);
|
||||
this.enchants = new XPrisonEnchants(this);
|
||||
this.autoSell = new XPrisonAutoSell(this);
|
||||
this.autoMiner = new XPrisonAutoMiner(this);
|
||||
this.pickaxeLevels = new XPrisonPickaxeLevels(this);
|
||||
this.gangs = new XPrisonGangs(this);
|
||||
this.mines = new XPrisonMines(this);
|
||||
this.history = new XPrisonHistory(this);
|
||||
|
||||
this.modules.put(this.tokens.getName().toLowerCase(), this.tokens);
|
||||
this.modules.put(this.gems.getName().toLowerCase(), this.gems);
|
||||
this.modules.put(this.ranks.getName().toLowerCase(), this.ranks);
|
||||
this.modules.put(this.prestiges.getName().toLowerCase(), this.prestiges);
|
||||
this.modules.put(this.multipliers.getName().toLowerCase(), this.multipliers);
|
||||
this.modules.put(this.enchants.getName().toLowerCase(), this.enchants);
|
||||
this.modules.put(this.autoSell.getName().toLowerCase(), this.autoSell);
|
||||
this.modules.put(this.autoMiner.getName().toLowerCase(), this.autoMiner);
|
||||
this.modules.put(this.pickaxeLevels.getName().toLowerCase(), this.pickaxeLevels);
|
||||
this.modules.put(this.gangs.getName().toLowerCase(), this.gangs);
|
||||
this.modules.put(this.mines.getName().toLowerCase(), this.mines);
|
||||
this.modules.put(this.history.getName().toLowerCase(), this.history);
|
||||
}
|
||||
|
||||
private void registerMainEvents() {
|
||||
//Updating of mapping table
|
||||
Events.subscribe(PlayerJoinEvent.class, EventPriority.LOW)
|
||||
.handler(e -> {
|
||||
this.nicknameService.updatePlayerNickname(e.getPlayer());
|
||||
}).bindWith(this);
|
||||
}
|
||||
|
||||
private void startMetrics() {
|
||||
new Metrics(this, Constants.METRICS_SERVICE_ID);
|
||||
}
|
||||
|
||||
private void loadModule(XPrisonModule module) {
|
||||
if (module.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
module.enable();
|
||||
this.getLogger().info(TextUtils.applyColor(String.format("&aX-Prison - Module %s loaded.", module.getName())));
|
||||
}
|
||||
|
||||
//Always unload via iterator!
|
||||
private void unloadModule(XPrisonModule module) {
|
||||
if (!module.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
module.disable();
|
||||
this.getLogger().info(TextUtils.applyColor(String.format("&aX-Prison - Module %s unloaded.", module.getName())));
|
||||
}
|
||||
|
||||
public void debug(String msg, XPrisonModule module) {
|
||||
if (!this.debugMode) {
|
||||
return;
|
||||
}
|
||||
if (module != null) {
|
||||
this.getLogger().info(String.format("[%s] %s", module.getName(), TextUtils.applyColor(msg)));
|
||||
} else {
|
||||
this.getLogger().info(TextUtils.applyColor(msg));
|
||||
}
|
||||
}
|
||||
|
||||
public void reloadModule(XPrisonModule module) {
|
||||
if (!module.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
module.reload();
|
||||
this.getLogger().info(TextUtils.applyColor(String.format("X-Prison - Module %s reloaded.", module.getName())));
|
||||
}
|
||||
|
||||
private void registerMainCommand() {
|
||||
|
||||
List<String> commandAliases = this.getConfig().getStringList("main-command-aliases");
|
||||
String[] commandAliasesArray = commandAliases.toArray(new String[commandAliases.size()]);
|
||||
|
||||
Commands.create()
|
||||
.assertPermission("xprison.admin")
|
||||
.handler(c -> {
|
||||
if (c.args().size() == 0 && c.sender() instanceof Player) {
|
||||
new MainMenu(this, (Player) c.sender()).open();
|
||||
} else if (c.args().size() >= 1) {
|
||||
if ("reload".equalsIgnoreCase(c.rawArg(0))) {
|
||||
final String name = c.args().size() >= 2 ? c.rawArg(1).trim().toLowerCase().replace("-", "") : "all";
|
||||
switch (name) {
|
||||
case "all":
|
||||
case "*":
|
||||
getModules().forEach(this::reloadModule);
|
||||
getItemMigrator().reload();
|
||||
c.sender().sendMessage(TextUtils.applyColor("&aSuccessfully reloaded all the plugin"));
|
||||
break;
|
||||
case "migrator":
|
||||
case "itemmigrator":
|
||||
getItemMigrator().reload();
|
||||
c.sender().sendMessage(TextUtils.applyColor("&aSuccessfully reloaded item migrator"));
|
||||
break;
|
||||
default:
|
||||
final XPrisonModule module = modules.get(name);
|
||||
if (module != null) {
|
||||
reloadModule(module);
|
||||
c.sender().sendMessage(TextUtils.applyColor("&aSuccessfully reloaded &f" + name + " &amodule"));
|
||||
} else {
|
||||
c.sender().sendMessage(TextUtils.applyColor("&cThe module &6" + c.rawArg(1) + " &cdoesn't exist"));
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else if (c.sender() instanceof Player && "help".equalsIgnoreCase(c.rawArg(0)) || "?".equalsIgnoreCase(c.rawArg(0))) {
|
||||
new HelpGui((Player) c.sender()).open();
|
||||
}
|
||||
}
|
||||
}).registerAndBind(this, commandAliasesArray);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void disable() {
|
||||
|
||||
Iterator<XPrisonModule> it = this.modules.values().iterator();
|
||||
|
||||
while (it.hasNext()) {
|
||||
this.unloadModule(it.next());
|
||||
it.remove();
|
||||
}
|
||||
|
||||
if (this.pluginDatabase != null) {
|
||||
if (this.pluginDatabase instanceof SQLDatabase) {
|
||||
SQLDatabase sqlDatabase = (SQLDatabase) this.pluginDatabase;
|
||||
sqlDatabase.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean isModuleEnabled(String moduleName) {
|
||||
XPrisonModule module = this.modules.get(moduleName.toLowerCase());
|
||||
return module != null && module.isEnabled();
|
||||
}
|
||||
|
||||
private void registerPlaceholders() {
|
||||
|
||||
if (isMVdWPlaceholderAPIEnabled()) {
|
||||
new XPrisonMVdWPlaceholder(this).register();
|
||||
}
|
||||
|
||||
if (isPlaceholderAPIEnabled()) {
|
||||
new XPrisonPAPIPlaceholder(this).register();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean setupEconomy() {
|
||||
|
||||
if (getServer().getPluginManager().getPlugin("Vault") == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
|
||||
|
||||
if (rsp == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
economy = rsp.getProvider();
|
||||
return economy != null;
|
||||
}
|
||||
|
||||
public boolean isPickaxeSupported(Material m) {
|
||||
return this.supportedPickaxes.contains(m);
|
||||
}
|
||||
|
||||
public boolean isPickaxeSupported(ItemStack item) {
|
||||
return item != null && isPickaxeSupported(item.getType());
|
||||
}
|
||||
|
||||
public Collection<XPrisonModule> getModules() {
|
||||
return this.modules.values();
|
||||
}
|
||||
|
||||
public boolean isDebugMode() {
|
||||
return debugMode;
|
||||
}
|
||||
|
||||
public void setDebugMode(boolean enabled) {
|
||||
this.debugMode = enabled;
|
||||
this.getConfig().set("debug-mode", debugMode);
|
||||
this.saveConfig();
|
||||
}
|
||||
|
||||
public boolean isUltraBackpacksEnabled() {
|
||||
return this.getServer().getPluginManager().isPluginEnabled("UltraBackpacks");
|
||||
}
|
||||
|
||||
public boolean isPlaceholderAPIEnabled() {
|
||||
return this.getServer().getPluginManager().isPluginEnabled("PlaceholderAPI");
|
||||
}
|
||||
|
||||
public boolean isMVdWPlaceholderAPIEnabled() {
|
||||
return this.getServer().getPluginManager().isPluginEnabled("MVdWPlaceholderAPI");
|
||||
}
|
||||
|
||||
private void registerWGFlag() {
|
||||
|
||||
if (Bukkit.getPluginManager().getPlugin("WorldGuard") == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
getWorldGuardWrapper().registerFlag(Constants.ENCHANTS_WG_FLAG_NAME, WrappedState.class, WrappedState.DENY);
|
||||
} catch (IllegalStateException e) {
|
||||
// This happens during plugin reloads. Flag cannot be registered as WG was already loaded,
|
||||
// so we can safely ignore this exception.
|
||||
}
|
||||
}
|
||||
|
||||
public static XPrison getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public WorldGuardWrapper getWorldGuardWrapper() {
|
||||
return WorldGuardWrapper.getInstance();
|
||||
}
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
package me.nvus.xprison;
|
||||
|
||||
public interface XPrisonModule {
|
||||
|
||||
void enable();
|
||||
|
||||
void disable();
|
||||
|
||||
void reload();
|
||||
|
||||
boolean isEnabled();
|
||||
|
||||
String getName();
|
||||
|
||||
boolean isHistoryEnabled();
|
||||
|
||||
void resetPlayerData();
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
package me.nvus.xprison.api.enums;
|
||||
|
||||
public enum LostCause {
|
||||
|
||||
/**
|
||||
* Player lost currency by pay command
|
||||
*/
|
||||
PAY,
|
||||
/**
|
||||
* Player lost currency by enchanting
|
||||
*/
|
||||
ENCHANT,
|
||||
/**
|
||||
* Player lost currency by prestiging
|
||||
*/
|
||||
PRESTIGE,
|
||||
/**
|
||||
* Player lost currency by rank up
|
||||
*/
|
||||
RANKUP,
|
||||
/**
|
||||
* Player lost currency by admin running command
|
||||
*/
|
||||
ADMIN,
|
||||
/**
|
||||
* Player lost currency by withdrawing to physical form
|
||||
*/
|
||||
WITHDRAW,
|
||||
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
package me.nvus.xprison.api.enums;
|
||||
|
||||
/**
|
||||
* ReceiveCause enum for Gems and Tokens events.
|
||||
*/
|
||||
public enum ReceiveCause {
|
||||
/**
|
||||
* Player received currency during mining (himself)
|
||||
*/
|
||||
MINING,
|
||||
/**
|
||||
* Player received currency by pay command
|
||||
*/
|
||||
PAY,
|
||||
/**
|
||||
* Player received currency by give command
|
||||
*/
|
||||
GIVE,
|
||||
/**
|
||||
* Player received currency by redeeming items
|
||||
*/
|
||||
REDEEM,
|
||||
/**
|
||||
* Player received currency by breaking lucky blocks
|
||||
*/
|
||||
LUCKY_BLOCK,
|
||||
/**
|
||||
* Player received currency by disenchanting
|
||||
*/
|
||||
REFUND,
|
||||
/**
|
||||
* Player received currency by mining (from other players)
|
||||
*/
|
||||
MINING_OTHERS
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
package me.nvus.xprison.api.events;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
|
||||
public abstract class XPrisonEvent extends Event {
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
package me.nvus.xprison.api.events.player;
|
||||
|
||||
import me.nvus.xprison.api.events.XPrisonEvent;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
public abstract class XPrisonPlayerEvent extends XPrisonEvent {
|
||||
|
||||
@Getter
|
||||
protected OfflinePlayer player;
|
||||
|
||||
/**
|
||||
* Abstract XPrisonPlayerEvent
|
||||
*
|
||||
* @param player Player
|
||||
*/
|
||||
public XPrisonPlayerEvent(OfflinePlayer player) {
|
||||
this.player = player;
|
||||
}
|
||||
}
|
|
@ -1,114 +0,0 @@
|
|||
package me.nvus.xprison.autominer;
|
||||
|
||||
import me.nvus.xprison.XPrison;
|
||||
import me.nvus.xprison.XPrisonModule;
|
||||
import me.nvus.xprison.autominer.api.XPrisonAutoMinerAPI;
|
||||
import me.nvus.xprison.autominer.api.XPrisonAutoMinerAPIImpl;
|
||||
import me.nvus.xprison.autominer.command.AdminAutoMinerCommand;
|
||||
import me.nvus.xprison.autominer.command.AutoMinerCommand;
|
||||
import me.nvus.xprison.autominer.config.AutoMinerConfig;
|
||||
import me.nvus.xprison.autominer.listener.AutoMinerListener;
|
||||
import me.nvus.xprison.autominer.manager.AutoMinerManager;
|
||||
import me.nvus.xprison.autominer.repo.AutominerRepository;
|
||||
import me.nvus.xprison.autominer.repo.impl.AutominerRepositoryImpl;
|
||||
import me.nvus.xprison.autominer.service.AutominerService;
|
||||
import me.nvus.xprison.autominer.service.impl.AutominerServiceImpl;
|
||||
import lombok.Getter;
|
||||
|
||||
public final class XPrisonAutoMiner implements XPrisonModule {
|
||||
|
||||
public static final String MODULE_NAME = "Auto Miner";
|
||||
|
||||
@Getter
|
||||
private static XPrisonAutoMiner instance;
|
||||
|
||||
@Getter
|
||||
private final XPrison core;
|
||||
|
||||
@Getter
|
||||
private AutoMinerManager manager;
|
||||
|
||||
@Getter
|
||||
private AutoMinerConfig autoMinerConfig;
|
||||
|
||||
@Getter
|
||||
private XPrisonAutoMinerAPI api;
|
||||
|
||||
@Getter
|
||||
private AutominerService autominerService;
|
||||
|
||||
@Getter
|
||||
private AutominerRepository autominerRepository;
|
||||
|
||||
private boolean enabled;
|
||||
|
||||
public XPrisonAutoMiner(XPrison core) {
|
||||
this.core = core;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
instance = this;
|
||||
|
||||
this.autoMinerConfig = new AutoMinerConfig(this);
|
||||
this.autoMinerConfig.load();
|
||||
|
||||
this.autominerRepository = new AutominerRepositoryImpl(this.core.getPluginDatabase());
|
||||
this.autominerRepository.createTables();
|
||||
this.autominerRepository.removeExpiredAutoMiners();
|
||||
|
||||
this.autominerService = new AutominerServiceImpl(this.autominerRepository);
|
||||
|
||||
this.manager = new AutoMinerManager(this);
|
||||
this.manager.load();
|
||||
|
||||
AutoMinerListener listener = new AutoMinerListener(this);
|
||||
listener.subscribeToEvents();
|
||||
|
||||
this.registerCommands();
|
||||
|
||||
this.api = new XPrisonAutoMinerAPIImpl(this);
|
||||
|
||||
this.enabled = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
this.manager.disable();
|
||||
this.enabled = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
this.autoMinerConfig.reload();
|
||||
this.manager.reload();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return MODULE_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHistoryEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetPlayerData() {
|
||||
this.autominerRepository.clearTableData();
|
||||
}
|
||||
|
||||
private void registerCommands() {
|
||||
AutoMinerCommand autoMinerCommand = new AutoMinerCommand(this);
|
||||
autoMinerCommand.register();
|
||||
|
||||
AdminAutoMinerCommand adminAutoMinerCommand = new AdminAutoMinerCommand(this);
|
||||
adminAutoMinerCommand.register();
|
||||
}
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
package me.nvus.xprison.autominer.api;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface XPrisonAutoMinerAPI {
|
||||
|
||||
/**
|
||||
* Returns true if player is in autominer region, otherwise return false
|
||||
*
|
||||
* @param player Player
|
||||
* @return returns true if player is in autominer region, otherwise return false
|
||||
*/
|
||||
boolean isInAutoMinerRegion(Player player);
|
||||
|
||||
/**
|
||||
* Returns remaining autominer time in seconds for specific player
|
||||
*
|
||||
* @param player Player
|
||||
* @return time in seconds left for specific player autominer
|
||||
*/
|
||||
int getAutoMinerTime(Player player);
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
package me.nvus.xprison.autominer.api;
|
||||
|
||||
import me.nvus.xprison.autominer.XPrisonAutoMiner;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public final class XPrisonAutoMinerAPIImpl implements XPrisonAutoMinerAPI {
|
||||
|
||||
private final XPrisonAutoMiner plugin;
|
||||
|
||||
public XPrisonAutoMinerAPIImpl(XPrisonAutoMiner plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInAutoMinerRegion(Player player) {
|
||||
return this.plugin.getManager().isInAutoMinerRegion(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAutoMinerTime(Player player) {
|
||||
return this.plugin.getManager().getAutoMinerTime(player);
|
||||
}
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
package me.nvus.xprison.autominer.api.events;
|
||||
|
||||
import me.nvus.xprison.api.events.player.XPrisonPlayerEvent;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public final class PlayerAutoMinerTimeModifyEvent extends XPrisonPlayerEvent {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private final TimeUnit timeUnit;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private final long duration;
|
||||
|
||||
/**
|
||||
* Called when player received autominer time
|
||||
*
|
||||
* @param player Player
|
||||
* @param unit TimeUnit
|
||||
* @param duration duration, can be negative
|
||||
*/
|
||||
public PlayerAutoMinerTimeModifyEvent(Player player, TimeUnit unit, long duration) {
|
||||
super(player);
|
||||
this.timeUnit = unit;
|
||||
this.duration = duration;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
package me.nvus.xprison.autominer.api.events;
|
||||
|
||||
import me.nvus.xprison.api.events.player.XPrisonPlayerEvent;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class PlayerAutomineEvent extends XPrisonPlayerEvent implements Cancellable {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private boolean cancelled;
|
||||
|
||||
@Getter
|
||||
private final int timeLeft;
|
||||
|
||||
/**
|
||||
* Called when player auto mines in region
|
||||
*
|
||||
* @param player Player
|
||||
* @param timeLeft Timeleft in seconds of player's autominer time
|
||||
*/
|
||||
public PlayerAutomineEvent(Player player, int timeLeft) {
|
||||
super(player);
|
||||
this.timeLeft = timeLeft;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
package me.nvus.xprison.autominer.command;
|
||||
|
||||
import me.nvus.xprison.autominer.XPrisonAutoMiner;
|
||||
import me.nvus.xprison.autominer.utils.AutoMinerConstants;
|
||||
import me.nvus.xprison.utils.player.PlayerUtils;
|
||||
import me.lucko.helper.Commands;
|
||||
import me.lucko.helper.command.context.CommandContext;
|
||||
import me.lucko.helper.utils.Players;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class AdminAutoMinerCommand {
|
||||
|
||||
private static final String[] COMMAND_ALIASES = {"adminautominer", "aam"};
|
||||
|
||||
private final XPrisonAutoMiner plugin;
|
||||
|
||||
public AdminAutoMinerCommand(XPrisonAutoMiner plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void register() {
|
||||
Commands.create()
|
||||
.assertPermission(AutoMinerConstants.ADMIN_PERMISSION)
|
||||
.tabHandler(this::createTabHandler)
|
||||
.handler(c -> {
|
||||
|
||||
if (!validateArguments(c)) {
|
||||
return;
|
||||
}
|
||||
|
||||
String action = c.rawArg(0);
|
||||
|
||||
Player target = c.arg(1).parseOrFail(Player.class);
|
||||
long time = c.arg(2).parseOrFail(Long.class);
|
||||
|
||||
TimeUnit timeUnit;
|
||||
try {
|
||||
timeUnit = TimeUnit.valueOf(Objects.requireNonNull(c.rawArg(3)).toUpperCase());
|
||||
} catch (IllegalArgumentException e) {
|
||||
PlayerUtils.sendMessage(c.sender(), "&cInvalid time unit! Please use one from: " + StringUtils.join(TimeUnit.values(), ","));
|
||||
return;
|
||||
}
|
||||
|
||||
if ("remove".equalsIgnoreCase(action)) {
|
||||
time = -time;
|
||||
}
|
||||
|
||||
this.plugin.getManager().modifyPlayerAutoMinerTime(c.sender(), target, time, timeUnit);
|
||||
}).registerAndBind(this.plugin.getCore(), COMMAND_ALIASES);
|
||||
}
|
||||
|
||||
private List<String> createTabHandler(CommandContext<CommandSender> context) {
|
||||
List<String> list = new ArrayList<>();
|
||||
|
||||
if (context.args().size() == 1) {
|
||||
list = Arrays.asList("give", "remove");
|
||||
} else if (context.args().size() == 2) {
|
||||
list = Players.all().stream().map(Player::getName).collect(Collectors.toList());
|
||||
} else if (context.args().size() == 4) {
|
||||
list = Arrays.stream(TimeUnit.values()).map(TimeUnit::name).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
private boolean validateArguments(CommandContext<CommandSender> c) {
|
||||
return c.args().size() == 4 && ("give".equalsIgnoreCase(c.rawArg(0)) || "remove".equalsIgnoreCase(c.rawArg(0)));
|
||||
}
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
package me.nvus.xprison.autominer.command;
|
||||
|
||||
import me.nvus.xprison.autominer.XPrisonAutoMiner;
|
||||
import me.nvus.xprison.autominer.utils.AutoMinerUtils;
|
||||
import me.nvus.xprison.utils.player.PlayerUtils;
|
||||
import me.lucko.helper.Commands;
|
||||
import me.lucko.helper.command.context.CommandContext;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class AutoMinerCommand {
|
||||
|
||||
private static final String[] COMMAND_ALIASES = {"autominer"};
|
||||
|
||||
private final XPrisonAutoMiner plugin;
|
||||
|
||||
public AutoMinerCommand(XPrisonAutoMiner plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void register() {
|
||||
Commands.create()
|
||||
.assertPlayer()
|
||||
.handler(c -> {
|
||||
|
||||
if (!validateArguments(c)) {
|
||||
return;
|
||||
}
|
||||
|
||||
int timeLeft = this.plugin.getManager().getAutoMinerTime(c.sender());
|
||||
PlayerUtils.sendMessage(c.sender(), this.plugin.getAutoMinerConfig().getMessage("auto_miner_time").replace("%time%", AutoMinerUtils.getAutoMinerTimeLeftFormatted(timeLeft)));
|
||||
|
||||
}).registerAndBind(this.plugin.getCore(), COMMAND_ALIASES);
|
||||
}
|
||||
|
||||
private boolean validateArguments(CommandContext<Player> c) {
|
||||
return c.args().size() == 0;
|
||||
}
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
package me.nvus.xprison.autominer.config;
|
||||
|
||||
import me.nvus.xprison.autominer.XPrisonAutoMiner;
|
||||
import me.nvus.xprison.config.FileManager;
|
||||
import me.nvus.xprison.utils.text.TextUtils;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class AutoMinerConfig {
|
||||
|
||||
private final XPrisonAutoMiner plugin;
|
||||
private final FileManager.Config config;
|
||||
|
||||
private Map<String, String> messages;
|
||||
|
||||
public AutoMinerConfig(XPrisonAutoMiner plugin) {
|
||||
this.plugin = plugin;
|
||||
this.config = this.plugin.getCore().getFileManager().getConfig("autominer.yml").copyDefaults(true).save();
|
||||
}
|
||||
|
||||
private void loadMessages() {
|
||||
messages = new HashMap<>();
|
||||
|
||||
YamlConfiguration configuration = getYamlConfig();
|
||||
|
||||
for (String key : configuration.getConfigurationSection("messages").getKeys(false)) {
|
||||
messages.put(key.toLowerCase(), TextUtils.applyColor(configuration.getString("messages." + key)));
|
||||
}
|
||||
}
|
||||
|
||||
public String getMessage(String key) {
|
||||
return messages.getOrDefault(key.toLowerCase(), "No message with key '" + key + "' found");
|
||||
}
|
||||
|
||||
private void loadVariables() {
|
||||
this.loadMessages();
|
||||
}
|
||||
|
||||
private FileManager.Config getConfig() {
|
||||
return this.config;
|
||||
}
|
||||
|
||||
public YamlConfiguration getYamlConfig() {
|
||||
return this.config.get();
|
||||
}
|
||||
|
||||
public void load() {
|
||||
this.getConfig().reload();
|
||||
this.loadVariables();
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
this.load();
|
||||
}
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
package me.nvus.xprison.autominer.listener;
|
||||
|
||||
import me.nvus.xprison.autominer.XPrisonAutoMiner;
|
||||
import me.lucko.helper.Events;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
public class AutoMinerListener {
|
||||
|
||||
private final XPrisonAutoMiner plugin;
|
||||
|
||||
public AutoMinerListener(XPrisonAutoMiner plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void subscribeToEvents() {
|
||||
this.subscribeToPlayerJoinEvent();
|
||||
this.subscribeToPlayerQuitEvent();
|
||||
}
|
||||
|
||||
private void subscribeToPlayerQuitEvent() {
|
||||
Events.subscribe(PlayerQuitEvent.class)
|
||||
.handler(e -> this.plugin.getManager().savePlayerAutoMinerData(e.getPlayer(), true)).bindWith(this.plugin.getCore());
|
||||
}
|
||||
|
||||
private void subscribeToPlayerJoinEvent() {
|
||||
Events.subscribe(PlayerJoinEvent.class)
|
||||
.handler(e -> this.plugin.getManager().loadPlayerAutoMinerData(e.getPlayer())).bindWith(this.plugin.getCore());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,216 +0,0 @@
|
|||
package me.nvus.xprison.autominer.manager;
|
||||
|
||||
import me.nvus.xprison.autominer.XPrisonAutoMiner;
|
||||
import me.nvus.xprison.autominer.api.events.PlayerAutoMinerTimeModifyEvent;
|
||||
import me.nvus.xprison.autominer.api.events.PlayerAutomineEvent;
|
||||
import me.nvus.xprison.autominer.model.AutoMinerRegion;
|
||||
import me.nvus.xprison.utils.player.PlayerUtils;
|
||||
import me.lucko.helper.Events;
|
||||
import me.lucko.helper.Schedulers;
|
||||
import me.lucko.helper.utils.Players;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.codemc.worldguardwrapper.WorldGuardWrapper;
|
||||
import org.codemc.worldguardwrapper.region.IWrappedRegion;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class AutoMinerManager {
|
||||
|
||||
private final XPrisonAutoMiner plugin;
|
||||
|
||||
private final Map<UUID, Integer> autoMinerTimes;
|
||||
|
||||
private List<AutoMinerRegion> autoMinerRegions;
|
||||
|
||||
public AutoMinerManager(XPrisonAutoMiner plugin) {
|
||||
this.plugin = plugin;
|
||||
this.autoMinerTimes = new ConcurrentHashMap<>();
|
||||
}
|
||||
|
||||
private void loadAllPlayersAutoMinerData() {
|
||||
Schedulers.async().run(() -> {
|
||||
for (Player p : Players.all()) {
|
||||
int timeLeft = this.plugin.getAutominerService().getPlayerAutoMinerTime(p);
|
||||
this.autoMinerTimes.put(p.getUniqueId(), timeLeft);
|
||||
this.plugin.getCore().debug(String.format("Loaded %s's AutoMiner Time.", p.getName()), this.plugin);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public void loadPlayerAutoMinerData(Player p) {
|
||||
Schedulers.async().run(() -> {
|
||||
int timeLeft = this.plugin.getAutominerService().getPlayerAutoMinerTime(p);
|
||||
this.autoMinerTimes.put(p.getUniqueId(), timeLeft);
|
||||
this.plugin.getCore().debug(String.format("Loaded %s's AutoMiner Time.", p.getName()), this.plugin);
|
||||
});
|
||||
}
|
||||
|
||||
public void savePlayerAutoMinerData(Player p, boolean async) {
|
||||
|
||||
int timeLeft = getAutoMinerTime(p);
|
||||
|
||||
if (async) {
|
||||
Schedulers.async().run(() -> savePlayerAutominerData(p, timeLeft));
|
||||
} else {
|
||||
savePlayerAutominerData(p, timeLeft);
|
||||
}
|
||||
}
|
||||
|
||||
private void savePlayerAutominerData(Player p, int timeLeft) {
|
||||
this.plugin.getAutominerService().setAutoMiner(p, timeLeft);
|
||||
this.autoMinerTimes.remove(p.getUniqueId());
|
||||
this.plugin.getCore().debug(String.format("Saved %s's AutoMiner time.", p.getName()), this.plugin);
|
||||
}
|
||||
|
||||
public void modifyPlayerAutoMinerTime(CommandSender sender, Player p, long time, TimeUnit unit) {
|
||||
|
||||
if (p == null || !p.isOnline()) {
|
||||
PlayerUtils.sendMessage(sender, "&cPlayer is not online!");
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerAutoMinerTimeModifyEvent event = this.callAutoMinerTimeModifyEvent(p, time, unit);
|
||||
|
||||
time = event.getDuration();
|
||||
unit = event.getTimeUnit();
|
||||
|
||||
int currentTime = getAutoMinerTime(p);
|
||||
currentTime += unit.toSeconds(time);
|
||||
|
||||
if (currentTime < 0) {
|
||||
currentTime = 0;
|
||||
}
|
||||
|
||||
this.autoMinerTimes.put(p.getUniqueId(), currentTime);
|
||||
|
||||
String messageKey = time < 0 ? "auto_miner_time_remove" : "auto_miner_time_add";
|
||||
PlayerUtils.sendMessage(sender, this.plugin.getAutoMinerConfig().getMessage(messageKey).replace("%time%", String.valueOf(Math.abs(time))).replace("%timeunit%", unit.name()).replace("%player%", p.getName()));
|
||||
}
|
||||
|
||||
private PlayerAutoMinerTimeModifyEvent callAutoMinerTimeModifyEvent(Player p, long time, TimeUnit unit) {
|
||||
PlayerAutoMinerTimeModifyEvent event = new PlayerAutoMinerTimeModifyEvent(p, unit, time);
|
||||
Events.callSync(event);
|
||||
return event;
|
||||
}
|
||||
|
||||
public boolean hasAutoMinerTime(Player p) {
|
||||
return getAutoMinerTime(p) > 0;
|
||||
}
|
||||
|
||||
public void decrementPlayerAutominerTime(Player p) {
|
||||
int newAmount = autoMinerTimes.get(p.getUniqueId()) - 1;
|
||||
autoMinerTimes.put(p.getUniqueId(), newAmount);
|
||||
}
|
||||
|
||||
public int getAutoMinerTime(Player player) {
|
||||
return this.autoMinerTimes.getOrDefault(player.getUniqueId(), 0);
|
||||
}
|
||||
|
||||
public boolean isInAutoMinerRegion(Player player) {
|
||||
for (AutoMinerRegion region : this.autoMinerRegions) {
|
||||
if (region.getRegion().contains(player.getLocation())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public PlayerAutomineEvent callAutoMineEvent(Player p) {
|
||||
PlayerAutomineEvent event = new PlayerAutomineEvent(p, this.getAutoMinerTime(p));
|
||||
Events.callSync(event);
|
||||
return event;
|
||||
}
|
||||
|
||||
public void saveAllPlayerAutoMinerData(boolean async) {
|
||||
Players.all().forEach(p -> savePlayerAutoMinerData(p, async));
|
||||
this.plugin.getCore().getLogger().info("Saved online players auto miner data.");
|
||||
}
|
||||
|
||||
private void loadAutoMinerRegions() {
|
||||
this.autoMinerRegions = new ArrayList<>();
|
||||
|
||||
YamlConfiguration configuration = this.plugin.getAutoMinerConfig().getYamlConfig();
|
||||
|
||||
Set<String> regionNames = configuration.getConfigurationSection("auto-miner-regions").getKeys(false);
|
||||
|
||||
for (String regionName : regionNames) {
|
||||
String worldName = configuration.getString("auto-miner-regions." + regionName + ".world");
|
||||
World world = Bukkit.getWorld(worldName);
|
||||
|
||||
if (world == null) {
|
||||
plugin.getCore().getLogger().warning(String.format("Unable to get world with name %s! Disabling AutoMiner region.", worldName));
|
||||
return;
|
||||
}
|
||||
|
||||
int rewardPeriod = configuration.getInt("auto-miner-regions." + regionName + ".reward-period");
|
||||
|
||||
if (rewardPeriod <= 0) {
|
||||
plugin.getCore().getLogger().warning("reward-period in autominer.yml for region " + regionName + " needs to be greater than 0!");
|
||||
return;
|
||||
}
|
||||
|
||||
Optional<IWrappedRegion> optRegion = WorldGuardWrapper.getInstance().getRegion(world, regionName);
|
||||
|
||||
if (!optRegion.isPresent()) {
|
||||
plugin.getCore().getLogger().warning(String.format("There is no such region named %s in world %s!", regionName, world.getName()));
|
||||
return;
|
||||
}
|
||||
|
||||
List<String> rewards = configuration.getStringList("auto-miner-regions." + regionName + ".rewards");
|
||||
|
||||
if (rewards.isEmpty()) {
|
||||
plugin.getCore().getLogger().warning("rewards in autominer.yml for region " + regionName + " are empty!");
|
||||
return;
|
||||
}
|
||||
|
||||
int blocksBroken = configuration.getInt("auto-miner-regions." + regionName + ".blocks-broken");
|
||||
|
||||
if (blocksBroken <= 0) {
|
||||
this.plugin.getCore().getLogger().warning("blocks-broken in autominer.yml for region " + regionName + " needs to be greater than 0!");
|
||||
return;
|
||||
}
|
||||
|
||||
AutoMinerRegion region = new AutoMinerRegion(this.plugin, world, optRegion.get(), rewards, rewardPeriod, blocksBroken);
|
||||
region.startAutoMinerTask();
|
||||
|
||||
this.plugin.getCore().getLogger().info("AutoMiner region '" + regionName + "' loaded successfully!");
|
||||
this.autoMinerRegions.add(region);
|
||||
}
|
||||
}
|
||||
|
||||
public void load() {
|
||||
this.removeExpiredAutoMiners();
|
||||
this.loadAllPlayersAutoMinerData();
|
||||
this.loadAutoMinerRegions();
|
||||
}
|
||||
|
||||
private void removeExpiredAutoMiners() {
|
||||
Schedulers.async().run(() -> {
|
||||
this.plugin.getAutominerService().removeExpiredAutoMiners();
|
||||
this.plugin.getCore().debug("Removed expired AutoMiners from database", this.plugin);
|
||||
});
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
this.stopAutoMinerRegions();
|
||||
this.loadAutoMinerRegions();
|
||||
}
|
||||
|
||||
public void disable() {
|
||||
this.stopAutoMinerRegions();
|
||||
this.saveAllPlayerAutoMinerData(false);
|
||||
}
|
||||
|
||||
private void stopAutoMinerRegions() {
|
||||
for (AutoMinerRegion region : this.autoMinerRegions) {
|
||||
region.stopAutoMinerTask();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,75 +0,0 @@
|
|||
package me.nvus.xprison.autominer.model;
|
||||
|
||||
import me.nvus.xprison.autominer.XPrisonAutoMiner;
|
||||
import lombok.Getter;
|
||||
import me.lucko.helper.utils.Players;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.codemc.worldguardwrapper.region.IWrappedRegion;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
public class AutoMinerRegion {
|
||||
|
||||
private final XPrisonAutoMiner plugin;
|
||||
private World world;
|
||||
private IWrappedRegion region;
|
||||
private List<String> commands;
|
||||
private int rewardPeriod;
|
||||
private int blocksBroken;
|
||||
private final AutoMinerTask autoMinerTask;
|
||||
|
||||
public AutoMinerRegion(XPrisonAutoMiner plugin, World world, IWrappedRegion region, List<String> rewards, int rewardPeriod, int blocksBroken) {
|
||||
this.plugin = plugin;
|
||||
this.world = world;
|
||||
this.region = region;
|
||||
this.commands = rewards;
|
||||
this.rewardPeriod = rewardPeriod;
|
||||
this.blocksBroken = blocksBroken;
|
||||
this.autoMinerTask = new AutoMinerTask(this);
|
||||
}
|
||||
|
||||
public void startAutoMinerTask() {
|
||||
this.autoMinerTask.start();
|
||||
}
|
||||
|
||||
public List<Player> getPlayersInRegion() {
|
||||
List<Player> list = new ArrayList<>();
|
||||
for (Player p : Players.all()) {
|
||||
if (isInAutoMinerRegion(p)) {
|
||||
list.add(p);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private boolean isInAutoMinerRegion(Player p) {
|
||||
return p.getWorld().getName().equals(this.world.getName()) && region.contains(p.getLocation());
|
||||
}
|
||||
|
||||
public void stopAutoMinerTask() {
|
||||
this.autoMinerTask.stop();
|
||||
}
|
||||
|
||||
public void setWorld(World world) {
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
public void setRegion(IWrappedRegion region) {
|
||||
this.region = region;
|
||||
}
|
||||
|
||||
public void setCommands(List<String> commands) {
|
||||
this.commands = commands;
|
||||
}
|
||||
|
||||
public void setRewardPeriod(int rewardPeriod) {
|
||||
this.rewardPeriod = rewardPeriod;
|
||||
}
|
||||
|
||||
public void setBlocksBroken(int blocksBroken) {
|
||||
this.blocksBroken = blocksBroken;
|
||||
}
|
||||
}
|
|
@ -1,115 +0,0 @@
|
|||
package me.nvus.xprison.autominer.model;
|
||||
|
||||
import com.cryptomorin.xseries.messages.ActionBar;
|
||||
import me.nvus.xprison.autominer.api.events.PlayerAutomineEvent;
|
||||
import me.lucko.helper.Schedulers;
|
||||
import me.lucko.helper.scheduler.Task;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public final class AutoMinerTask implements Runnable {
|
||||
|
||||
private final AtomicInteger counter;
|
||||
private final AutoMinerRegion region;
|
||||
private Task task;
|
||||
|
||||
public AutoMinerTask(AutoMinerRegion region) {
|
||||
this.region = region;
|
||||
this.counter = new AtomicInteger(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
int current = counter.getAndIncrement();
|
||||
boolean resetCounterAfterEnd = current >= region.getRewardPeriod();
|
||||
|
||||
List<Player> players = this.region.getPlayersInRegion();
|
||||
|
||||
for (Player p : players) {
|
||||
|
||||
if (!this.executeTaskValidationAndNotifyPlayerOnFail(p)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
this.decrementPlayerAutoMinerTimeAndNotify(p);
|
||||
|
||||
if (resetCounterAfterEnd) {
|
||||
this.executeTaskLogic(p);
|
||||
}
|
||||
}
|
||||
|
||||
if (resetCounterAfterEnd) {
|
||||
counter.set(0);
|
||||
}
|
||||
}
|
||||
|
||||
public void start() {
|
||||
this.stop();
|
||||
this.task = Schedulers.async().runRepeating(this, 1, TimeUnit.SECONDS, 1, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
if (this.task != null) {
|
||||
this.task.stop();
|
||||
}
|
||||
}
|
||||
|
||||
private void decrementPlayerAutoMinerTimeAndNotify(Player p) {
|
||||
this.region.getPlugin().getManager().decrementPlayerAutominerTime(p);
|
||||
ActionBar.sendActionBar(p, this.region.getPlugin().getAutoMinerConfig().getMessage("auto_miner_enabled"));
|
||||
}
|
||||
|
||||
private boolean executeTaskValidationAndNotifyPlayerOnFail(Player p) {
|
||||
|
||||
if (!this.checkPlayerAutoMinerTime(p)) {
|
||||
ActionBar.sendActionBar(p, this.region.getPlugin().getAutoMinerConfig().getMessage("auto_miner_disabled"));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!this.checkPlayerItemInHand(p)) {
|
||||
ActionBar.sendActionBar(p, this.region.getPlugin().getAutoMinerConfig().getMessage("auto_miner_no_pickaxe"));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void executeTaskLogic(Player p) {
|
||||
|
||||
if (!this.callAutoMineEvent(p)) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.executeCommands(p);
|
||||
this.region.getPlugin().getCore().getEnchants().getEnchantsManager().addBlocksBrokenToItem(p, p.getItemInHand(), this.region.getBlocksBroken());
|
||||
}
|
||||
|
||||
private boolean callAutoMineEvent(Player p) {
|
||||
PlayerAutomineEvent event = this.region.getPlugin().getManager().callAutoMineEvent(p);
|
||||
return !event.isCancelled();
|
||||
}
|
||||
|
||||
private boolean checkPlayerItemInHand(Player p) {
|
||||
ItemStack item = p.getItemInHand();
|
||||
return this.region.getPlugin().getCore().isPickaxeSupported(item);
|
||||
}
|
||||
|
||||
private boolean checkPlayerAutoMinerTime(Player p) {
|
||||
return this.region.getPlugin().getManager().hasAutoMinerTime(p);
|
||||
}
|
||||
|
||||
private void executeCommands(Player p) {
|
||||
|
||||
if (this.region.getCommands().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.region.getCommands().forEach(c -> Schedulers.sync().run(() -> Bukkit.dispatchCommand(Bukkit.getConsoleSender(), c.replace("%player%", p.getName()))));
|
||||
}
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
package me.nvus.xprison.autominer.repo;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface AutominerRepository {
|
||||
|
||||
int getPlayerAutoMinerTime(OfflinePlayer player);
|
||||
|
||||
void removeExpiredAutoMiners();
|
||||
|
||||
void saveAutoMiner(Player p, int timeLeft);
|
||||
|
||||
void createTables();
|
||||
|
||||
void clearTableData();
|
||||
}
|
|
@ -1,81 +0,0 @@
|
|||
package me.nvus.xprison.autominer.repo.impl;
|
||||
|
||||
import me.nvus.xprison.autominer.repo.AutominerRepository;
|
||||
import me.nvus.xprison.database.SQLDatabase;
|
||||
import me.nvus.xprison.database.model.SQLDatabaseType;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class AutominerRepositoryImpl implements AutominerRepository {
|
||||
|
||||
private static final String TABLE_NAME = "UltraPrison_AutoMiner";
|
||||
private static final String AUTOMINER_UUID_COLNAME = "UUID";
|
||||
private static final String AUTOMINER_TIME_COLNAME = "time";
|
||||
private final SQLDatabase database;
|
||||
|
||||
public AutominerRepositoryImpl(SQLDatabase database) {
|
||||
|
||||
this.database = database;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPlayerAutoMinerTime(OfflinePlayer p) {
|
||||
try (Connection con = this.database.getConnection(); PreparedStatement statement = database.prepareStatement(con, "SELECT * FROM " + TABLE_NAME + " WHERE " + AUTOMINER_UUID_COLNAME + "=?")) {
|
||||
statement.setString(1, p.getUniqueId().toString());
|
||||
try (ResultSet set = statement.executeQuery()) {
|
||||
if (set.next()) {
|
||||
return set.getInt(AUTOMINER_TIME_COLNAME);
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeExpiredAutoMiners() {
|
||||
try (Connection con = this.database.getConnection(); PreparedStatement statement = database.prepareStatement(con, "DELETE FROM " + TABLE_NAME + " WHERE " + AUTOMINER_TIME_COLNAME + " <= 0")) {
|
||||
statement.execute();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveAutoMiner(Player p, int timeLeft) {
|
||||
if (database.getDatabaseType() == SQLDatabaseType.MYSQL) {
|
||||
try (Connection con = this.database.getConnection(); PreparedStatement statement = database.prepareStatement(con, "INSERT INTO " + TABLE_NAME + " VALUES (?,?) ON DUPLICATE KEY UPDATE " + AUTOMINER_TIME_COLNAME + "=?")) {
|
||||
statement.setString(1, p.getUniqueId().toString());
|
||||
statement.setInt(2, timeLeft);
|
||||
statement.setInt(3, timeLeft);
|
||||
statement.execute();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
try (Connection con = this.database.getConnection(); PreparedStatement statement = database.prepareStatement(con, "INSERT OR REPLACE INTO " + TABLE_NAME + " VALUES(?,?)")) {
|
||||
statement.setString(1, p.getUniqueId().toString());
|
||||
statement.setDouble(2, timeLeft);
|
||||
statement.execute();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createTables() {
|
||||
this.database.executeSql("CREATE TABLE IF NOT EXISTS " + TABLE_NAME + "(UUID varchar(36) NOT NULL UNIQUE, time int, primary key (UUID))");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearTableData() {
|
||||
this.database.executeSqlAsync("DELETE FROM " + TABLE_NAME);
|
||||
}
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
package me.nvus.xprison.autominer.service;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface AutominerService {
|
||||
|
||||
int getPlayerAutoMinerTime(OfflinePlayer player);
|
||||
|
||||
void removeExpiredAutoMiners();
|
||||
|
||||
void setAutoMiner(Player p, int timeLeft);
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
package me.nvus.xprison.autominer.service.impl;
|
||||
|
||||
import me.nvus.xprison.autominer.repo.AutominerRepository;
|
||||
import me.nvus.xprison.autominer.service.AutominerService;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class AutominerServiceImpl implements AutominerService {
|
||||
|
||||
private final AutominerRepository repository;
|
||||
|
||||
public AutominerServiceImpl(AutominerRepository repository) {
|
||||
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPlayerAutoMinerTime(OfflinePlayer player) {
|
||||
return repository.getPlayerAutoMinerTime(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeExpiredAutoMiners() {
|
||||
repository.removeExpiredAutoMiners();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAutoMiner(Player p, int timeLeft) {
|
||||
repository.saveAutoMiner(p, timeLeft);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
package me.nvus.xprison.autominer.utils;
|
||||
|
||||
public class AutoMinerConstants {
|
||||
|
||||
public static final String ADMIN_PERMISSION = "xprison.autominer.admin";
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
package me.nvus.xprison.autominer.utils;
|
||||
|
||||
public class AutoMinerUtils {
|
||||
|
||||
public static String getAutoMinerTimeLeftFormatted(int timeLeft) {
|
||||
|
||||
if (timeLeft == 0) {
|
||||
return "0s";
|
||||
}
|
||||
|
||||
long days = timeLeft / (24 * 60 * 60);
|
||||
timeLeft -= days * (24 * 60 * 60);
|
||||
|
||||
long hours = timeLeft / (60 * 60);
|
||||
timeLeft -= hours * (60 * 60);
|
||||
|
||||
long minutes = timeLeft / (60);
|
||||
timeLeft -= minutes * (60);
|
||||
|
||||
long seconds = timeLeft;
|
||||
|
||||
return days + "d " + hours + "h " + minutes + "m " + seconds + "s";
|
||||
}
|
||||
}
|
|
@ -1,108 +0,0 @@
|
|||
package me.nvus.xprison.autosell;
|
||||
|
||||
import me.nvus.xprison.XPrison;
|
||||
import me.nvus.xprison.XPrisonModule;
|
||||
import me.nvus.xprison.autosell.api.XPrisonAutoSellAPI;
|
||||
import me.nvus.xprison.autosell.api.XPrisonAutoSellAPIImpl;
|
||||
import me.nvus.xprison.autosell.command.AutoSellCommand;
|
||||
import me.nvus.xprison.autosell.command.SellAllCommand;
|
||||
import me.nvus.xprison.autosell.command.SellPriceCommand;
|
||||
import me.nvus.xprison.autosell.config.AutoSellConfig;
|
||||
import me.nvus.xprison.autosell.listener.AutoSellListener;
|
||||
import me.nvus.xprison.autosell.manager.AutoSellManager;
|
||||
import me.nvus.xprison.autosell.model.AutoSellBroadcastTask;
|
||||
import me.nvus.xprison.multipliers.XPrisonMultipliers;
|
||||
import lombok.Getter;
|
||||
|
||||
public final class XPrisonAutoSell implements XPrisonModule {
|
||||
|
||||
public static final String MODULE_NAME = "Auto Sell";
|
||||
|
||||
@Getter
|
||||
private static XPrisonAutoSell instance;
|
||||
@Getter
|
||||
private final XPrison core;
|
||||
@Getter
|
||||
private XPrisonAutoSellAPI api;
|
||||
@Getter
|
||||
private AutoSellConfig autoSellConfig;
|
||||
@Getter
|
||||
private AutoSellManager manager;
|
||||
@Getter
|
||||
private AutoSellBroadcastTask broadcastTask;
|
||||
|
||||
private boolean enabled;
|
||||
|
||||
public XPrisonAutoSell(XPrison core) {
|
||||
instance = this;
|
||||
this.core = core;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
this.autoSellConfig.reload();
|
||||
this.manager.reload();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
this.autoSellConfig = new AutoSellConfig(this);
|
||||
this.autoSellConfig.load();
|
||||
|
||||
this.manager = new AutoSellManager(this);
|
||||
this.manager.load();
|
||||
|
||||
this.broadcastTask = new AutoSellBroadcastTask(this);
|
||||
this.broadcastTask.start();
|
||||
|
||||
AutoSellListener listener = new AutoSellListener(this);
|
||||
listener.subscribeToEvents();
|
||||
|
||||
this.registerCommands();
|
||||
|
||||
this.api = new XPrisonAutoSellAPIImpl(this);
|
||||
this.enabled = true;
|
||||
}
|
||||
|
||||
private void registerCommands() {
|
||||
SellAllCommand sellAllCommand = new SellAllCommand(this);
|
||||
sellAllCommand.register();
|
||||
|
||||
AutoSellCommand autoSellCommand = new AutoSellCommand(this);
|
||||
autoSellCommand.register();
|
||||
|
||||
SellPriceCommand sellPriceCommand = new SellPriceCommand(this);
|
||||
sellPriceCommand.register();
|
||||
}
|
||||
|
||||
public boolean isMultipliersModuleEnabled() {
|
||||
return this.core.isModuleEnabled(XPrisonMultipliers.MODULE_NAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
this.broadcastTask.stop();
|
||||
this.enabled = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return MODULE_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHistoryEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetPlayerData() {
|
||||
}
|
||||
|
||||
}
|
|
@ -1,68 +0,0 @@
|
|||
package me.nvus.xprison.autosell.api;
|
||||
|
||||
import me.nvus.xprison.autosell.model.SellRegion;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public interface XPrisonAutoSellAPI {
|
||||
|
||||
/**
|
||||
* Method to get current earnings of player
|
||||
*
|
||||
* @param player Player
|
||||
* @return Current earnings
|
||||
*/
|
||||
double getCurrentEarnings(Player player);
|
||||
|
||||
/**
|
||||
* Method to get price for ItemStack in specified mine region
|
||||
*
|
||||
* @param regionName Name of region
|
||||
* @param item ItemStack
|
||||
* @return Price for item
|
||||
*/
|
||||
double getPriceForItem(String regionName, ItemStack item);
|
||||
|
||||
/**
|
||||
* Method to get price for Block
|
||||
*
|
||||
* @param block Block
|
||||
* @return Price for block
|
||||
*/
|
||||
double getPriceForBlock(Block block);
|
||||
|
||||
/**
|
||||
* Sells the given blocks
|
||||
*
|
||||
* @param player Player
|
||||
* @param blocks List of blocks
|
||||
*/
|
||||
void sellBlocks(Player player, List<Block> blocks);
|
||||
|
||||
/**
|
||||
* Method to get if player has autosell enabled
|
||||
*
|
||||
* @param p Player
|
||||
* @return true if player has autosell enabled, otherwise false
|
||||
*/
|
||||
boolean hasAutoSellEnabled(Player p);
|
||||
|
||||
/**
|
||||
* Method to get all sell regions
|
||||
*
|
||||
* @return Collection of all loaded and active Sell Regions
|
||||
*/
|
||||
Collection<SellRegion> getSellRegions();
|
||||
|
||||
/**
|
||||
* Method to get SellRegion at specified location
|
||||
*
|
||||
* @return Sell Region at given location or null if not present.
|
||||
*/
|
||||
SellRegion getSellRegionAtLocation(Location location);
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
package me.nvus.xprison.autosell.api;
|
||||
|
||||
import me.nvus.xprison.autosell.XPrisonAutoSell;
|
||||
import me.nvus.xprison.autosell.model.SellRegion;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public final class XPrisonAutoSellAPIImpl implements XPrisonAutoSellAPI {
|
||||
|
||||
private final XPrisonAutoSell plugin;
|
||||
|
||||
public XPrisonAutoSellAPIImpl(XPrisonAutoSell plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getCurrentEarnings(Player player) {
|
||||
return plugin.getManager().getCurrentEarnings(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getPriceForItem(String regionName, ItemStack item) {
|
||||
return plugin.getManager().getPriceForItem(regionName, item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getPriceForBlock(Block block) {
|
||||
return plugin.getManager().getPriceForBlock(block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sellBlocks(Player player, List<Block> blocks) {
|
||||
plugin.getManager().sellBlocks(player, blocks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasAutoSellEnabled(Player p) {
|
||||
return plugin.getManager().hasAutoSellEnabled(p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<SellRegion> getSellRegions() {
|
||||
return plugin.getManager().getAutoSellRegions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SellRegion getSellRegionAtLocation(Location location) {
|
||||
return plugin.getManager().getAutoSellRegion(location);
|
||||
}
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
package me.nvus.xprison.autosell.api.events;
|
||||
|
||||
import me.nvus.xprison.api.events.player.XPrisonPlayerEvent;
|
||||
import me.nvus.xprison.autosell.model.AutoSellItemStack;
|
||||
import me.nvus.xprison.autosell.model.SellRegion;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@Getter
|
||||
public final class XPrisonAutoSellEvent extends XPrisonPlayerEvent implements Cancellable {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
private final Player player;
|
||||
private final SellRegion region;
|
||||
@Setter
|
||||
private Map<AutoSellItemStack, Double> itemsToSell;
|
||||
@Setter
|
||||
private boolean cancelled;
|
||||
|
||||
/**
|
||||
* Called when mined blocks are automatically sold
|
||||
*
|
||||
* @param player Player
|
||||
* @param reg IWrappedRegion where block was mined
|
||||
* @param itemsToSell ItemStacks to sell with prices
|
||||
*/
|
||||
public XPrisonAutoSellEvent(Player player, SellRegion reg, Map<AutoSellItemStack, Double> itemsToSell) {
|
||||
super(player);
|
||||
this.player = player;
|
||||
this.region = reg;
|
||||
this.itemsToSell = itemsToSell;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
package me.nvus.xprison.autosell.api.events;
|
||||
|
||||
import me.nvus.xprison.api.events.player.XPrisonPlayerEvent;
|
||||
import me.nvus.xprison.autosell.model.AutoSellItemStack;
|
||||
import me.nvus.xprison.autosell.model.SellRegion;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@Getter
|
||||
public final class XPrisonSellAllEvent extends XPrisonPlayerEvent implements Cancellable {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
private final Player player;
|
||||
private final SellRegion region;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private Map<AutoSellItemStack, Double> itemsToSell;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private boolean cancelled;
|
||||
|
||||
/**
|
||||
* Called when mined blocks are automatically sold
|
||||
*
|
||||
* @param player Player
|
||||
* @param reg SellRegion where block was mined
|
||||
* @param itemsToSell Map of items to sell with prices as values
|
||||
*/
|
||||
public XPrisonSellAllEvent(Player player, SellRegion reg, Map<AutoSellItemStack, Double> itemsToSell) {
|
||||
super(player);
|
||||
this.player = player;
|
||||
this.region = reg;
|
||||
this.itemsToSell = itemsToSell;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
package me.nvus.xprison.autosell.command;
|
||||
|
||||
import me.nvus.xprison.autosell.XPrisonAutoSell;
|
||||
import me.nvus.xprison.autosell.utils.AutoSellContants;
|
||||
import me.lucko.helper.Commands;
|
||||
|
||||
public class AutoSellCommand {
|
||||
|
||||
private static final String COMMAND_NAME = "autosell";
|
||||
private final XPrisonAutoSell plugin;
|
||||
|
||||
public AutoSellCommand(XPrisonAutoSell plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void register() {
|
||||
Commands.create()
|
||||
.assertPlayer()
|
||||
.assertPermission(AutoSellContants.AUTOSELL_PERMISSION, this.plugin.getAutoSellConfig().getMessage("no_permission_autosell_toggle"))
|
||||
.handler(c -> {
|
||||
if (c.args().size() == 0) {
|
||||
this.plugin.getManager().toggleAutoSell(c.sender());
|
||||
}
|
||||
}).registerAndBind(this.plugin.getCore(), COMMAND_NAME);
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
package me.nvus.xprison.autosell.command;
|
||||
|
||||
import me.nvus.xprison.autosell.XPrisonAutoSell;
|
||||
import me.nvus.xprison.utils.misc.RegionUtils;
|
||||
import me.nvus.xprison.utils.player.PlayerUtils;
|
||||
import me.lucko.helper.Commands;
|
||||
import me.lucko.helper.command.context.CommandContext;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.codemc.worldguardwrapper.WorldGuardWrapper;
|
||||
import org.codemc.worldguardwrapper.region.IWrappedRegion;
|
||||
|
||||
public class SellAllCommand {
|
||||
|
||||
private static final String COMMAND_NAME = "sellall";
|
||||
private final XPrisonAutoSell plugin;
|
||||
|
||||
public SellAllCommand(XPrisonAutoSell plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void register() {
|
||||
Commands.create()
|
||||
.assertPlayer()
|
||||
.handler(c -> {
|
||||
IWrappedRegion region = this.parseRegionFromCommandContext(c);
|
||||
|
||||
if (region == null) {
|
||||
PlayerUtils.sendMessage(c.sender(), this.plugin.getAutoSellConfig().getMessage("invalid_region"));
|
||||
return;
|
||||
}
|
||||
|
||||
this.plugin.getManager().sellAll(c.sender(), region);
|
||||
|
||||
}).registerAndBind(this.plugin.getCore(), COMMAND_NAME);
|
||||
}
|
||||
|
||||
private IWrappedRegion parseRegionFromCommandContext(CommandContext<Player> c) {
|
||||
IWrappedRegion region = null;
|
||||
if (c.args().size() == 0) {
|
||||
region = RegionUtils.getRegionWithHighestPriority(c.sender().getLocation());
|
||||
} else if (c.args().size() == 1) {
|
||||
String regionName = c.rawArg(0);
|
||||
region = WorldGuardWrapper.getInstance().getRegion(c.sender().getLocation().getWorld(), regionName).orElse(null);
|
||||
}
|
||||
return region;
|
||||
}
|
||||
}
|
|
@ -1,139 +0,0 @@
|
|||
package me.nvus.xprison.autosell.command;
|
||||
|
||||
import me.nvus.xprison.autosell.XPrisonAutoSell;
|
||||
import me.nvus.xprison.autosell.gui.AllSellRegionsGui;
|
||||
import me.nvus.xprison.autosell.model.SellRegion;
|
||||
import me.nvus.xprison.autosell.utils.AutoSellContants;
|
||||
import me.nvus.xprison.utils.compat.CompMaterial;
|
||||
import me.nvus.xprison.utils.misc.RegionUtils;
|
||||
import me.nvus.xprison.utils.player.PlayerUtils;
|
||||
import me.lucko.helper.Commands;
|
||||
import me.lucko.helper.command.CommandInterruptException;
|
||||
import me.lucko.helper.command.context.CommandContext;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.codemc.worldguardwrapper.region.IWrappedRegion;
|
||||
|
||||
public class SellPriceCommand {
|
||||
|
||||
private static final String COMMAND_NAME = "sellprice";
|
||||
private final XPrisonAutoSell plugin;
|
||||
|
||||
public SellPriceCommand(XPrisonAutoSell plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void register() {
|
||||
Commands.create()
|
||||
.assertPlayer()
|
||||
.assertPermission(AutoSellContants.ADMIN_PERMISSION)
|
||||
.handler(c -> {
|
||||
|
||||
if (!this.validateContext(c)) {
|
||||
this.sendInvalidUsage(c.sender());
|
||||
return;
|
||||
}
|
||||
|
||||
if (isEditorCommand(c)) {
|
||||
this.openEditorGui(c.sender());
|
||||
return;
|
||||
}
|
||||
|
||||
CompMaterial type = this.parseMaterialFromCommandContext(c);
|
||||
double price = this.parsePriceFromCommandContext(c);
|
||||
|
||||
if (!validateMaterial(type)) {
|
||||
PlayerUtils.sendMessage(c.sender(), "&cInvalid item in hand / specified item!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!validatePrice(price)) {
|
||||
PlayerUtils.sendMessage(c.sender(), "&cSell price needs to be higher than 0!");
|
||||
return;
|
||||
}
|
||||
|
||||
IWrappedRegion wrappedRegion = RegionUtils.getFirstRegionAtLocation(c.sender().getLocation());
|
||||
|
||||
if (!validateRegion(wrappedRegion)) {
|
||||
PlayerUtils.sendMessage(c.sender(), "&cYou must be standing in a region / specify a valid region!");
|
||||
return;
|
||||
}
|
||||
|
||||
SellRegion sellRegion = this.getSellRegionFromWrappedRegion(wrappedRegion);
|
||||
|
||||
if (sellRegion == null) {
|
||||
sellRegion = new SellRegion(wrappedRegion, c.sender().getWorld());
|
||||
}
|
||||
|
||||
sellRegion.addSellPrice(type, price);
|
||||
|
||||
this.plugin.getManager().updateSellRegion(sellRegion);
|
||||
this.plugin.getAutoSellConfig().saveSellRegion(sellRegion);
|
||||
|
||||
PlayerUtils.sendMessage(c.sender(), String.format("&aSuccessfuly set sell price of &e%s &ato &e$%.2f &ain region &e%s", type.name(), price, wrappedRegion.getId()));
|
||||
|
||||
}).registerAndBind(this.plugin.getCore(), COMMAND_NAME);
|
||||
}
|
||||
|
||||
private void openEditorGui(Player sender) {
|
||||
AllSellRegionsGui.createAndOpenTo(sender);
|
||||
}
|
||||
|
||||
private boolean isEditorCommand(CommandContext<Player> c) {
|
||||
return "editor".equalsIgnoreCase(c.rawArg(0));
|
||||
}
|
||||
|
||||
private SellRegion getSellRegionByName(String name) {
|
||||
return this.plugin.getManager().getSellRegionByName(name);
|
||||
}
|
||||
|
||||
private SellRegion getSellRegionFromWrappedRegion(IWrappedRegion region) {
|
||||
return this.plugin.getManager().getSellRegionFromWrappedRegion(region);
|
||||
}
|
||||
|
||||
private boolean validateRegion(IWrappedRegion region) {
|
||||
return region != null;
|
||||
}
|
||||
|
||||
private boolean validatePrice(double price) {
|
||||
return price > 0.0;
|
||||
}
|
||||
|
||||
private boolean validateMaterial(CompMaterial type) {
|
||||
return type != null;
|
||||
}
|
||||
|
||||
private void sendInvalidUsage(Player player) {
|
||||
PlayerUtils.sendMessage(player, "&cInvalid usage!");
|
||||
PlayerUtils.sendMessage(player, "&c/sellprice editor - Opens Editor GUI for sell prices");
|
||||
PlayerUtils.sendMessage(player, "&c/sellprice <material> <price> - Sets the sell price of specified material.");
|
||||
PlayerUtils.sendMessage(player, "&c/sellprice <price> - Sets the sell price of item material you have in your hand.");
|
||||
}
|
||||
|
||||
private boolean validateContext(CommandContext<Player> context) {
|
||||
return context.args().size() == 1 || context.args().size() == 2 || context.args().size() == 3;
|
||||
}
|
||||
|
||||
private CompMaterial parseMaterialFromCommandContext(CommandContext<Player> c) {
|
||||
CompMaterial material = null;
|
||||
if (c.args().size() == 1) {
|
||||
if (c.sender().getItemInHand() == null) {
|
||||
PlayerUtils.sendMessage(c.sender(), "&cPlease hold some item!");
|
||||
} else {
|
||||
material = CompMaterial.fromItem(c.sender().getItemInHand());
|
||||
}
|
||||
} else if (c.args().size() == 2) {
|
||||
material = CompMaterial.fromString(c.rawArg(0));
|
||||
}
|
||||
return material;
|
||||
}
|
||||
|
||||
private double parsePriceFromCommandContext(CommandContext<Player> c) throws CommandInterruptException {
|
||||
double price = 0.0;
|
||||
if (c.args().size() == 1) {
|
||||
price = c.arg(0).parseOrFail(Double.class);
|
||||
} else if (c.args().size() == 2) {
|
||||
price = c.arg(1).parseOrFail(Double.class);
|
||||
}
|
||||
return price;
|
||||
}
|
||||
}
|
|
@ -1,112 +0,0 @@
|
|||
package me.nvus.xprison.autosell.config;
|
||||
|
||||
import me.nvus.xprison.autosell.XPrisonAutoSell;
|
||||
import me.nvus.xprison.autosell.model.SellRegion;
|
||||
import me.nvus.xprison.config.FileManager;
|
||||
import me.nvus.xprison.utils.compat.CompMaterial;
|
||||
import me.nvus.xprison.utils.text.TextUtils;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class AutoSellConfig {
|
||||
|
||||
private final XPrisonAutoSell plugin;
|
||||
private final FileManager.Config config;
|
||||
|
||||
private Map<String, String> messages;
|
||||
private boolean enableAutosellAutomatically;
|
||||
private boolean autoSmelt;
|
||||
private int autoSellBroadcastTime;
|
||||
private List<String> autoSellBroadcastMessage;
|
||||
private boolean inventoryFullNotificationEnabled;
|
||||
private List<String> inventoryFullNotificationTitle;
|
||||
private String inventoryFullNotificationMessage;
|
||||
|
||||
|
||||
public AutoSellConfig(XPrisonAutoSell plugin) {
|
||||
this.plugin = plugin;
|
||||
this.config = this.plugin.getCore().getFileManager().getConfig("autosell.yml").copyDefaults(true).save();
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
this.getConfig().reload();
|
||||
this.load();
|
||||
}
|
||||
|
||||
public void load() {
|
||||
this.loadVariables();
|
||||
}
|
||||
|
||||
private void loadVariables() {
|
||||
this.loadMessages();
|
||||
this.autoSellBroadcastTime = this.getYamlConfig().getInt("auto_sell_broadcast.time");
|
||||
this.autoSellBroadcastMessage = this.getYamlConfig().getStringList("auto_sell_broadcast.message");
|
||||
this.enableAutosellAutomatically = this.getYamlConfig().getBoolean("enable-autosell-automatically");
|
||||
this.autoSmelt = this.getYamlConfig().getBoolean("auto-smelt");
|
||||
this.inventoryFullNotificationEnabled = this.getYamlConfig().getBoolean("inventory_full_notification.enabled");
|
||||
this.inventoryFullNotificationTitle = this.getYamlConfig().getStringList("inventory_full_notification.title");
|
||||
this.inventoryFullNotificationMessage = this.getYamlConfig().getString("inventory_full_notification.chat");
|
||||
}
|
||||
|
||||
private void loadMessages() {
|
||||
this.messages = new HashMap<>();
|
||||
for (String key : this.getYamlConfig().getConfigurationSection("messages").getKeys(false)) {
|
||||
messages.put(key.toLowerCase(), TextUtils.applyColor(this.getYamlConfig().getString("messages." + key)));
|
||||
}
|
||||
}
|
||||
|
||||
private FileManager.Config getConfig() {
|
||||
return this.config;
|
||||
}
|
||||
|
||||
public YamlConfiguration getYamlConfig() {
|
||||
return this.config.get();
|
||||
}
|
||||
|
||||
public String getMessage(String key) {
|
||||
return messages.getOrDefault(key.toLowerCase(), "Message not found with key: " + key);
|
||||
}
|
||||
|
||||
public boolean isEnableAutosellAutomatically() {
|
||||
return enableAutosellAutomatically;
|
||||
}
|
||||
|
||||
public boolean isAutoSmelt() {
|
||||
return autoSmelt;
|
||||
}
|
||||
|
||||
public int getAutoSellBroadcastTime() {
|
||||
return autoSellBroadcastTime;
|
||||
}
|
||||
|
||||
public List<String> getAutoSellBroadcastMessage() {
|
||||
return autoSellBroadcastMessage;
|
||||
}
|
||||
|
||||
public boolean isInventoryFullNotificationEnabled() {
|
||||
return inventoryFullNotificationEnabled;
|
||||
}
|
||||
|
||||
public List<String> getInventoryFullNotificationTitle() {
|
||||
return inventoryFullNotificationTitle;
|
||||
}
|
||||
|
||||
public String getInventoryFullNotificationMessage() {
|
||||
return inventoryFullNotificationMessage;
|
||||
}
|
||||
|
||||
public void saveSellRegion(SellRegion region) {
|
||||
this.getConfig().set("regions." + region.getRegion().getId() + ".world", region.getWorld().getName());
|
||||
for (CompMaterial material : region.getSellingMaterials()) {
|
||||
double sellPrice = region.getSellPriceForMaterial(material);
|
||||
if (sellPrice <= 0.0) {
|
||||
continue;
|
||||
}
|
||||
this.getConfig().set("regions." + region.getRegion().getId() + ".items." + material.name(), sellPrice);
|
||||
}
|
||||
this.getConfig().save();
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
package me.nvus.xprison.autosell.gui;
|
||||
|
||||
import me.nvus.xprison.autosell.XPrisonAutoSell;
|
||||
import me.nvus.xprison.autosell.model.SellRegion;
|
||||
import me.nvus.xprison.utils.item.ItemStackBuilder;
|
||||
import me.lucko.helper.menu.Item;
|
||||
import me.lucko.helper.menu.paginated.PaginatedGui;
|
||||
import me.lucko.helper.menu.paginated.PaginatedGuiBuilder;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public final class AllSellRegionsGui {
|
||||
|
||||
private AllSellRegionsGui() {
|
||||
throw new UnsupportedOperationException("Cannot instantiate");
|
||||
}
|
||||
|
||||
public static void createAndOpenTo(Player player) {
|
||||
|
||||
PaginatedGuiBuilder builder = PaginatedGuiBuilder.create();
|
||||
|
||||
builder.title("Sell Regions");
|
||||
builder.lines(6);
|
||||
builder.previousPageSlot(45);
|
||||
builder.nextPageSlot(53);
|
||||
builder.nextPageItem((pageInfo) -> ItemStackBuilder.of(Material.ARROW).name("&aNext Page").lore("&7Click to see next page.").build());
|
||||
builder.previousPageItem((pageInfo) -> ItemStackBuilder.of(Material.ARROW).name("&aPrevious Page").lore("&7Click to see previous page.").build());
|
||||
|
||||
Collection<SellRegion> regions = getSellRegions();
|
||||
PaginatedGui gui = builder.build(player, paginatedGui -> regions.stream().map(sellRegion -> buildItemForSellRegion(sellRegion, player)).collect(Collectors.toList()));
|
||||
gui.open();
|
||||
}
|
||||
|
||||
private static Item buildItemForSellRegion(SellRegion sellRegion, Player player) {
|
||||
return ItemStackBuilder.of(Material.DIAMOND_PICKAXE)
|
||||
.name(sellRegion.getRegion().getId())
|
||||
.lore(" ", "&7Click to edit sell prices.", " ")
|
||||
.build(() -> new SellRegionGui(sellRegion, player).open());
|
||||
}
|
||||
|
||||
private static Collection<SellRegion> getSellRegions() {
|
||||
return XPrisonAutoSell.getInstance().getManager().getAutoSellRegions();
|
||||
}
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
package me.nvus.xprison.autosell.gui;
|
||||
|
||||
import me.nvus.xprison.autosell.XPrisonAutoSell;
|
||||
import me.nvus.xprison.autosell.model.SellRegion;
|
||||
import me.nvus.xprison.autosell.utils.SellPriceComparator;
|
||||
import me.nvus.xprison.utils.compat.CompMaterial;
|
||||
import me.nvus.xprison.utils.item.ItemStackBuilder;
|
||||
import me.lucko.helper.menu.Gui;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public final class SellRegionGui extends Gui {
|
||||
|
||||
private final SellRegion sellRegion;
|
||||
|
||||
public SellRegionGui(SellRegion sellRegion, Player player) {
|
||||
super(player, 6, sellRegion.getRegion().getId() + " Prices");
|
||||
this.sellRegion = sellRegion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void redraw() {
|
||||
this.clearItems();
|
||||
|
||||
this.setActionItems();
|
||||
|
||||
this.setBackItem();
|
||||
}
|
||||
|
||||
private void setBackItem() {
|
||||
this.setItem(45, ItemStackBuilder.of(Material.ARROW).name("&cBack").lore("&7Click to go back to all regions").build(() -> {
|
||||
this.close();
|
||||
AllSellRegionsGui.createAndOpenTo(this.getPlayer());
|
||||
}));
|
||||
}
|
||||
|
||||
private void setActionItems() {
|
||||
for (CompMaterial material : this.sellRegion.getSellingMaterialsSorted(new SellPriceComparator(sellRegion))) {
|
||||
this.addItemForMaterial(material);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void addItemForMaterial(CompMaterial material) {
|
||||
double price = this.sellRegion.getSellPriceForMaterial(material);
|
||||
|
||||
this.addItem(ItemStackBuilder.of(material.toItem()).name(material.name()).lore(" ", String.format("&7Sell Price: &2$&a%,.2f", price), " ", "&aLeft-Click &7to edit the price", "&aRight-Click &7to remove.").build(() -> {
|
||||
this.deleteSellPrice(material);
|
||||
this.redraw();
|
||||
}, () -> {
|
||||
new UpdateSellPriceGui(this.getPlayer(), sellRegion, material).open();
|
||||
}));
|
||||
}
|
||||
|
||||
private void deleteSellPrice(CompMaterial material) {
|
||||
this.sellRegion.removeSellPrice(material);
|
||||
XPrisonAutoSell.getInstance().getAutoSellConfig().saveSellRegion(sellRegion);
|
||||
}
|
||||
}
|
|
@ -1,86 +0,0 @@
|
|||
package me.nvus.xprison.autosell.gui;
|
||||
|
||||
import me.nvus.xprison.autosell.XPrisonAutoSell;
|
||||
import me.nvus.xprison.autosell.model.SellRegion;
|
||||
import me.nvus.xprison.utils.compat.CompMaterial;
|
||||
import me.nvus.xprison.utils.item.ItemStackBuilder;
|
||||
import me.lucko.helper.menu.Gui;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public final class UpdateSellPriceGui extends Gui {
|
||||
|
||||
private final SellRegion sellRegion;
|
||||
private final CompMaterial material;
|
||||
private double price;
|
||||
|
||||
public UpdateSellPriceGui(Player player, SellRegion sellRegion, CompMaterial material) {
|
||||
super(player, 5, "Editing Sell Price");
|
||||
this.sellRegion = sellRegion;
|
||||
this.material = material;
|
||||
this.price = sellRegion.getSellPriceForMaterial(material);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void redraw() {
|
||||
this.setPreviewItem();
|
||||
this.setActionItems();
|
||||
this.setBackItem();
|
||||
this.setSaveItem();
|
||||
}
|
||||
|
||||
private void setPreviewItem() {
|
||||
this.setItem(4, ItemStackBuilder.of(this.material.toItem()).name("&eSell Price").lore(" ", "&7Selling price for this block", String.format("&7in region &b%s &7is &2$&a%,.2f", this.sellRegion.getRegion().getId(), this.price)).buildItem().build());
|
||||
}
|
||||
|
||||
private void setSaveItem() {
|
||||
this.setItem(40, ItemStackBuilder.of(CompMaterial.GREEN_WOOL.toItem()).name("&aSave").lore("&7Click to save the current price.").build(() -> {
|
||||
this.saveChanges();
|
||||
this.close();
|
||||
new SellRegionGui(this.sellRegion, this.getPlayer()).open();
|
||||
}));
|
||||
}
|
||||
|
||||
private void setBackItem() {
|
||||
this.setItem(36, ItemStackBuilder.of(Material.ARROW).name("&cBack").lore("&7Click to go back to all blocks.").build(() -> {
|
||||
this.close();
|
||||
new SellRegionGui(this.sellRegion, this.getPlayer()).open();
|
||||
}));
|
||||
}
|
||||
|
||||
private void setActionItems() {
|
||||
this.setItem(10, ItemStackBuilder.of(CompMaterial.GREEN_STAINED_GLASS_PANE.toItem()).name("&a+$1.0").build(() -> handleAddition(1.0)));
|
||||
this.setItem(11, ItemStackBuilder.of(CompMaterial.GREEN_STAINED_GLASS_PANE.toItem()).name("&a+$5.0").build(() -> handleAddition(5.0)));
|
||||
this.setItem(12, ItemStackBuilder.of(CompMaterial.GREEN_STAINED_GLASS_PANE.toItem()).name("&a+$10.0").build(() -> handleAddition(10.0)));
|
||||
this.setItem(19, ItemStackBuilder.of(CompMaterial.GREEN_STAINED_GLASS_PANE.toItem()).name("&a+$25.0").build(() -> handleAddition(25.0)));
|
||||
this.setItem(20, ItemStackBuilder.of(CompMaterial.GREEN_STAINED_GLASS_PANE.toItem()).name("&a+$50.0").build(() -> handleAddition(50.0)));
|
||||
this.setItem(21, ItemStackBuilder.of(CompMaterial.GREEN_STAINED_GLASS_PANE.toItem()).name("&a+$100.0").build(() -> handleAddition(100.0)));
|
||||
this.setItem(28, ItemStackBuilder.of(CompMaterial.GREEN_STAINED_GLASS_PANE.toItem()).name("&a+$250.0").build(() -> handleAddition(250.0)));
|
||||
this.setItem(29, ItemStackBuilder.of(CompMaterial.GREEN_STAINED_GLASS_PANE.toItem()).name("&a+$500.0").build(() -> handleAddition(500.0)));
|
||||
this.setItem(30, ItemStackBuilder.of(CompMaterial.GREEN_STAINED_GLASS_PANE.toItem()).name("&a+$1000.0").build(() -> handleAddition(1000.0)));
|
||||
|
||||
this.setItem(14, ItemStackBuilder.of(CompMaterial.RED_STAINED_GLASS_PANE.toItem()).name("&c-$1.0").build(() -> handleAddition(-1.0)));
|
||||
this.setItem(15, ItemStackBuilder.of(CompMaterial.RED_STAINED_GLASS_PANE.toItem()).name("&c-$5.0").build(() -> handleAddition(-5.0)));
|
||||
this.setItem(16, ItemStackBuilder.of(CompMaterial.RED_STAINED_GLASS_PANE.toItem()).name("&c-$10.0").build(() -> handleAddition(-10.0)));
|
||||
this.setItem(23, ItemStackBuilder.of(CompMaterial.RED_STAINED_GLASS_PANE.toItem()).name("&c-$25.0").build(() -> handleAddition(-25.0)));
|
||||
this.setItem(24, ItemStackBuilder.of(CompMaterial.RED_STAINED_GLASS_PANE.toItem()).name("&c-$50.0").build(() -> handleAddition(-50.0)));
|
||||
this.setItem(25, ItemStackBuilder.of(CompMaterial.RED_STAINED_GLASS_PANE.toItem()).name("&c-$100.0").build(() -> handleAddition(-100.0)));
|
||||
this.setItem(32, ItemStackBuilder.of(CompMaterial.RED_STAINED_GLASS_PANE.toItem()).name("&c-$250.0").build(() -> handleAddition(-250.0)));
|
||||
this.setItem(33, ItemStackBuilder.of(CompMaterial.RED_STAINED_GLASS_PANE.toItem()).name("&c-$500.0").build(() -> handleAddition(-500.0)));
|
||||
this.setItem(34, ItemStackBuilder.of(CompMaterial.RED_STAINED_GLASS_PANE.toItem()).name("&c-$1000.0").build(() -> handleAddition(-1000.0)));
|
||||
}
|
||||
|
||||
private void saveChanges() {
|
||||
this.sellRegion.addSellPrice(this.material, this.price);
|
||||
XPrisonAutoSell.getInstance().getAutoSellConfig().saveSellRegion(sellRegion);
|
||||
}
|
||||
|
||||
private void handleAddition(double addition) {
|
||||
if (this.price + addition < 0.0) {
|
||||
this.price = 0.0;
|
||||
} else {
|
||||
this.price += addition;
|
||||
}
|
||||
this.redraw();
|
||||
}
|
||||
}
|
|
@ -1,79 +0,0 @@
|
|||
package me.nvus.xprison.autosell.listener;
|
||||
|
||||
import me.nvus.xprison.autosell.XPrisonAutoSell;
|
||||
import me.nvus.xprison.autosell.model.SellRegion;
|
||||
import me.nvus.xprison.utils.compat.CompMaterial;
|
||||
import me.nvus.xprison.utils.player.PlayerUtils;
|
||||
import me.lucko.helper.Events;
|
||||
import me.lucko.helper.Schedulers;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.world.WorldLoadEvent;
|
||||
|
||||
public class AutoSellListener {
|
||||
|
||||
private final XPrisonAutoSell plugin;
|
||||
|
||||
public AutoSellListener(XPrisonAutoSell plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void subscribeToEvents() {
|
||||
this.subscribeToPlayerJoinEvent();
|
||||
this.subscribeToBlockBreakEvent();
|
||||
this.subscribeToWorldLoadEvent();
|
||||
}
|
||||
|
||||
private void subscribeToWorldLoadEvent() {
|
||||
Events.subscribe(WorldLoadEvent.class)
|
||||
.handler(e -> this.plugin.getManager().loadPostponedAutoSellRegions(e.getWorld())).bindWith(this.plugin.getCore());
|
||||
}
|
||||
|
||||
private void subscribeToPlayerJoinEvent() {
|
||||
Events.subscribe(PlayerJoinEvent.class)
|
||||
.handler(e -> Schedulers.sync().runLater(() -> {
|
||||
|
||||
if (this.plugin.getManager().hasAutoSellEnabled(e.getPlayer())) {
|
||||
PlayerUtils.sendMessage(e.getPlayer(), this.plugin.getAutoSellConfig().getMessage("autosell_enable"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.plugin.getManager().canPlayerEnableAutosellOnJoin(e.getPlayer())) {
|
||||
this.plugin.getManager().toggleAutoSell(e.getPlayer());
|
||||
}
|
||||
}, 20)).bindWith(this.plugin.getCore());
|
||||
}
|
||||
|
||||
private void subscribeToBlockBreakEvent() {
|
||||
|
||||
Events.subscribe(BlockBreakEvent.class, EventPriority.HIGHEST)
|
||||
.filter(e -> !e.isCancelled() && e.getPlayer().getItemInHand() != null && this.plugin.getCore().isPickaxeSupported(e.getPlayer().getItemInHand().getType()))
|
||||
.handler(e -> {
|
||||
|
||||
SellRegion sellRegion = this.plugin.getManager().getAutoSellRegion(e.getBlock().getLocation());
|
||||
|
||||
if (sellRegion == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean success = false;
|
||||
|
||||
if (this.plugin.getManager().hasAutoSellEnabled(e.getPlayer())) {
|
||||
success = this.plugin.getManager().autoSellBlock(e.getPlayer(), e.getBlock());
|
||||
}
|
||||
|
||||
if (!success) {
|
||||
success = this.plugin.getManager().givePlayerItem(e.getPlayer(), e.getBlock());
|
||||
}
|
||||
|
||||
if (success) {
|
||||
// Do not set block to air due compatibility issues
|
||||
e.setDropItems(false);
|
||||
} else {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}).bindWith(this.plugin.getCore());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,408 +0,0 @@
|
|||
package me.nvus.xprison.autosell.manager;
|
||||
|
||||
import me.nvus.xprison.autosell.XPrisonAutoSell;
|
||||
import me.nvus.xprison.autosell.api.events.XPrisonAutoSellEvent;
|
||||
import me.nvus.xprison.autosell.api.events.XPrisonSellAllEvent;
|
||||
import me.nvus.xprison.autosell.model.AutoSellItemStack;
|
||||
import me.nvus.xprison.autosell.model.SellRegion;
|
||||
import me.nvus.xprison.autosell.utils.AutoSellContants;
|
||||
import me.nvus.xprison.enchants.utils.EnchantUtils;
|
||||
import me.nvus.xprison.multipliers.enums.MultiplierType;
|
||||
import me.nvus.xprison.utils.compat.CompMaterial;
|
||||
import me.nvus.xprison.utils.economy.EconomyUtils;
|
||||
import me.nvus.xprison.utils.inventory.InventoryUtils;
|
||||
import me.nvus.xprison.utils.misc.MaterialUtils;
|
||||
import me.nvus.xprison.utils.player.PlayerUtils;
|
||||
import me.lucko.helper.Events;
|
||||
import me.lucko.helper.cooldown.Cooldown;
|
||||
import me.lucko.helper.cooldown.CooldownMap;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.codemc.worldguardwrapper.WorldGuardWrapper;
|
||||
import org.codemc.worldguardwrapper.region.IWrappedRegion;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class AutoSellManager {
|
||||
|
||||
private static final CooldownMap<Player> INVENTORY_FULL_COOLDOWN_MAP = CooldownMap.create(Cooldown.of(2, TimeUnit.SECONDS));
|
||||
|
||||
private final XPrisonAutoSell plugin;
|
||||
private final Map<UUID, Double> lastEarnings;
|
||||
private final Map<UUID, Long> lastItems;
|
||||
private final Map<String, SellRegion> regionsAutoSell;
|
||||
private final List<UUID> enabledAutoSellPlayers;
|
||||
private final Map<String, Set<String>> notLoadedSellRegions;
|
||||
|
||||
public AutoSellManager(XPrisonAutoSell plugin) {
|
||||
this.plugin = plugin;
|
||||
this.enabledAutoSellPlayers = new ArrayList<>();
|
||||
this.lastEarnings = new HashMap<>();
|
||||
this.lastItems = new HashMap<>();
|
||||
this.regionsAutoSell = new HashMap<>();
|
||||
this.notLoadedSellRegions = new HashMap<>();
|
||||
}
|
||||
|
||||
|
||||
private void loadAutoSellRegions() {
|
||||
this.regionsAutoSell.clear();
|
||||
|
||||
YamlConfiguration configuration = this.plugin.getAutoSellConfig().getYamlConfig();
|
||||
|
||||
ConfigurationSection section = configuration.getConfigurationSection("regions");
|
||||
|
||||
if (section == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (String regName : section.getKeys(false)) {
|
||||
this.loadSellRegionFromConfig(configuration, regName);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean loadSellRegionFromConfig(YamlConfiguration config, String regionName) {
|
||||
|
||||
String worldName = config.getString("regions." + regionName + ".world");
|
||||
|
||||
World world = Bukkit.getWorld(worldName);
|
||||
|
||||
if (world == null) {
|
||||
this.plugin.getCore().getLogger().warning("There is no such World named " + worldName + "! Perhaps its no loaded yet?");
|
||||
this.plugin.getCore().getLogger().warning("Postponing loading of region " + regionName + ".");
|
||||
this.postponeLoadingOfSellRegion(worldName, regionName);
|
||||
return false;
|
||||
}
|
||||
|
||||
IWrappedRegion region = this.validateWrappedRegion(regionName, world);
|
||||
|
||||
if (region == null) {
|
||||
this.plugin.getCore().getLogger().warning("There is no such WorldGuard region named " + regionName + " in world " + world.getName());
|
||||
return false;
|
||||
}
|
||||
|
||||
String permRequired = config.getString("regions." + regionName + ".permission");
|
||||
|
||||
Map<CompMaterial, Double> sellPrices = this.loadSellPricesForRegion(config, regionName);
|
||||
|
||||
SellRegion sellRegion = new SellRegion(region, world, permRequired, sellPrices);
|
||||
this.regionsAutoSell.put(regionName, sellRegion);
|
||||
|
||||
this.plugin.getCore().getLogger().info("Loaded auto-sell region named '" + regionName + "'");
|
||||
return true;
|
||||
}
|
||||
|
||||
private void postponeLoadingOfSellRegion(String worldName, String regionName) {
|
||||
Set<String> currentlyPostponed = this.notLoadedSellRegions.getOrDefault(worldName, new HashSet<>());
|
||||
currentlyPostponed.add(regionName);
|
||||
this.notLoadedSellRegions.put(worldName, currentlyPostponed);
|
||||
}
|
||||
|
||||
private IWrappedRegion validateWrappedRegion(String regionName, World world) {
|
||||
Optional<IWrappedRegion> optRegion = WorldGuardWrapper.getInstance().getRegion(world, regionName);
|
||||
return optRegion.orElse(null);
|
||||
}
|
||||
|
||||
private Map<CompMaterial, Double> loadSellPricesForRegion(YamlConfiguration config, String regionName) {
|
||||
Map<CompMaterial, Double> sellPrices = new HashMap<>();
|
||||
|
||||
for (String item : config.getConfigurationSection("regions." + regionName + ".items").getKeys(false)) {
|
||||
CompMaterial type = CompMaterial.valueOf(item);
|
||||
double sellPrice = config.getDouble("regions." + regionName + ".items." + item);
|
||||
sellPrices.put(type, sellPrice);
|
||||
}
|
||||
return sellPrices;
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
this.load();
|
||||
}
|
||||
|
||||
public void load() {
|
||||
this.loadAutoSellRegions();
|
||||
}
|
||||
|
||||
|
||||
public void sellAll(Player sender, IWrappedRegion region) {
|
||||
|
||||
if (!this.validateRegionBeforeSellAll(sender, region)) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.plugin.getCore().debug("User " + sender.getName() + " ran /sellall in region " + region.getId(), this.plugin);
|
||||
|
||||
SellRegion sellRegion = regionsAutoSell.get(region.getId());
|
||||
|
||||
if (!checkIfPlayerCanSellInSellRegion(sender, sellRegion)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Map<AutoSellItemStack, Double> itemsToSell = sellRegion.previewInventorySell(sender);
|
||||
|
||||
XPrisonSellAllEvent event = this.callSellAllEvent(sender, sellRegion, itemsToSell);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
itemsToSell = event.getItemsToSell();
|
||||
|
||||
double totalAmount = this.sellItems(sender, itemsToSell);
|
||||
|
||||
itemsToSell.keySet().forEach(item -> sender.getInventory().remove(item.getItemStack()));
|
||||
|
||||
if (totalAmount > 0.0) {
|
||||
PlayerUtils.sendMessage(sender, this.plugin.getAutoSellConfig().getMessage("sell_all_complete").replace("%price%", String.format("%,.0f", totalAmount)));
|
||||
}
|
||||
}
|
||||
|
||||
private double sellItems(Player player, Map<AutoSellItemStack, Double> itemsToSell) {
|
||||
|
||||
double totalAmount = itemsToSell.values().stream().mapToDouble(Double::doubleValue).sum();
|
||||
|
||||
if (this.plugin.isMultipliersModuleEnabled()) {
|
||||
totalAmount = (long) this.plugin.getCore().getMultipliers().getApi().getTotalToDeposit(player, totalAmount, MultiplierType.SELL);
|
||||
}
|
||||
|
||||
EconomyUtils.deposit(player, totalAmount);
|
||||
return totalAmount;
|
||||
}
|
||||
|
||||
private XPrisonSellAllEvent callSellAllEvent(Player sender, SellRegion sellRegion, Map<AutoSellItemStack, Double> sellItems) {
|
||||
XPrisonSellAllEvent event = new XPrisonSellAllEvent(sender, sellRegion, sellItems);
|
||||
|
||||
Events.call(event);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
this.plugin.getCore().debug("XPrisonSellAllEvent was cancelled.", this.plugin);
|
||||
}
|
||||
|
||||
return event;
|
||||
}
|
||||
|
||||
private XPrisonAutoSellEvent callAutoSellEvent(Player player, SellRegion sellRegion, Map<AutoSellItemStack, Double> itemsToSell) {
|
||||
XPrisonAutoSellEvent event = new XPrisonAutoSellEvent(player, sellRegion, itemsToSell);
|
||||
|
||||
Events.call(event);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
this.plugin.getCore().debug("XPrisonAutoSellEvent was cancelled.", this.plugin);
|
||||
}
|
||||
|
||||
return event;
|
||||
}
|
||||
|
||||
private boolean checkIfPlayerCanSellInSellRegion(Player sender, SellRegion sellRegion) {
|
||||
if (!sellRegion.canPlayerSellInRegion(sender)) {
|
||||
PlayerUtils.sendMessage(sender, this.plugin.getAutoSellConfig().getMessage("no_permission_sell").replace("%perm%", sellRegion.getPermissionRequired()));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean validateRegionBeforeSellAll(Player sender, IWrappedRegion region) {
|
||||
|
||||
if (region == null) {
|
||||
//PlayerUtils.sendMessage(sender, this.plugin.getAutoSellConfig().getMessage("not_in_region"));
|
||||
return false;
|
||||
}
|
||||
|
||||
return isAutoSellRegion(region);
|
||||
}
|
||||
|
||||
private boolean isAutoSellRegion(IWrappedRegion region) {
|
||||
return regionsAutoSell.containsKey(region.getId());
|
||||
}
|
||||
|
||||
public void resetLastEarnings() {
|
||||
this.lastEarnings.clear();
|
||||
}
|
||||
|
||||
public void resetLastItems() {
|
||||
this.lastItems.clear();
|
||||
}
|
||||
|
||||
public double getPlayerLastEarnings(Player p) {
|
||||
return this.lastEarnings.getOrDefault(p.getUniqueId(), 0.0D);
|
||||
}
|
||||
|
||||
public long getPlayerLastItemsAmount(Player p) {
|
||||
return this.lastItems.getOrDefault(p.getUniqueId(), 0L);
|
||||
}
|
||||
|
||||
public double getCurrentEarnings(Player player) {
|
||||
return lastEarnings.getOrDefault(player.getUniqueId(), 0.0);
|
||||
}
|
||||
|
||||
public double getPriceForItem(String regionName, ItemStack item) {
|
||||
SellRegion region = regionsAutoSell.get(regionName);
|
||||
if (region != null) {
|
||||
return region.getPriceForItem(item);
|
||||
}
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
public boolean hasAutoSellEnabled(Player p) {
|
||||
return enabledAutoSellPlayers.contains(p.getUniqueId());
|
||||
}
|
||||
|
||||
public Collection<SellRegion> getAutoSellRegions() {
|
||||
return this.regionsAutoSell.values();
|
||||
}
|
||||
|
||||
public SellRegion getAutoSellRegion(Location location) {
|
||||
for (SellRegion region : this.regionsAutoSell.values()) {
|
||||
if (region.contains(location)) {
|
||||
return region;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void toggleAutoSell(Player player) {
|
||||
boolean removed = enabledAutoSellPlayers.remove(player.getUniqueId());
|
||||
|
||||
if (removed) {
|
||||
PlayerUtils.sendMessage(player, this.plugin.getAutoSellConfig().getMessage("autosell_disable"));
|
||||
} else {
|
||||
PlayerUtils.sendMessage(player, this.plugin.getAutoSellConfig().getMessage("autosell_enable"));
|
||||
enabledAutoSellPlayers.add(player.getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canPlayerEnableAutosellOnJoin(Player player) {
|
||||
if (!this.plugin.getAutoSellConfig().isEnableAutosellAutomatically()) {
|
||||
return false;
|
||||
}
|
||||
return player.hasPermission(AutoSellContants.AUTOSELL_PERMISSION) && !hasAutoSellEnabled(player);
|
||||
}
|
||||
|
||||
public SellRegion getSellRegionFromWrappedRegion(IWrappedRegion region) {
|
||||
return regionsAutoSell.getOrDefault(region.getId(), null);
|
||||
}
|
||||
|
||||
public void updateSellRegion(SellRegion sellRegion) {
|
||||
this.regionsAutoSell.put(sellRegion.getRegion().getId(), sellRegion);
|
||||
}
|
||||
|
||||
public boolean givePlayerItem(Player player, Block block) {
|
||||
|
||||
if (!InventoryUtils.hasSpace(player.getInventory())) {
|
||||
this.notifyInventoryFull(player);
|
||||
return true;
|
||||
}
|
||||
|
||||
player.getInventory().addItem(createItemStackToGive(player, block));
|
||||
return true;
|
||||
}
|
||||
|
||||
private ItemStack createItemStackToGive(Player player, Block block) {
|
||||
int amount = EnchantUtils.getFortuneBlockCount(player.getItemInHand(), block);
|
||||
|
||||
ItemStack toGive;
|
||||
|
||||
if (this.plugin.getAutoSellConfig().isAutoSmelt()) {
|
||||
toGive = MaterialUtils.getSmeltedFormAsItemStack(block);
|
||||
} else {
|
||||
toGive = CompMaterial.fromBlock(block).toItem();
|
||||
}
|
||||
toGive.setAmount(amount);
|
||||
return toGive;
|
||||
}
|
||||
|
||||
private void notifyInventoryFull(Player player) {
|
||||
|
||||
if (!this.plugin.getAutoSellConfig().isInventoryFullNotificationEnabled() || !INVENTORY_FULL_COOLDOWN_MAP.test(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<String> inventoryFullTitle = this.plugin.getAutoSellConfig().getInventoryFullNotificationTitle();
|
||||
String inventoryFullNotificationMessage = this.plugin.getAutoSellConfig().getInventoryFullNotificationMessage();
|
||||
|
||||
if (!inventoryFullTitle.isEmpty()) {
|
||||
PlayerUtils.sendTitle(player, inventoryFullTitle.get(0), inventoryFullTitle.get(1));
|
||||
} else {
|
||||
PlayerUtils.sendMessage(player, inventoryFullNotificationMessage);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean autoSellBlock(Player player, Block block) {
|
||||
|
||||
SellRegion sellRegion = this.getAutoSellRegion(block.getLocation());
|
||||
|
||||
if (sellRegion == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Map<AutoSellItemStack, Double> itemsToSell = sellRegion.previewItemsSell(Arrays.asList(createItemStackToGive(player, block)));
|
||||
|
||||
XPrisonAutoSellEvent event = this.callAutoSellEvent(player, sellRegion, itemsToSell);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
itemsToSell = event.getItemsToSell();
|
||||
|
||||
int amountOfItems = itemsToSell.keySet().stream().mapToInt(item -> item.getItemStack().getAmount()).sum();
|
||||
double moneyEarned = this.sellItems(player, itemsToSell);
|
||||
|
||||
this.updateCurrentEarningsAndLastItems(player, moneyEarned, amountOfItems);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void updateCurrentEarningsAndLastItems(Player player, double moneyEarned, int amountOfItems) {
|
||||
this.addToCurrentEarnings(player, moneyEarned);
|
||||
this.addToLastItems(player, amountOfItems);
|
||||
}
|
||||
|
||||
public void addToCurrentEarnings(Player player, double amount) {
|
||||
double current = this.lastEarnings.getOrDefault(player.getUniqueId(), 0.0);
|
||||
this.lastEarnings.put(player.getUniqueId(), current + amount);
|
||||
}
|
||||
|
||||
public void addToLastItems(Player player, int amountOfItems) {
|
||||
long current = this.lastItems.getOrDefault(player.getUniqueId(), 0L);
|
||||
this.lastItems.put(player.getUniqueId(), current + amountOfItems);
|
||||
}
|
||||
|
||||
public double getPriceForBlock(String regionName, Block block) {
|
||||
CompMaterial material = CompMaterial.fromBlock(block);
|
||||
SellRegion region = regionsAutoSell.get(regionName);
|
||||
if (region != null) {
|
||||
return region.getSellPriceForMaterial(material);
|
||||
}
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
public double getPriceForBlock(Block block) {
|
||||
CompMaterial material = CompMaterial.fromBlock(block);
|
||||
SellRegion region = getAutoSellRegion(block.getLocation());
|
||||
if (region != null) {
|
||||
return region.getSellPriceForMaterial(material);
|
||||
}
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
public void loadPostponedAutoSellRegions(World world) {
|
||||
YamlConfiguration configuration = this.plugin.getAutoSellConfig().getYamlConfig();
|
||||
Set<String> regionNames = this.notLoadedSellRegions.getOrDefault(world.getName(), new HashSet<>());
|
||||
regionNames.removeIf(regionName -> this.loadSellRegionFromConfig(configuration, regionName));
|
||||
this.notLoadedSellRegions.put(world.getName(), regionNames);
|
||||
}
|
||||
|
||||
public SellRegion getSellRegionByName(String name) {
|
||||
return regionsAutoSell.get(name);
|
||||
}
|
||||
|
||||
public void sellBlocks(Player player, List<Block> blocks) {
|
||||
blocks.forEach(block -> autoSellBlock(player, block));
|
||||
}
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
package me.nvus.xprison.autosell.model;
|
||||
|
||||
import me.nvus.xprison.autosell.XPrisonAutoSell;
|
||||
import me.nvus.xprison.utils.player.PlayerUtils;
|
||||
import me.lucko.helper.Schedulers;
|
||||
import me.lucko.helper.scheduler.Task;
|
||||
import me.lucko.helper.utils.Players;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public final class AutoSellBroadcastTask implements Runnable {
|
||||
|
||||
private final XPrisonAutoSell plugin;
|
||||
private Task task;
|
||||
|
||||
public AutoSellBroadcastTask(XPrisonAutoSell plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
for (Player p : Players.all()) {
|
||||
|
||||
double lastEarnings = this.plugin.getManager().getPlayerLastEarnings(p);
|
||||
|
||||
if (lastEarnings <= 0.0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
long lastItems = this.plugin.getManager().getPlayerLastItemsAmount(p);
|
||||
this.sendAutoSellBroadcastMessage(p, lastEarnings, lastItems);
|
||||
}
|
||||
|
||||
this.plugin.getManager().resetLastEarnings();
|
||||
this.plugin.getManager().resetLastItems();
|
||||
|
||||
}
|
||||
|
||||
private void sendAutoSellBroadcastMessage(Player p, double lastEarnings, long lastItems) {
|
||||
for (String s : this.plugin.getAutoSellConfig().getAutoSellBroadcastMessage()) {
|
||||
PlayerUtils.sendMessage(p, s.replace("%money%", String.format("%,.0f", lastEarnings)).replace("%items%", String.format("%,d", lastItems)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void start() {
|
||||
this.task = Schedulers.async().runRepeating(this, this.plugin.getAutoSellConfig().getAutoSellBroadcastTime(), TimeUnit.SECONDS, this.plugin.getAutoSellConfig().getAutoSellBroadcastTime(), TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
if (this.task != null) {
|
||||
this.task.stop();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
package me.nvus.xprison.autosell.model;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class AutoSellItemStack {
|
||||
|
||||
private final ItemStack itemStack;
|
||||
|
||||
public AutoSellItemStack(ItemStack stack) {
|
||||
this.itemStack = stack;
|
||||
}
|
||||
|
||||
public ItemStack getItemStack() {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
public static AutoSellItemStack of(ItemStack item) {
|
||||
return new AutoSellItemStack(item);
|
||||
}
|
||||
}
|
|
@ -1,102 +0,0 @@
|
|||
package me.nvus.xprison.autosell.model;
|
||||
|
||||
import me.nvus.xprison.utils.compat.CompMaterial;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.codemc.worldguardwrapper.region.IWrappedRegion;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@AllArgsConstructor
|
||||
@ToString
|
||||
public class SellRegion {
|
||||
|
||||
@Getter
|
||||
private final IWrappedRegion region;
|
||||
@Getter
|
||||
private final World world;
|
||||
|
||||
@Getter
|
||||
private final String permissionRequired;
|
||||
private final Map<CompMaterial, Double> sellPrices;
|
||||
|
||||
|
||||
public SellRegion(IWrappedRegion region, World world) {
|
||||
this.region = region;
|
||||
this.world = world;
|
||||
this.permissionRequired = null;
|
||||
this.sellPrices = new HashMap<>();
|
||||
}
|
||||
|
||||
public double getSellPriceForMaterial(CompMaterial material) {
|
||||
return sellPrices.getOrDefault(material, 0.0);
|
||||
}
|
||||
|
||||
public Set<CompMaterial> getSellingMaterials() {
|
||||
return this.sellPrices.keySet();
|
||||
}
|
||||
|
||||
public Set<CompMaterial> getSellingMaterialsSorted(Comparator<CompMaterial> comparator) {
|
||||
return this.sellPrices.keySet().stream().sorted(comparator).collect(Collectors.toCollection(LinkedHashSet::new));
|
||||
}
|
||||
|
||||
public void addSellPrice(CompMaterial material, double price) {
|
||||
this.sellPrices.put(material, price);
|
||||
}
|
||||
|
||||
public boolean contains(Location loc) {
|
||||
return Objects.equals(loc.getWorld(), this.world) && this.region.contains(loc);
|
||||
}
|
||||
|
||||
public boolean canPlayerSellInRegion(Player player) {
|
||||
if (this.permissionRequired == null || this.permissionRequired.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
return player.hasPermission(this.permissionRequired);
|
||||
}
|
||||
|
||||
public double getPriceForItem(ItemStack item) {
|
||||
CompMaterial material = CompMaterial.fromItem(item);
|
||||
return item.getAmount() * this.sellPrices.getOrDefault(material, 0.0);
|
||||
}
|
||||
|
||||
public Map<AutoSellItemStack, Double> previewInventorySell(Player player) {
|
||||
return previewItemsSell(Arrays.asList(player.getInventory().getContents()));
|
||||
}
|
||||
|
||||
public Map<AutoSellItemStack, Double> previewItemsSell(Collection<ItemStack> items) {
|
||||
|
||||
Map<AutoSellItemStack, Double> itemsToSell = new HashMap<>();
|
||||
|
||||
for (ItemStack item : items) {
|
||||
|
||||
if (item == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
double priceForItem = this.getPriceForItem(item);
|
||||
|
||||
if (priceForItem <= 0.0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
itemsToSell.put(new AutoSellItemStack(item), priceForItem);
|
||||
}
|
||||
|
||||
return itemsToSell;
|
||||
}
|
||||
|
||||
public boolean sellsMaterial(CompMaterial material) {
|
||||
return this.sellPrices.containsKey(material);
|
||||
}
|
||||
|
||||
public void removeSellPrice(CompMaterial material) {
|
||||
this.sellPrices.remove(material);
|
||||
}
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
package me.nvus.xprison.autosell.utils;
|
||||
|
||||
public class AutoSellContants {
|
||||
|
||||
public static final String AUTOSELL_PERMISSION = "xprison.autosell.toggle";
|
||||
public static final String ADMIN_PERMISSION = "xprison.autosell.admin";
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
package me.nvus.xprison.autosell.utils;
|
||||
|
||||
import me.nvus.xprison.autosell.model.SellRegion;
|
||||
import me.nvus.xprison.utils.compat.CompMaterial;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
public class SellPriceComparator implements Comparator<CompMaterial> {
|
||||
|
||||
private final SellRegion region;
|
||||
|
||||
public SellPriceComparator(SellRegion region) {
|
||||
this.region = region;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(CompMaterial o1, CompMaterial o2) {
|
||||
double sellPrice1 = region.getSellPriceForMaterial(o1);
|
||||
double sellPrice2 = region.getSellPriceForMaterial(o2);
|
||||
return Double.compare(sellPrice1, sellPrice2);
|
||||
}
|
||||
}
|
|
@ -1,169 +0,0 @@
|
|||
package me.nvus.xprison.config;
|
||||
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.HashMap;
|
||||
|
||||
|
||||
public class FileManager {
|
||||
|
||||
private final JavaPlugin plugin;
|
||||
private HashMap<String, Config> configs = new HashMap<String, Config>();
|
||||
|
||||
public FileManager(JavaPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the config by the name(Don't forget the .yml)
|
||||
*
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
public Config getConfig(String name) {
|
||||
if (!configs.containsKey(name))
|
||||
configs.put(name, new Config(name));
|
||||
|
||||
return configs.get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the config by the name(Don't forget the .yml)
|
||||
*
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
public Config saveConfig(String name) {
|
||||
return getConfig(name).save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reload the config by the name(Don't forget the .yml)
|
||||
*
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
public Config reloadConfig(String name) {
|
||||
return getConfig(name).reload();
|
||||
}
|
||||
|
||||
public class Config {
|
||||
|
||||
private String name;
|
||||
private File file;
|
||||
private YamlConfiguration config;
|
||||
|
||||
public Config(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the config as long as the config isn't empty
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Config save() {
|
||||
if ((this.config == null) || (this.file == null))
|
||||
return this;
|
||||
try {
|
||||
if (config.getConfigurationSection("").getKeys(true).size() != 0)
|
||||
config.save(this.file);
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the config as a YamlConfiguration
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public YamlConfiguration get() {
|
||||
if (this.config == null)
|
||||
reload();
|
||||
|
||||
return this.config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the default config(Will overwrite anything in the current config's file)
|
||||
* <p>
|
||||
* Don't forget to reload after!
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Config saveDefaultConfig() {
|
||||
file = new File(plugin.getDataFolder(), this.name);
|
||||
|
||||
plugin.saveResource(this.name, false);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads the config
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Config reload() {
|
||||
if (file == null)
|
||||
this.file = new File(plugin.getDataFolder(), this.name);
|
||||
|
||||
this.config = YamlConfiguration.loadConfiguration(file);
|
||||
|
||||
Reader defConfigStream;
|
||||
try {
|
||||
defConfigStream = new InputStreamReader(plugin.getResource(this.name), "UTF8");
|
||||
|
||||
if (defConfigStream != null) {
|
||||
YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
|
||||
this.config.setDefaults(defConfig);
|
||||
}
|
||||
} catch (UnsupportedEncodingException | NullPointerException e) {
|
||||
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies the config from the resources to the config's default settings.
|
||||
* <p>
|
||||
* Force = true ----> Will add any new values from the default file
|
||||
* <p>
|
||||
* Force = false ---> Will NOT add new values from the default file
|
||||
*
|
||||
* @param force
|
||||
* @return
|
||||
*/
|
||||
public Config copyDefaults(boolean force) {
|
||||
get().options().copyDefaults(force);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* An easy way to set a value into the config
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
public Config set(String key, Object value) {
|
||||
get().set(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* An easy way to get a value from the config
|
||||
*
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
public Object get(String key) {
|
||||
return get().get(key);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
package me.nvus.xprison.database;
|
||||
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import me.nvus.xprison.XPrison;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public abstract class PooledSQLDatabase extends SQLDatabase {
|
||||
|
||||
protected static final AtomicInteger POOL_COUNTER = new AtomicInteger(0);
|
||||
protected HikariDataSource hikari;
|
||||
|
||||
public PooledSQLDatabase(XPrison plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
if (this.hikari != null) {
|
||||
this.hikari.close();
|
||||
this.plugin.getLogger().info("Database Connection closed");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection getConnection() {
|
||||
try {
|
||||
return this.hikari.getConnection();
|
||||
} catch (SQLException e) {
|
||||
this.plugin.getLogger().warning("Unable to get database connection!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,87 +0,0 @@
|
|||
package me.nvus.xprison.database;
|
||||
|
||||
import me.nvus.xprison.XPrison;
|
||||
import me.nvus.xprison.database.model.SQLDatabaseType;
|
||||
import me.lucko.helper.Schedulers;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Arrays;
|
||||
|
||||
public abstract class SQLDatabase {
|
||||
|
||||
protected final XPrison plugin;
|
||||
|
||||
SQLDatabase(XPrison plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public abstract SQLDatabaseType getDatabaseType();
|
||||
|
||||
public abstract void connect();
|
||||
|
||||
public abstract void close();
|
||||
|
||||
public abstract Connection getConnection();
|
||||
|
||||
public PreparedStatement prepareStatement(Connection connection, String sql, Object... replacements) {
|
||||
|
||||
PreparedStatement statement;
|
||||
try {
|
||||
statement = connection.prepareStatement(sql);
|
||||
this.replaceQueryParameters(statement,replacements);
|
||||
|
||||
if (this.plugin.isDebugMode()) {
|
||||
this.plugin.getLogger().info("Statement prepared: " + sql + " (Replacement values: " + Arrays.toString(replacements) + ")");
|
||||
}
|
||||
|
||||
return statement;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void executeSql(String sql, Object... replacements) {
|
||||
|
||||
if (sql == null || sql.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
try (Connection c = getConnection(); PreparedStatement statement = prepareStatement(c,sql,replacements)) {
|
||||
|
||||
statement.execute();
|
||||
|
||||
long endTime = System.currentTimeMillis();
|
||||
|
||||
if (this.plugin.isDebugMode()) {
|
||||
this.plugin.getLogger().info("Statement executed: " + sql + " (Replacement values: " + Arrays.toString(replacements) + "). Took " + (endTime - startTime) + "ms.");
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void replaceQueryParameters(PreparedStatement statement, Object[] replacements) {
|
||||
if (replacements != null) {
|
||||
for (int i = 0; i < replacements.length; i++) {
|
||||
int position = i + 1;
|
||||
Object value = replacements[i];
|
||||
try {
|
||||
statement.setObject(position, value);
|
||||
} catch (SQLException e) {
|
||||
this.plugin.getLogger().warning("Unable to set query parameter at position " + position + " to " + value + " for query: " + statement);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void executeSqlAsync(String sql, Object... replacements) {
|
||||
Schedulers.async().run(() -> this.executeSql(sql, replacements));
|
||||
}
|
||||
}
|
|
@ -1,68 +0,0 @@
|
|||
package me.nvus.xprison.database.impl;
|
||||
|
||||
import com.zaxxer.hikari.HikariConfig;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import me.nvus.xprison.XPrison;
|
||||
import me.nvus.xprison.database.PooledSQLDatabase;
|
||||
import me.nvus.xprison.database.model.ConnectionProperties;
|
||||
import me.nvus.xprison.database.model.DatabaseCredentials;
|
||||
import me.nvus.xprison.database.model.SQLDatabaseType;
|
||||
|
||||
public final class MySQLDatabase extends PooledSQLDatabase {
|
||||
|
||||
private final DatabaseCredentials credentials;
|
||||
private final ConnectionProperties connectionProperties;
|
||||
|
||||
public MySQLDatabase(XPrison parent, DatabaseCredentials credentials, ConnectionProperties connectionProperties) {
|
||||
super(parent);
|
||||
this.connectionProperties = connectionProperties;
|
||||
this.credentials = credentials;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connect() {
|
||||
final HikariConfig hikari = new HikariConfig();
|
||||
|
||||
hikari.setPoolName("xprison-" + POOL_COUNTER.getAndIncrement());
|
||||
|
||||
this.applyCredentials(hikari, credentials, connectionProperties);
|
||||
this.applyConnectionProperties(hikari, connectionProperties);
|
||||
this.addDefaultDataSourceProperties(hikari);
|
||||
this.hikari = new HikariDataSource(hikari);
|
||||
}
|
||||
|
||||
private void applyCredentials(HikariConfig hikari, DatabaseCredentials credentials, ConnectionProperties connectionProperties) {
|
||||
hikari.setJdbcUrl("jdbc:mysql://" + credentials.getHost() + ":" + credentials.getPort() + "/" + credentials.getDatabaseName() + "?characterEncoding=" + connectionProperties.getCharacterEncoding());
|
||||
hikari.setUsername(credentials.getUserName());
|
||||
hikari.setPassword(credentials.getPassword());
|
||||
}
|
||||
|
||||
private void applyConnectionProperties(HikariConfig hikari, ConnectionProperties connectionProperties) {
|
||||
hikari.setConnectionTimeout(connectionProperties.getConnectionTimeout());
|
||||
hikari.setIdleTimeout(connectionProperties.getIdleTimeout());
|
||||
hikari.setKeepaliveTime(connectionProperties.getKeepAliveTime());
|
||||
hikari.setMaxLifetime(connectionProperties.getMaxLifetime());
|
||||
hikari.setMinimumIdle(connectionProperties.getMinimumIdle());
|
||||
hikari.setMaximumPoolSize(connectionProperties.getMaximumPoolSize());
|
||||
hikari.setLeakDetectionThreshold(connectionProperties.getLeakDetectionThreshold());
|
||||
hikari.setConnectionTestQuery(connectionProperties.getTestQuery());
|
||||
}
|
||||
|
||||
private void addDefaultDataSourceProperties(HikariConfig hikari) {
|
||||
hikari.addDataSourceProperty("cachePrepStmts", true);
|
||||
hikari.addDataSourceProperty("prepStmtCacheSize", 250);
|
||||
hikari.addDataSourceProperty("prepStmtCacheSqlLimit", 2048);
|
||||
hikari.addDataSourceProperty("useServerPrepStmts", true);
|
||||
hikari.addDataSourceProperty("useLocalSessionState", true);
|
||||
hikari.addDataSourceProperty("rewriteBatchedStatements", true);
|
||||
hikari.addDataSourceProperty("cacheResultSetMetadata", true);
|
||||
hikari.addDataSourceProperty("cacheServerConfiguration", true);
|
||||
hikari.addDataSourceProperty("elideSetAutoCommits", true);
|
||||
hikari.addDataSourceProperty("maintainTimeStats", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SQLDatabaseType getDatabaseType() {
|
||||
return SQLDatabaseType.MYSQL;
|
||||
}
|
||||
}
|
|
@ -1,65 +0,0 @@
|
|||
package me.nvus.xprison.database.impl;
|
||||
|
||||
import com.zaxxer.hikari.HikariConfig;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import me.nvus.xprison.XPrison;
|
||||
import me.nvus.xprison.database.PooledSQLDatabase;
|
||||
import me.nvus.xprison.database.model.ConnectionProperties;
|
||||
import me.nvus.xprison.database.model.SQLDatabaseType;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public final class SQLiteDatabase extends PooledSQLDatabase {
|
||||
|
||||
private static final String FILE_NAME = "playerdata.db";
|
||||
|
||||
private final String filePath;
|
||||
private final ConnectionProperties connectionProperties;
|
||||
|
||||
public SQLiteDatabase(XPrison plugin, ConnectionProperties connectionProperties) {
|
||||
super(plugin);
|
||||
this.connectionProperties = connectionProperties;
|
||||
this.filePath = this.plugin.getDataFolder().getPath() + File.separator + FILE_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SQLDatabaseType getDatabaseType() {
|
||||
return SQLDatabaseType.SQLITE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connect() {
|
||||
|
||||
this.createDBFile();
|
||||
|
||||
final HikariConfig hikari = new HikariConfig();
|
||||
|
||||
hikari.setPoolName("xprison-" + POOL_COUNTER.getAndIncrement());
|
||||
|
||||
hikari.setDriverClassName("org.sqlite.JDBC");
|
||||
hikari.setJdbcUrl("jdbc:sqlite:" + this.filePath);
|
||||
|
||||
hikari.setConnectionTimeout(connectionProperties.getConnectionTimeout());
|
||||
hikari.setIdleTimeout(connectionProperties.getIdleTimeout());
|
||||
hikari.setKeepaliveTime(connectionProperties.getKeepAliveTime());
|
||||
hikari.setMaxLifetime(connectionProperties.getMaxLifetime());
|
||||
hikari.setMinimumIdle(connectionProperties.getMinimumIdle());
|
||||
hikari.setMaximumPoolSize(1);
|
||||
hikari.setLeakDetectionThreshold(connectionProperties.getLeakDetectionThreshold());
|
||||
hikari.setConnectionTestQuery(connectionProperties.getTestQuery());
|
||||
|
||||
this.hikari = new HikariDataSource(hikari);
|
||||
}
|
||||
|
||||
private void createDBFile() {
|
||||
File dbFile = new File(this.filePath);
|
||||
try {
|
||||
dbFile.createNewFile();
|
||||
} catch (IOException e) {
|
||||
this.plugin.getLogger().warning(String.format("Unable to create %s", FILE_NAME));
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
package me.nvus.xprison.database.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class ConnectionProperties {
|
||||
|
||||
private final long idleTimeout, maxLifetime, connectionTimeout, leakDetectionThreshold, keepAliveTime;
|
||||
private final int minimumIdle, maximumPoolSize;
|
||||
private final String testQuery, characterEncoding;
|
||||
|
||||
public static ConnectionProperties fromConfig(FileConfiguration config) {
|
||||
|
||||
String rootPath = "connection_properties.";
|
||||
|
||||
long connectionTimeout = config.getLong(rootPath + "connection_timeout");
|
||||
long idleTimeout = config.getLong(rootPath + "idle_timeout");
|
||||
long keepAliveTime = config.getLong(rootPath + "keep_alive_time");
|
||||
long maxLifeTime = config.getLong(rootPath + "max_life_time");
|
||||
int minimumIdle = config.getInt(rootPath + "minimum_idle");
|
||||
int maximumPoolSize = config.getInt(rootPath + "maximum_pool_size");
|
||||
long leakDetectionThreshold = config.getLong(rootPath + "leak_detection_threshold");
|
||||
String characterEncoding = config.getString(rootPath + "character_encoding", "utf8");
|
||||
String testQuery = config.getString(rootPath + "connection_test_query");
|
||||
return new ConnectionProperties(idleTimeout, maxLifeTime, connectionTimeout, leakDetectionThreshold, keepAliveTime, minimumIdle, maximumPoolSize, testQuery,characterEncoding);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
package me.nvus.xprison.database.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class DatabaseCredentials {
|
||||
|
||||
private final String host, databaseName, userName, password;
|
||||
private final int port;
|
||||
|
||||
public static DatabaseCredentials fromConfig(FileConfiguration config) {
|
||||
|
||||
String rootPath = "mysql.";
|
||||
|
||||
String host = config.getString(rootPath + "host");
|
||||
String dbName = config.getString(rootPath + "database");
|
||||
String userName = config.getString(rootPath + "username");
|
||||
String password = config.getString(rootPath + "password");
|
||||
int port = config.getInt(rootPath + "port");
|
||||
|
||||
Validate.notNull(host);
|
||||
Validate.notNull(dbName);
|
||||
Validate.notNull(userName);
|
||||
Validate.notNull(password);
|
||||
|
||||
return new DatabaseCredentials(host, dbName, userName, password, port);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
package me.nvus.xprison.database.model;
|
||||
|
||||
public enum SQLDatabaseType {
|
||||
SQLITE,
|
||||
MYSQL
|
||||
}
|
|
@ -1,161 +0,0 @@
|
|||
package me.nvus.xprison.enchants;
|
||||
|
||||
import me.nvus.xprison.XPrison;
|
||||
import me.nvus.xprison.XPrisonModule;
|
||||
import me.nvus.xprison.autosell.XPrisonAutoSell;
|
||||
import me.nvus.xprison.enchants.api.XPrisonEnchantsAPI;
|
||||
import me.nvus.xprison.enchants.api.XPrisonEnchantsAPIImpl;
|
||||
import me.nvus.xprison.enchants.command.*;
|
||||
import me.nvus.xprison.enchants.config.EnchantsConfig;
|
||||
import me.nvus.xprison.enchants.gui.DisenchantGUI;
|
||||
import me.nvus.xprison.enchants.gui.EnchantGUI;
|
||||
import me.nvus.xprison.enchants.listener.EnchantsListener;
|
||||
import me.nvus.xprison.enchants.managers.CooldownManager;
|
||||
import me.nvus.xprison.enchants.managers.EnchantsManager;
|
||||
import me.nvus.xprison.enchants.managers.RespawnManager;
|
||||
import me.nvus.xprison.enchants.repo.EnchantsRepository;
|
||||
import me.nvus.xprison.mines.XPrisonMines;
|
||||
import me.nvus.xprison.multipliers.XPrisonMultipliers;
|
||||
import lombok.Getter;
|
||||
import me.lucko.helper.utils.Players;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public final class XPrisonEnchants implements XPrisonModule {
|
||||
|
||||
|
||||
public static final String MODULE_NAME = "Enchants";
|
||||
|
||||
@Getter
|
||||
private static XPrisonEnchants instance;
|
||||
|
||||
@Getter
|
||||
private XPrisonEnchantsAPI api;
|
||||
|
||||
@Getter
|
||||
private EnchantsManager enchantsManager;
|
||||
|
||||
@Getter
|
||||
private CooldownManager cooldownManager;
|
||||
|
||||
@Getter
|
||||
private RespawnManager respawnManager;
|
||||
|
||||
@Getter
|
||||
private EnchantsConfig enchantsConfig;
|
||||
|
||||
@Getter
|
||||
private EnchantsListener enchantsListener;
|
||||
|
||||
@Getter
|
||||
private EnchantsRepository enchantsRepository;
|
||||
|
||||
@Getter
|
||||
private final XPrison core;
|
||||
|
||||
private boolean enabled;
|
||||
|
||||
public XPrisonEnchants(XPrison core) {
|
||||
instance = this;
|
||||
this.core = core;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
|
||||
this.enchantsConfig.reload();
|
||||
this.enchantsRepository.reload();
|
||||
|
||||
EnchantGUI.init();
|
||||
DisenchantGUI.init();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
|
||||
this.enchantsConfig = new EnchantsConfig(this);
|
||||
this.enchantsConfig.load();
|
||||
|
||||
this.cooldownManager = new CooldownManager(this);
|
||||
this.respawnManager = new RespawnManager(this);
|
||||
|
||||
this.enchantsManager = new EnchantsManager(this);
|
||||
this.enchantsManager.enable();
|
||||
|
||||
this.enchantsListener = new EnchantsListener(this);
|
||||
this.enchantsListener.register();
|
||||
|
||||
this.registerCommands();
|
||||
|
||||
this.enchantsRepository = new EnchantsRepository(this);
|
||||
this.enchantsRepository.loadDefaultEnchantments();
|
||||
|
||||
EnchantGUI.init();
|
||||
DisenchantGUI.init();
|
||||
|
||||
this.api = new XPrisonEnchantsAPIImpl(this.enchantsManager, this.enchantsRepository);
|
||||
|
||||
|
||||
this.enabled = true;
|
||||
}
|
||||
|
||||
|
||||
private void registerCommands() {
|
||||
DisenchantCommand disenchantCommand = new DisenchantCommand(this);
|
||||
disenchantCommand.register();
|
||||
|
||||
EnchantMenuCommand enchantMenuCommand = new EnchantMenuCommand(this);
|
||||
enchantMenuCommand.register();
|
||||
|
||||
GiveFirstJoinPickaxeCommand giveFirstJoinPickaxeCommand = new GiveFirstJoinPickaxeCommand(this);
|
||||
giveFirstJoinPickaxeCommand.register();
|
||||
|
||||
GivePickaxeCommand givePickaxeCommand = new GivePickaxeCommand(this);
|
||||
givePickaxeCommand.register();
|
||||
|
||||
ValueCommand valueCommand = new ValueCommand(this);
|
||||
valueCommand.register();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
for (Player p : Players.all()) {
|
||||
p.closeInventory();
|
||||
}
|
||||
this.enchantsManager.disable();
|
||||
this.enabled = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return MODULE_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHistoryEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetPlayerData() {
|
||||
}
|
||||
|
||||
public boolean isAutoSellModuleEnabled() {
|
||||
return this.core.isModuleEnabled(XPrisonAutoSell.MODULE_NAME);
|
||||
}
|
||||
|
||||
public boolean isMultipliersModuleEnabled() {
|
||||
return this.core.isModuleEnabled(XPrisonMultipliers.MODULE_NAME);
|
||||
}
|
||||
|
||||
public boolean isMinesModuleEnabled() {
|
||||
return this.core.isModuleEnabled(XPrisonMines.MODULE_NAME);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,89 +0,0 @@
|
|||
package me.nvus.xprison.enchants.api;
|
||||
|
||||
import me.nvus.xprison.enchants.model.XPrisonEnchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface XPrisonEnchantsAPI {
|
||||
|
||||
|
||||
/**
|
||||
* Method to get all custom enchants applied on specific ItemStack
|
||||
*
|
||||
* @param itemStack ItemStack
|
||||
* @return
|
||||
*/
|
||||
Map<XPrisonEnchantment, Integer> getEnchants(ItemStack itemStack);
|
||||
|
||||
/**
|
||||
* Method to check if item has specific enchant
|
||||
*
|
||||
* @param item {@link ItemStack}
|
||||
* @param enchantment {@link XPrisonEnchantment}
|
||||
* @return true if item has enchant
|
||||
*/
|
||||
boolean hasEnchant(ItemStack item, XPrisonEnchantment enchantment);
|
||||
|
||||
/**
|
||||
* Method to get enchant level of specific ItemStack
|
||||
*
|
||||
* @param item ItemStack
|
||||
* @param enchantment {@link XPrisonEnchantment}
|
||||
* @return 0 if enchant was not found, otherwise level of enchant
|
||||
*/
|
||||
int getEnchantLevel(ItemStack item, XPrisonEnchantment enchantment);
|
||||
|
||||
/**
|
||||
* Method to set enchant with specific level to pickaxe
|
||||
*
|
||||
* @param item pickaxe
|
||||
* @param enchantment {@link XPrisonEnchantment}
|
||||
* @param level Enchant Level
|
||||
* @return modified ItemStack
|
||||
*/
|
||||
ItemStack setEnchantLevel(Player player, ItemStack item, XPrisonEnchantment enchantment, int level);
|
||||
|
||||
/**
|
||||
* Method to remove enchant from pickaxe
|
||||
*
|
||||
* @param item ItemStack pickaxe
|
||||
* @param enchantment {@link XPrisonEnchantment}
|
||||
* @return modified ItemStack
|
||||
*/
|
||||
ItemStack removeEnchant(Player player, ItemStack item, XPrisonEnchantment enchantment);
|
||||
|
||||
/**
|
||||
* Method to get Enchant by ID
|
||||
*
|
||||
* @param id enchant id
|
||||
* @return XPrisonEnchantment
|
||||
*/
|
||||
XPrisonEnchantment getById(int id);
|
||||
|
||||
/**
|
||||
* Method to get Enchant by ID
|
||||
*
|
||||
* @param rawName enchant rawname
|
||||
* @return XPrisonEnchantment
|
||||
*/
|
||||
XPrisonEnchantment getByName(String rawName);
|
||||
|
||||
/**
|
||||
* Registers a specific {@link XPrisonEnchantment}
|
||||
*
|
||||
* @param enchantment
|
||||
* @return
|
||||
*/
|
||||
boolean registerEnchant(XPrisonEnchantment enchantment);
|
||||
|
||||
/**
|
||||
* Unregisters a specific {@link XPrisonEnchantment}
|
||||
*
|
||||
* @param enchantment
|
||||
* @return
|
||||
*/
|
||||
boolean unregisterEnchant(XPrisonEnchantment enchantment);
|
||||
|
||||
}
|
|
@ -1,65 +0,0 @@
|
|||
package me.nvus.xprison.enchants.api;
|
||||
|
||||
import me.nvus.xprison.enchants.managers.EnchantsManager;
|
||||
import me.nvus.xprison.enchants.model.XPrisonEnchantment;
|
||||
import me.nvus.xprison.enchants.repo.EnchantsRepository;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public final class XPrisonEnchantsAPIImpl implements XPrisonEnchantsAPI {
|
||||
|
||||
private final EnchantsManager enchantsManager;
|
||||
private final EnchantsRepository enchantsRepository;
|
||||
|
||||
public XPrisonEnchantsAPIImpl(EnchantsManager enchantsManager, EnchantsRepository enchantsRepository) {
|
||||
this.enchantsManager = enchantsManager;
|
||||
this.enchantsRepository = enchantsRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<XPrisonEnchantment, Integer> getEnchants(ItemStack pickAxe) {
|
||||
return this.enchantsManager.getItemEnchants(pickAxe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasEnchant(ItemStack item, XPrisonEnchantment enchant) {
|
||||
return getEnchantLevel(item, enchant) != 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnchantLevel(ItemStack item, XPrisonEnchantment enchantment) {
|
||||
return this.enchantsManager.getEnchantLevel(item, enchantment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack setEnchantLevel(Player player, ItemStack item, XPrisonEnchantment enchantment, int level) {
|
||||
return this.enchantsManager.setEnchantLevel(player, item, enchantment, level);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeEnchant(Player player, ItemStack item, XPrisonEnchantment enchantment) {
|
||||
return this.enchantsManager.removeEnchant(player, item, enchantment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public XPrisonEnchantment getById(int id) {
|
||||
return this.enchantsRepository.getEnchantById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public XPrisonEnchantment getByName(String rawName) {
|
||||
return this.enchantsRepository.getEnchantByName(rawName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean registerEnchant(XPrisonEnchantment enchantment) {
|
||||
return this.enchantsRepository.register(enchantment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean unregisterEnchant(XPrisonEnchantment enchantment) {
|
||||
return this.enchantsRepository.unregister(enchantment);
|
||||
}
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
package me.nvus.xprison.enchants.api.events;
|
||||
|
||||
|
||||
import lombok.Getter;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.codemc.worldguardwrapper.region.IWrappedRegion;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
public final class ExplosionTriggerEvent extends XPrisonPlayerEnchantTriggerEvent {
|
||||
|
||||
private static final HandlerList HANDLERS_LIST = new HandlerList();
|
||||
private boolean cancelled;
|
||||
|
||||
/**
|
||||
* Called when explosive enchant procs
|
||||
*
|
||||
* @param p Player
|
||||
* @param mineRegion WorldGuard region where it was triggered
|
||||
* @param originBlock Original block broken that triggered it
|
||||
* @param blocksAffected List of affected blocks (marked for removal)
|
||||
*/
|
||||
public ExplosionTriggerEvent(Player p, IWrappedRegion mineRegion, Block originBlock, List<Block> blocksAffected) {
|
||||
super(p, mineRegion, originBlock, blocksAffected);
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLERS_LIST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return HANDLERS_LIST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancelled = cancel;
|
||||
}
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
package me.nvus.xprison.enchants.api.events;
|
||||
|
||||
|
||||
import lombok.Getter;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.codemc.worldguardwrapper.region.IWrappedRegion;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
public final class LayerTriggerEvent extends XPrisonPlayerEnchantTriggerEvent {
|
||||
|
||||
private static final HandlerList HANDLERS_LIST = new HandlerList();
|
||||
private boolean cancelled;
|
||||
|
||||
/**
|
||||
* Called when layer enchant procs
|
||||
*
|
||||
* @param p Player
|
||||
* @param mineRegion WorldGuard region where it was triggered
|
||||
* @param originBlock Original block broken that triggered it
|
||||
* @param blocks List of affected blocks (marked for removal)
|
||||
*/
|
||||
public LayerTriggerEvent(Player p, IWrappedRegion mineRegion, Block originBlock, List<Block> blocks) {
|
||||
super(p, mineRegion, originBlock, blocks);
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLERS_LIST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return HANDLERS_LIST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancelled = cancel;
|
||||
}
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
package me.nvus.xprison.enchants.api.events;
|
||||
|
||||
|
||||
import lombok.Getter;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.codemc.worldguardwrapper.region.IWrappedRegion;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
public final class NukeTriggerEvent extends XPrisonPlayerEnchantTriggerEvent {
|
||||
|
||||
private static final HandlerList HANDLERS_LIST = new HandlerList();
|
||||
private boolean cancelled;
|
||||
|
||||
/**
|
||||
* Called when nuke enchant procs
|
||||
*
|
||||
* @param p Player
|
||||
* @param mineRegion WorldGuard region where it was triggered
|
||||
* @param originBlock Original block broken that triggered it
|
||||
* @param blocks List of affected blocks (marked for removal)
|
||||
*/
|
||||
public NukeTriggerEvent(Player p, IWrappedRegion mineRegion, Block originBlock, List<Block> blocks) {
|
||||
super(p, mineRegion, originBlock, blocks);
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLERS_LIST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return HANDLERS_LIST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancelled = cancel;
|
||||
}
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
package me.nvus.xprison.enchants.api.events;
|
||||
|
||||
import me.nvus.xprison.api.events.player.XPrisonPlayerEvent;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
public final class XPrisonPlayerEnchantEvent extends XPrisonPlayerEvent implements Cancellable {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private long tokenCost;
|
||||
@Getter
|
||||
private final int level;
|
||||
@Getter
|
||||
@Setter
|
||||
private boolean cancelled;
|
||||
|
||||
|
||||
/**
|
||||
* Called when player enchants a tool
|
||||
*
|
||||
* @param player Player
|
||||
* @param tokenCost cost of enchant in tokens
|
||||
* @param level level of enchant
|
||||
*/
|
||||
public XPrisonPlayerEnchantEvent(Player player, long tokenCost, int level) {
|
||||
super(player);
|
||||
this.tokenCost = tokenCost;
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
package me.nvus.xprison.enchants.api.events;
|
||||
|
||||
import me.nvus.xprison.api.events.player.XPrisonPlayerEvent;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.codemc.worldguardwrapper.region.IWrappedRegion;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
public abstract class XPrisonPlayerEnchantTriggerEvent extends XPrisonPlayerEvent implements Cancellable {
|
||||
|
||||
protected final Player player;
|
||||
protected final IWrappedRegion mineRegion;
|
||||
protected final Block originBlock;
|
||||
protected final List<Block> blocksAffected;
|
||||
|
||||
public XPrisonPlayerEnchantTriggerEvent(Player p, IWrappedRegion mineRegion, Block originBlock, List<Block> blocksAffected) {
|
||||
super(p);
|
||||
this.player = p;
|
||||
this.mineRegion = mineRegion;
|
||||
this.originBlock = originBlock;
|
||||
this.blocksAffected = blocksAffected;
|
||||
}
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
package me.nvus.xprison.enchants.command;
|
||||
|
||||
import me.nvus.xprison.enchants.XPrisonEnchants;
|
||||
import me.nvus.xprison.enchants.gui.DisenchantGUI;
|
||||
import me.nvus.xprison.utils.inventory.InventoryUtils;
|
||||
import me.nvus.xprison.utils.player.PlayerUtils;
|
||||
import me.lucko.helper.Commands;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class DisenchantCommand {
|
||||
|
||||
private final XPrisonEnchants plugin;
|
||||
|
||||
public DisenchantCommand(XPrisonEnchants plugin) {
|
||||
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void register() {
|
||||
Commands.create()
|
||||
.assertPlayer()
|
||||
.handler(c -> {
|
||||
ItemStack pickAxe = c.sender().getItemInHand();
|
||||
|
||||
if (!validatePickaxe(pickAxe)) {
|
||||
PlayerUtils.sendMessage(c.sender(), this.plugin.getEnchantsConfig().getMessage("no_pickaxe_found"));
|
||||
return;
|
||||
}
|
||||
|
||||
openDisenchantGui(pickAxe, c.sender());
|
||||
|
||||
}).registerAndBind(this.plugin.getCore(), "disenchant", "dise", "de", "disenchantmenu", "dismenu");
|
||||
}
|
||||
|
||||
private void openDisenchantGui(ItemStack pickAxe, Player player) {
|
||||
int pickaxeSlot = InventoryUtils.getInventorySlot(player, pickAxe);
|
||||
this.plugin.getCore().debug("Pickaxe slot is: " + pickaxeSlot, this.plugin);
|
||||
new DisenchantGUI(this.plugin, player, pickAxe, pickaxeSlot).open();
|
||||
}
|
||||
|
||||
private boolean validatePickaxe(ItemStack pickAxe) {
|
||||
return pickAxe != null && this.plugin.getCore().isPickaxeSupported(pickAxe.getType());
|
||||
}
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
package me.nvus.xprison.enchants.command;
|
||||
|
||||
import me.nvus.xprison.enchants.XPrisonEnchants;
|
||||
import me.nvus.xprison.enchants.gui.EnchantGUI;
|
||||
import me.nvus.xprison.utils.inventory.InventoryUtils;
|
||||
import me.nvus.xprison.utils.player.PlayerUtils;
|
||||
import me.lucko.helper.Commands;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class EnchantMenuCommand {
|
||||
|
||||
private final XPrisonEnchants plugin;
|
||||
|
||||
public EnchantMenuCommand(XPrisonEnchants plugin) {
|
||||
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void register() {
|
||||
Commands.create()
|
||||
.assertPlayer()
|
||||
.handler(c -> {
|
||||
ItemStack pickAxe = c.sender().getItemInHand();
|
||||
|
||||
if (!validatePickaxe(pickAxe)) {
|
||||
PlayerUtils.sendMessage(c.sender(), this.plugin.getEnchantsConfig().getMessage("no_pickaxe_found"));
|
||||
return;
|
||||
}
|
||||
|
||||
openEnchantMenu(pickAxe, c.sender());
|
||||
}).registerAndBind(this.plugin.getCore(), "enchantmenu", "enchmenu");
|
||||
}
|
||||
|
||||
private void openEnchantMenu(ItemStack pickAxe, Player player) {
|
||||
int pickaxeSlot = InventoryUtils.getInventorySlot(player, pickAxe);
|
||||
this.plugin.getCore().debug("Pickaxe slot is: " + pickaxeSlot, this.plugin);
|
||||
new EnchantGUI(this.plugin, player, pickAxe, pickaxeSlot).open();
|
||||
}
|
||||
|
||||
private boolean validatePickaxe(ItemStack pickAxe) {
|
||||
return pickAxe != null && this.plugin.getCore().isPickaxeSupported(pickAxe.getType());
|
||||
}
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
package me.nvus.xprison.enchants.command;
|
||||
|
||||
import me.nvus.xprison.enchants.XPrisonEnchants;
|
||||
import me.nvus.xprison.utils.player.PlayerUtils;
|
||||
import me.lucko.helper.Commands;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class GiveFirstJoinPickaxeCommand {
|
||||
|
||||
private final XPrisonEnchants plugin;
|
||||
|
||||
public GiveFirstJoinPickaxeCommand(XPrisonEnchants plugin) {
|
||||
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void register() {
|
||||
Commands.create()
|
||||
.assertOp()
|
||||
.handler(c -> {
|
||||
|
||||
if (c.args().size() == 0) {
|
||||
PlayerUtils.sendMessage(c.sender(), "&c/givefirstjoinpickaxe <player>");
|
||||
return;
|
||||
}
|
||||
|
||||
Player target = c.arg(0).parseOrFail(Player.class);
|
||||
|
||||
this.plugin.getEnchantsManager().giveFirstJoinPickaxe(target);
|
||||
PlayerUtils.sendMessage(c.sender(), "&aYou have given first join pickaxe to &e" + target.getName());
|
||||
}).registerAndBind(this.plugin.getCore(), "givefirstjoinpickaxe");
|
||||
}
|
||||
}
|
|
@ -1,82 +0,0 @@
|
|||
package me.nvus.xprison.enchants.command;
|
||||
|
||||
import me.nvus.xprison.enchants.XPrisonEnchants;
|
||||
import me.nvus.xprison.enchants.model.XPrisonEnchantment;
|
||||
import me.nvus.xprison.enchants.repo.EnchantsRepository;
|
||||
import me.nvus.xprison.utils.player.PlayerUtils;
|
||||
import me.lucko.helper.Commands;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class GivePickaxeCommand {
|
||||
|
||||
private final XPrisonEnchants plugin;
|
||||
|
||||
public GivePickaxeCommand(XPrisonEnchants plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void register() {
|
||||
Commands.create()
|
||||
.assertOp()
|
||||
.handler(c -> {
|
||||
|
||||
if (c.args().size() == 0) {
|
||||
PlayerUtils.sendMessage(c.sender(), "&c/givepickaxe <player> <[enchant1]=[level1],[enchant2]=[level2],...[enchantX]=[levelX]> <pickaxe_name>");
|
||||
return;
|
||||
}
|
||||
|
||||
String input = null, name = null;
|
||||
Player target = null;
|
||||
|
||||
if (c.args().size() == 1) {
|
||||
input = c.rawArg(0);
|
||||
} else if (c.args().size() == 2) {
|
||||
target = c.arg(0).parseOrFail(Player.class);
|
||||
input = c.rawArg(1);
|
||||
} else if (c.args().size() >= 3) {
|
||||
target = c.arg(0).parseOrFail(Player.class);
|
||||
input = c.rawArg(1);
|
||||
name = StringUtils.join(c.args().subList(2, c.args().size()), " ");
|
||||
}
|
||||
|
||||
Map<XPrisonEnchantment, Integer> enchants = parseEnchantsFromInput(input);
|
||||
|
||||
this.plugin.getEnchantsManager().givePickaxe(target, enchants, name, c.sender());
|
||||
}).registerAndBind(this.plugin.getCore(), "givepickaxe");
|
||||
}
|
||||
|
||||
|
||||
private Map<XPrisonEnchantment, Integer> parseEnchantsFromInput(String input) {
|
||||
Map<XPrisonEnchantment, Integer> enchants = new HashMap<>();
|
||||
|
||||
String[] split = input.split(",");
|
||||
for (String s : split) {
|
||||
String[] enchantData = s.split("=");
|
||||
|
||||
try {
|
||||
XPrisonEnchantment enchantment = getEnchantsRepository().getEnchantByName(enchantData[0]);
|
||||
if (enchantment == null) {
|
||||
enchantment = getEnchantsRepository().getEnchantById(Integer.parseInt(enchantData[0]));
|
||||
}
|
||||
|
||||
if (enchantment == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int enchantLevel = Integer.parseInt(enchantData[1]);
|
||||
enchants.put(enchantment, enchantLevel);
|
||||
} catch (Exception ignored) {
|
||||
|
||||
}
|
||||
}
|
||||
return enchants;
|
||||
}
|
||||
|
||||
private EnchantsRepository getEnchantsRepository() {
|
||||
return this.plugin.getEnchantsRepository();
|
||||
}
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
package me.nvus.xprison.enchants.command;
|
||||
|
||||
import me.nvus.xprison.enchants.XPrisonEnchants;
|
||||
import me.nvus.xprison.enchants.managers.CooldownManager;
|
||||
import me.nvus.xprison.utils.player.PlayerUtils;
|
||||
import me.lucko.helper.Commands;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class ValueCommand {
|
||||
|
||||
private static final String COMMAND_NAME = "value";
|
||||
|
||||
private final XPrisonEnchants plugin;
|
||||
|
||||
public ValueCommand(XPrisonEnchants plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
|
||||
public void register() {
|
||||
Commands.create()
|
||||
.assertPlayer()
|
||||
.assertPermission("xprison.value", this.plugin.getEnchantsConfig().getMessage("value_no_permission"))
|
||||
.handler(c -> {
|
||||
|
||||
if (!checkCooldown(c.sender())) {
|
||||
PlayerUtils.sendMessage(c.sender(), this.plugin.getEnchantsConfig().getMessage("value_cooldown").replace("%time%", String.valueOf(this.getCooldownManager().getRemainingTime(c.sender()))));
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack pickAxe = c.sender().getItemInHand();
|
||||
|
||||
if (!validatePickaxe(pickAxe)) {
|
||||
PlayerUtils.sendMessage(c.sender(), this.plugin.getEnchantsConfig().getMessage("value_no_pickaxe"));
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerUtils.sendMessage(c.sender(), this.plugin.getEnchantsConfig().getMessage("value_value").replace("%player%", c.sender().getName()).replace("%tokens%", String.format("%,d", this.plugin.getEnchantsManager().getPickaxeValue(pickAxe))));
|
||||
}).registerAndBind(plugin.getCore(), COMMAND_NAME);
|
||||
}
|
||||
|
||||
private boolean validatePickaxe(ItemStack pickAxe) {
|
||||
return pickAxe != null && this.plugin.getCore().isPickaxeSupported(pickAxe.getType());
|
||||
}
|
||||
|
||||
private boolean checkCooldown(Player sender) {
|
||||
return (sender.isOp() || !getCooldownManager().hasValueCooldown(sender));
|
||||
}
|
||||
|
||||
private CooldownManager getCooldownManager() {
|
||||
return this.plugin.getCooldownManager();
|
||||
}
|
||||
}
|
|
@ -1,124 +0,0 @@
|
|||
package me.nvus.xprison.enchants.config;
|
||||
|
||||
import me.nvus.xprison.config.FileManager;
|
||||
import me.nvus.xprison.enchants.XPrisonEnchants;
|
||||
import me.nvus.xprison.enchants.model.LevelFormat;
|
||||
import me.nvus.xprison.utils.compat.CompMaterial;
|
||||
import me.nvus.xprison.utils.text.TextUtils;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.event.block.Action;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class EnchantsConfig {
|
||||
|
||||
private final XPrisonEnchants plugin;
|
||||
private final FileManager.Config config;
|
||||
|
||||
private Map<String, String> messages;
|
||||
|
||||
private LevelFormat levelFormat;
|
||||
private String excludedFormat;
|
||||
private List<String> pickaxeLore;
|
||||
private boolean allowEnchantsOutside;
|
||||
private boolean firstJoinPickaxeEnabled;
|
||||
private CompMaterial firstJoinPickaxeMaterial;
|
||||
private List<String> firstJoinPickaxeEnchants;
|
||||
private String firstJoinPickaxeName;
|
||||
private boolean keepPickaxesOnDeath;
|
||||
private boolean useUnbreakablePermission;
|
||||
private List<Action> openEnchantMenuActions;
|
||||
|
||||
public EnchantsConfig(XPrisonEnchants plugin) {
|
||||
this.plugin = plugin;
|
||||
this.config = plugin.getCore().getFileManager().getConfig("enchants.yml").copyDefaults(true).save();
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
this.getConfig().reload();
|
||||
this.load();
|
||||
}
|
||||
|
||||
public void load() {
|
||||
this.loadVariables();
|
||||
this.loadMessages();
|
||||
}
|
||||
|
||||
private void loadVariables() {
|
||||
this.levelFormat = LevelFormat.of(getYamlConfig().getString("Pickaxe.level-format", "NUMBER"));
|
||||
this.excludedFormat = getYamlConfig().getString("Pickaxe.excluded-format", "&7[&c-&7] &8%Enchant% %Level%");
|
||||
this.pickaxeLore = getYamlConfig().getStringList("Pickaxe.lore");
|
||||
this.openEnchantMenuActions = Arrays.stream(getYamlConfig().getString("open-enchant-menu-action", "RIGHT_CLICK_AIR,RIGHT_CLICK_BLOCK").split(",")).map(s-> Action.valueOf(s.toUpperCase())).collect(Collectors.toList());
|
||||
this.allowEnchantsOutside = getYamlConfig().getBoolean("allow-enchants-outside-mine-regions");
|
||||
this.firstJoinPickaxeEnabled = getYamlConfig().getBoolean("first-join-pickaxe.enabled");
|
||||
this.firstJoinPickaxeMaterial = CompMaterial.fromString(getYamlConfig().getString("first-join-pickaxe.material"));
|
||||
this.firstJoinPickaxeEnchants = getYamlConfig().getStringList("first-join-pickaxe.enchants");
|
||||
this.firstJoinPickaxeName = getYamlConfig().getString("first-join-pickaxe.name");
|
||||
this.keepPickaxesOnDeath = getYamlConfig().getBoolean("keep-pickaxes-on-death");
|
||||
this.useUnbreakablePermission = getYamlConfig().getBoolean("use-unbreakable-permission");
|
||||
}
|
||||
|
||||
private void loadMessages() {
|
||||
this.messages = new HashMap<>();
|
||||
for (String key : getYamlConfig().getConfigurationSection("messages").getKeys(false)) {
|
||||
messages.put(key, TextUtils.applyColor(getConfig().get().getString("messages." + key)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private FileManager.Config getConfig() {
|
||||
return this.config;
|
||||
}
|
||||
|
||||
public YamlConfiguration getYamlConfig() {
|
||||
return this.config.get();
|
||||
}
|
||||
|
||||
public String getMessage(String key) {
|
||||
return messages.getOrDefault(key.toLowerCase(), "Message not found with key: " + key);
|
||||
}
|
||||
|
||||
public LevelFormat getLevelFormat() {
|
||||
return levelFormat;
|
||||
}
|
||||
|
||||
public String getExcludedFormat() {
|
||||
return excludedFormat;
|
||||
}
|
||||
|
||||
public List<String> getPickaxeLore() {
|
||||
return pickaxeLore;
|
||||
}
|
||||
|
||||
public boolean isFirstJoinPickaxeEnabled() {
|
||||
return firstJoinPickaxeEnabled;
|
||||
}
|
||||
|
||||
public CompMaterial getFirstJoinPickaxeMaterial() {
|
||||
return firstJoinPickaxeMaterial;
|
||||
}
|
||||
|
||||
public List<String> getFirstJoinPickaxeEnchants() {
|
||||
return firstJoinPickaxeEnchants;
|
||||
}
|
||||
|
||||
public String getFirstJoinPickaxeName() {
|
||||
return firstJoinPickaxeName;
|
||||
}
|
||||
|
||||
public boolean isKeepPickaxesOnDeath() {
|
||||
return keepPickaxesOnDeath;
|
||||
}
|
||||
|
||||
public boolean isUseUnbreakablePermission() {
|
||||
return useUnbreakablePermission;
|
||||
}
|
||||
|
||||
public List<Action> getOpenEnchantMenuActions() {
|
||||
return openEnchantMenuActions;
|
||||
}
|
||||
}
|
|
@ -1,159 +0,0 @@
|
|||
package me.nvus.xprison.enchants.gui;
|
||||
|
||||
import me.nvus.xprison.XPrison;
|
||||
import me.nvus.xprison.enchants.XPrisonEnchants;
|
||||
import me.nvus.xprison.enchants.model.XPrisonEnchantment;
|
||||
import me.nvus.xprison.enchants.utils.GuiUtils;
|
||||
import me.nvus.xprison.utils.compat.CompMaterial;
|
||||
import me.nvus.xprison.utils.item.ItemStackBuilder;
|
||||
import me.nvus.xprison.utils.misc.SkullUtils;
|
||||
import me.nvus.xprison.utils.text.TextUtils;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import me.lucko.helper.Events;
|
||||
import me.lucko.helper.Schedulers;
|
||||
import me.lucko.helper.menu.Gui;
|
||||
import me.lucko.helper.menu.Item;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public final class DisenchantGUI extends Gui {
|
||||
|
||||
private static List<String> GUI_ITEM_LORE;
|
||||
private static String GUI_TITLE;
|
||||
private static Item EMPTY_SLOT_ITEM;
|
||||
private static Item HELP_ITEM;
|
||||
private static int HELP_ITEM_SLOT;
|
||||
private static int PICKAXE_ITEM_SLOT;
|
||||
private static int GUI_LINES;
|
||||
private static boolean PICKAXE_ITEM_ENABLED;
|
||||
private static boolean HELP_ITEM_ENABLED;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private ItemStack pickAxe;
|
||||
|
||||
@Getter
|
||||
private final int pickaxePlayerInventorySlot;
|
||||
|
||||
private final XPrisonEnchants plugin;
|
||||
|
||||
public DisenchantGUI(XPrisonEnchants plugin, Player player, ItemStack pickAxe, int pickaxePlayerInventorySlot) {
|
||||
super(player, GUI_LINES, GUI_TITLE);
|
||||
this.plugin = plugin;
|
||||
this.pickAxe = pickAxe;
|
||||
this.pickaxePlayerInventorySlot = pickaxePlayerInventorySlot;
|
||||
|
||||
Events.subscribe(InventoryCloseEvent.class, EventPriority.LOWEST)
|
||||
.filter(e -> e.getInventory().equals(this.getHandle()))
|
||||
.handler(e -> {
|
||||
XPrison.getInstance().getEnchants().getEnchantsManager().handlePickaxeUnequip(this.getPlayer(), this.pickAxe);
|
||||
XPrison.getInstance().getEnchants().getEnchantsManager().handlePickaxeEquip(this.getPlayer(), this.pickAxe);
|
||||
}).bindWith(this);
|
||||
|
||||
Schedulers.sync().runLater(() -> {
|
||||
if (!pickAxe.equals(this.getPlayer().getInventory().getItem(this.pickaxePlayerInventorySlot))) {
|
||||
this.close();
|
||||
}
|
||||
}, 10);
|
||||
setFallbackGui(player1 -> new EnchantGUI(plugin, player, pickAxe, pickaxePlayerInventorySlot));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void redraw() {
|
||||
|
||||
if (isFirstDraw()) {
|
||||
for (int i = 0; i < this.getHandle().getSize(); i++) {
|
||||
this.setItem(i, EMPTY_SLOT_ITEM);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (HELP_ITEM_ENABLED) {
|
||||
this.setItem(HELP_ITEM_SLOT, HELP_ITEM);
|
||||
}
|
||||
|
||||
if (PICKAXE_ITEM_ENABLED) {
|
||||
this.setItem(PICKAXE_ITEM_SLOT, Item.builder(pickAxe).build());
|
||||
}
|
||||
|
||||
Collection<XPrisonEnchantment> allEnchants = this.plugin.getEnchantsRepository().getAll();
|
||||
|
||||
for (XPrisonEnchantment enchantment : allEnchants) {
|
||||
|
||||
if (!enchantment.isRefundEnabled() || !enchantment.isEnabled()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int level = XPrisonEnchants.getInstance().getEnchantsManager().getEnchantLevel(this.pickAxe, enchantment);
|
||||
this.setItem(enchantment.getRefundGuiSlot(), getRefundGuiItem(enchantment, this, level));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private Item getRefundGuiItem(XPrisonEnchantment enchantment, DisenchantGUI gui, int level) {
|
||||
Material m = enchantment.isRefundEnabled() ? enchantment.getMaterial() : CompMaterial.BARRIER.toMaterial();
|
||||
ItemStackBuilder builder = ItemStackBuilder.of(m);
|
||||
|
||||
if (enchantment.getBase64() != null && !enchantment.getBase64().isEmpty()) {
|
||||
builder = ItemStackBuilder.of(SkullUtils.getCustomTextureHead(enchantment.getBase64()));
|
||||
}
|
||||
|
||||
builder.name(enchantment.isRefundEnabled() ? enchantment.getGuiName() : this.plugin.getEnchantsConfig().getMessage("enchant_cant_disenchant"));
|
||||
builder.lore(enchantment.isRefundEnabled() ? GuiUtils.translateGuiLore(enchantment, GUI_ITEM_LORE, level) : new ArrayList<>());
|
||||
|
||||
return enchantment.isRefundEnabled() ? builder.buildItem().bind(handler -> {
|
||||
if (handler.getClick() == ClickType.MIDDLE || handler.getClick() == ClickType.SHIFT_RIGHT) {
|
||||
this.plugin.getEnchantsManager().disenchant(enchantment, gui, level, 100);
|
||||
gui.redraw();
|
||||
} else if (handler.getClick() == ClickType.LEFT) {
|
||||
this.plugin.getEnchantsManager().disenchant(enchantment, gui, level, 1);
|
||||
gui.redraw();
|
||||
} else if (handler.getClick() == ClickType.RIGHT) {
|
||||
this.plugin.getEnchantsManager().disenchant(enchantment, gui, level, 10);
|
||||
gui.redraw();
|
||||
} else if (handler.getClick() == ClickType.DROP) {
|
||||
this.plugin.getEnchantsManager().disenchantMax(enchantment, gui, level);
|
||||
}
|
||||
}, ClickType.MIDDLE, ClickType.SHIFT_RIGHT, ClickType.LEFT, ClickType.RIGHT, ClickType.DROP).build() : builder.buildConsumer(handler -> handler.getWhoClicked().sendMessage(this.plugin.getEnchantsConfig().getMessage("enchant_cant_disenchant")));
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
|
||||
GUI_ITEM_LORE = XPrisonEnchants.getInstance().getEnchantsConfig().getYamlConfig().getStringList("disenchant_menu.item.lore");
|
||||
GUI_TITLE = TextUtils.applyColor(XPrisonEnchants.getInstance().getEnchantsConfig().getYamlConfig().getString("disenchant_menu.title"));
|
||||
GUI_LINES = XPrisonEnchants.getInstance().getEnchantsConfig().getYamlConfig().getInt("disenchant_menu.lines");
|
||||
|
||||
EMPTY_SLOT_ITEM = ItemStackBuilder.
|
||||
of(CompMaterial.fromString(XPrisonEnchants.getInstance().getEnchantsConfig().getYamlConfig().getString("disenchant_menu.empty_slots")).toItem()).buildItem().build();
|
||||
|
||||
HELP_ITEM_ENABLED = XPrisonEnchants.getInstance().getEnchantsConfig().getYamlConfig().getBoolean("disenchant_menu.help_item.enabled", true);
|
||||
PICKAXE_ITEM_ENABLED = XPrisonEnchants.getInstance().getEnchantsConfig().getYamlConfig().getBoolean("disenchant_menu.pickaxe_enabled", true);
|
||||
|
||||
if (HELP_ITEM_ENABLED) {
|
||||
String base64 = XPrisonEnchants.getInstance().getEnchantsConfig().getYamlConfig().getString("disenchant_menu.help_item.Base64", null);
|
||||
|
||||
if (base64 != null) {
|
||||
HELP_ITEM = ItemStackBuilder.of(SkullUtils.getCustomTextureHead(base64))
|
||||
.name(XPrisonEnchants.getInstance().getEnchantsConfig().getYamlConfig().getString("disenchant_menu.help_item.name")).lore(XPrisonEnchants.getInstance().getEnchantsConfig().getYamlConfig().getStringList("disenchant_menu.help_item.lore")).buildItem().build();
|
||||
} else {
|
||||
HELP_ITEM = ItemStackBuilder.of(CompMaterial.fromString(XPrisonEnchants.getInstance().getEnchantsConfig().getYamlConfig().getString("disenchant_menu.help_item.material")).toMaterial())
|
||||
.name(XPrisonEnchants.getInstance().getEnchantsConfig().getYamlConfig().getString("disenchant_menu.help_item.name")).lore(XPrisonEnchants.getInstance().getEnchantsConfig().getYamlConfig().getStringList("disenchant_menu.help_item.lore")).buildItem().build();
|
||||
}
|
||||
HELP_ITEM_SLOT = XPrisonEnchants.getInstance().getEnchantsConfig().getYamlConfig().getInt("disenchant_menu.help_item.slot");
|
||||
}
|
||||
|
||||
if (PICKAXE_ITEM_ENABLED) {
|
||||
PICKAXE_ITEM_SLOT = XPrisonEnchants.getInstance().getEnchantsConfig().getYamlConfig().getInt("disenchant_menu.pickaxe_slot");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,183 +0,0 @@
|
|||
package me.nvus.xprison.enchants.gui;
|
||||
|
||||
import me.nvus.xprison.XPrison;
|
||||
import me.nvus.xprison.enchants.XPrisonEnchants;
|
||||
import me.nvus.xprison.enchants.model.XPrisonEnchantment;
|
||||
import me.nvus.xprison.enchants.utils.GuiUtils;
|
||||
import me.nvus.xprison.utils.compat.CompMaterial;
|
||||
import me.nvus.xprison.utils.item.ItemStackBuilder;
|
||||
import me.nvus.xprison.utils.misc.SkullUtils;
|
||||
import me.nvus.xprison.utils.player.PlayerUtils;
|
||||
import me.nvus.xprison.utils.text.TextUtils;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import me.lucko.helper.Events;
|
||||
import me.lucko.helper.Schedulers;
|
||||
import me.lucko.helper.menu.Gui;
|
||||
import me.lucko.helper.menu.Item;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public final class EnchantGUI extends Gui {
|
||||
|
||||
private static List<String> GUI_ITEM_LORE;
|
||||
private static String GUI_TITLE;
|
||||
private static Item EMPTY_SLOT_ITEM;
|
||||
private static int PICKAXE_ITEM_SLOT;
|
||||
private static int HELP_ITEM_SLOT;
|
||||
private static int DISENCHANT_ITEM_SLOT;
|
||||
private static int GUI_LINES;
|
||||
private static Item HELP_ITEM;
|
||||
private static ItemStack DISENCHANT_ITEM;
|
||||
private static boolean PICKAXE_ITEM_ENABLED;
|
||||
private static boolean HELP_ITEM_ENABLED;
|
||||
private static boolean DISENCHANT_ITEM_ENABLED;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private ItemStack pickAxe;
|
||||
|
||||
@Getter
|
||||
private final int pickaxePlayerInventorySlot;
|
||||
|
||||
private final XPrisonEnchants plugin;
|
||||
|
||||
public EnchantGUI(XPrisonEnchants plugin, Player player, ItemStack pickAxe, int pickaxePlayerInventorySlot) {
|
||||
super(player, GUI_LINES, GUI_TITLE);
|
||||
this.plugin = plugin;
|
||||
this.pickAxe = pickAxe;
|
||||
this.pickaxePlayerInventorySlot = pickaxePlayerInventorySlot;
|
||||
|
||||
Events.subscribe(InventoryCloseEvent.class, EventPriority.LOWEST)
|
||||
.filter(e -> e.getInventory().equals(this.getHandle()))
|
||||
.handler(e -> {
|
||||
XPrison.getInstance().getEnchants().getEnchantsManager().handlePickaxeUnequip(this.getPlayer(), this.pickAxe);
|
||||
XPrison.getInstance().getEnchants().getEnchantsManager().handlePickaxeEquip(this.getPlayer(), this.pickAxe);
|
||||
}).bindWith(this);
|
||||
|
||||
// Checking for duping
|
||||
Schedulers.sync().runLater(() -> {
|
||||
if (!pickAxe.equals(this.getPlayer().getInventory().getItem(this.pickaxePlayerInventorySlot))) {
|
||||
this.close();
|
||||
}
|
||||
},10);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void redraw() {
|
||||
|
||||
// perform initial setup.
|
||||
if (isFirstDraw()) {
|
||||
for (int i = 0; i < this.getHandle().getSize(); i++) {
|
||||
this.setItem(i, EMPTY_SLOT_ITEM);
|
||||
}
|
||||
}
|
||||
|
||||
if (HELP_ITEM_ENABLED) {
|
||||
this.setItem(HELP_ITEM_SLOT, HELP_ITEM);
|
||||
}
|
||||
|
||||
if (DISENCHANT_ITEM_ENABLED) {
|
||||
this.setItem(DISENCHANT_ITEM_SLOT, ItemStackBuilder.of(DISENCHANT_ITEM).build(() -> {
|
||||
this.close();
|
||||
new DisenchantGUI(this.plugin, this.getPlayer(), this.pickAxe, this.pickaxePlayerInventorySlot).open();
|
||||
}));
|
||||
}
|
||||
|
||||
if (PICKAXE_ITEM_ENABLED) {
|
||||
this.setItem(PICKAXE_ITEM_SLOT, Item.builder(this.pickAxe).build());
|
||||
}
|
||||
|
||||
Collection<XPrisonEnchantment> allEnchants = this.plugin.getEnchantsRepository().getAll();
|
||||
for (XPrisonEnchantment enchantment : allEnchants) {
|
||||
if (!enchantment.isEnabled()) {
|
||||
continue;
|
||||
}
|
||||
int level = XPrisonEnchants.getInstance().getEnchantsManager().getEnchantLevel(this.pickAxe, enchantment);
|
||||
this.setItem(enchantment.getGuiSlot(), getGuiItem(enchantment, this, level));
|
||||
}
|
||||
}
|
||||
|
||||
private Item getGuiItem(XPrisonEnchantment enchantment, EnchantGUI gui, int currentLevel) {
|
||||
|
||||
ItemStackBuilder builder = ItemStackBuilder.of(enchantment.getMaterial());
|
||||
|
||||
if (enchantment.getBase64() != null && !enchantment.getBase64().isEmpty()) {
|
||||
builder = ItemStackBuilder.of(SkullUtils.getCustomTextureHead(enchantment.getBase64()));
|
||||
}
|
||||
|
||||
builder.name(enchantment.getGuiName());
|
||||
builder.lore(GuiUtils.translateGuiLore(enchantment, GUI_ITEM_LORE, currentLevel));
|
||||
|
||||
return builder.buildItem().bind(handler -> {
|
||||
if (!enchantment.canBeBought(gui.getPickAxe())) {
|
||||
PlayerUtils.sendMessage(this.getPlayer(), this.plugin.getEnchantsConfig().getMessage("pickaxe_level_required").replace("%pickaxe_level%", String.format("%,d", enchantment.getRequiredPickaxeLevel())));
|
||||
return;
|
||||
}
|
||||
if (handler.getClick() == ClickType.MIDDLE || handler.getClick() == ClickType.SHIFT_RIGHT) {
|
||||
this.plugin.getEnchantsManager().buyEnchnant(enchantment, gui, currentLevel, 100);
|
||||
gui.redraw();
|
||||
} else if (handler.getClick() == ClickType.LEFT) {
|
||||
this.plugin.getEnchantsManager().buyEnchnant(enchantment, gui, currentLevel, 1);
|
||||
gui.redraw();
|
||||
} else if (handler.getClick() == ClickType.RIGHT) {
|
||||
this.plugin.getEnchantsManager().buyEnchnant(enchantment, gui, currentLevel, 10);
|
||||
gui.redraw();
|
||||
} else if (handler.getClick() == ClickType.DROP) {
|
||||
this.plugin.getEnchantsManager().buyMaxEnchant(enchantment, gui, currentLevel);
|
||||
}
|
||||
}, ClickType.MIDDLE, ClickType.SHIFT_RIGHT, ClickType.RIGHT, ClickType.LEFT, ClickType.DROP).build();
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
|
||||
GUI_ITEM_LORE = XPrisonEnchants.getInstance().getEnchantsConfig().getYamlConfig().getStringList("enchant_menu.item.lore");
|
||||
GUI_TITLE = TextUtils.applyColor(XPrisonEnchants.getInstance().getEnchantsConfig().getYamlConfig().getString("enchant_menu.title"));
|
||||
EMPTY_SLOT_ITEM = ItemStackBuilder.
|
||||
of(CompMaterial.fromString(XPrisonEnchants.getInstance().getEnchantsConfig().getYamlConfig().getString("enchant_menu.empty_slots")).toItem()).buildItem().build();
|
||||
GUI_LINES = XPrisonEnchants.getInstance().getEnchantsConfig().getYamlConfig().getInt("enchant_menu.lines");
|
||||
|
||||
HELP_ITEM_ENABLED = XPrisonEnchants.getInstance().getEnchantsConfig().getYamlConfig().getBoolean("enchant_menu.help_item.enabled", true);
|
||||
PICKAXE_ITEM_ENABLED = XPrisonEnchants.getInstance().getEnchantsConfig().getYamlConfig().getBoolean("enchant_menu.pickaxe_enabled", true);
|
||||
DISENCHANT_ITEM_ENABLED = XPrisonEnchants.getInstance().getEnchantsConfig().getYamlConfig().getBoolean("enchant_menu.disenchant_item.enabled", true);
|
||||
|
||||
if (DISENCHANT_ITEM_ENABLED) {
|
||||
String base64 = XPrisonEnchants.getInstance().getEnchantsConfig().getYamlConfig().getString("enchant_menu.disenchant_item.Base64", null);
|
||||
|
||||
if (base64 != null) {
|
||||
DISENCHANT_ITEM = ItemStackBuilder.of(SkullUtils.getCustomTextureHead(base64))
|
||||
.name(XPrisonEnchants.getInstance().getEnchantsConfig().getYamlConfig().getString("enchant_menu.disenchant_item.name")).lore(XPrisonEnchants.getInstance().getEnchantsConfig().getYamlConfig().getStringList("enchant_menu.disenchant_item.lore")).build();
|
||||
} else {
|
||||
DISENCHANT_ITEM = ItemStackBuilder.of(CompMaterial.fromString(XPrisonEnchants.getInstance().getEnchantsConfig().getYamlConfig().getString("enchant_menu.disenchant_item.material")).toMaterial())
|
||||
.name(XPrisonEnchants.getInstance().getEnchantsConfig().getYamlConfig().getString("enchant_menu.disenchant_item.name")).lore(XPrisonEnchants.getInstance().getEnchantsConfig().getYamlConfig().getStringList("enchant_menu.disenchant_item.lore")).build();
|
||||
}
|
||||
DISENCHANT_ITEM_SLOT = XPrisonEnchants.getInstance().getEnchantsConfig().getYamlConfig().getInt("enchant_menu.disenchant_item.slot");
|
||||
|
||||
}
|
||||
|
||||
if (HELP_ITEM_ENABLED) {
|
||||
String base64 = XPrisonEnchants.getInstance().getEnchantsConfig().getYamlConfig().getString("enchant_menu.help_item.Base64", null);
|
||||
|
||||
if (base64 != null) {
|
||||
HELP_ITEM = ItemStackBuilder.of(SkullUtils.getCustomTextureHead(base64))
|
||||
.name(XPrisonEnchants.getInstance().getEnchantsConfig().getYamlConfig().getString("enchant_menu.help_item.name")).lore(XPrisonEnchants.getInstance().getEnchantsConfig().getYamlConfig().getStringList("enchant_menu.help_item.lore")).buildItem().build();
|
||||
} else {
|
||||
HELP_ITEM = ItemStackBuilder.of(CompMaterial.fromString(XPrisonEnchants.getInstance().getEnchantsConfig().getYamlConfig().getString("enchant_menu.help_item.material")).toMaterial())
|
||||
.name(XPrisonEnchants.getInstance().getEnchantsConfig().getYamlConfig().getString("enchant_menu.help_item.name")).lore(XPrisonEnchants.getInstance().getEnchantsConfig().getYamlConfig().getStringList("enchant_menu.help_item.lore")).buildItem().build();
|
||||
}
|
||||
|
||||
HELP_ITEM_SLOT = XPrisonEnchants.getInstance().getEnchantsConfig().getYamlConfig().getInt("enchant_menu.help_item.slot");
|
||||
|
||||
}
|
||||
|
||||
if (PICKAXE_ITEM_ENABLED) {
|
||||
PICKAXE_ITEM_SLOT = XPrisonEnchants.getInstance().getEnchantsConfig().getYamlConfig().getInt("enchant_menu.pickaxe_slot");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,172 +0,0 @@
|
|||
package me.nvus.xprison.enchants.listener;
|
||||
|
||||
import me.nvus.xprison.enchants.XPrisonEnchants;
|
||||
import me.nvus.xprison.enchants.gui.EnchantGUI;
|
||||
import me.nvus.xprison.utils.Constants;
|
||||
import me.nvus.xprison.utils.compat.MinecraftVersion;
|
||||
import me.nvus.xprison.utils.inventory.InventoryUtils;
|
||||
import me.lucko.helper.Events;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.inventory.InventoryAction;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.player.*;
|
||||
import org.bukkit.inventory.GrindstoneInventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.codemc.worldguardwrapper.flag.IWrappedFlag;
|
||||
import org.codemc.worldguardwrapper.flag.WrappedState;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class EnchantsListener {
|
||||
|
||||
private final XPrisonEnchants plugin;
|
||||
private final List<BlockBreakEvent> ignoredEvents = new ArrayList<>();
|
||||
|
||||
public EnchantsListener(XPrisonEnchants plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void register() {
|
||||
|
||||
this.subscribeToPlayerDeathEvent();
|
||||
this.subscribeToPlayerRespawnEvent();
|
||||
this.subscribeToInventoryClickEvent();
|
||||
this.subscribeToPlayerJoinEvent();
|
||||
this.subscribeToPlayerDropItemEvent();
|
||||
this.subscribeToPlayerInteractEvent();
|
||||
this.subscribeToPlayerItemHeldEvent();
|
||||
this.subscribeToBlockBreakEvent();
|
||||
}
|
||||
|
||||
public List<BlockBreakEvent> getIgnoredEvents() {
|
||||
return ignoredEvents;
|
||||
}
|
||||
|
||||
private void subscribeToBlockBreakEvent() {
|
||||
Events.subscribe(BlockBreakEvent.class, EventPriority.HIGHEST)
|
||||
.filter(e -> !e.isCancelled() && !ignoredEvents.contains(e))
|
||||
.filter(e -> e.getPlayer().getItemInHand() != null && this.plugin.getCore().isPickaxeSupported(e.getPlayer().getItemInHand().getType()))
|
||||
.handler(e -> this.plugin.getEnchantsManager().handleBlockBreak(e, e.getPlayer().getItemInHand())).bindWith(this.plugin.getCore());
|
||||
}
|
||||
|
||||
private void subscribeToPlayerItemHeldEvent() {
|
||||
// Switching pickaxes
|
||||
Events.subscribe(PlayerItemHeldEvent.class, EventPriority.HIGHEST)
|
||||
.handler(e -> {
|
||||
|
||||
ItemStack newItem = e.getPlayer().getInventory().getItem(e.getNewSlot());
|
||||
ItemStack previousItem = e.getPlayer().getInventory().getItem(e.getPreviousSlot());
|
||||
|
||||
// Old item
|
||||
if (previousItem != null && this.plugin.getCore().isPickaxeSupported(previousItem.getType())) {
|
||||
this.plugin.getEnchantsManager().handlePickaxeUnequip(e.getPlayer(), previousItem);
|
||||
}
|
||||
|
||||
// New item
|
||||
if (newItem != null && this.plugin.getCore().isPickaxeSupported(newItem.getType())) {
|
||||
this.plugin.getEnchantsManager().handlePickaxeEquip(e.getPlayer(), newItem);
|
||||
}
|
||||
|
||||
}).bindWith(this.plugin.getCore());
|
||||
}
|
||||
|
||||
private void subscribeToPlayerInteractEvent() {
|
||||
Events.subscribe(PlayerInteractEvent.class)
|
||||
.filter(e -> e.getItem() != null && this.plugin.getCore().isPickaxeSupported(e.getItem().getType()))
|
||||
.filter(e -> (this.plugin.getEnchantsConfig().getOpenEnchantMenuActions().contains(e.getAction())))
|
||||
.handler(e -> {
|
||||
|
||||
e.setCancelled(true);
|
||||
|
||||
ItemStack pickAxe = e.getItem();
|
||||
int pickaxeSlot = InventoryUtils.getInventorySlot(e.getPlayer(), pickAxe);
|
||||
this.plugin.getCore().debug("Pickaxe slot is: " + pickaxeSlot, this.plugin);
|
||||
|
||||
new EnchantGUI(this.plugin, e.getPlayer(), pickAxe, pickaxeSlot).open();
|
||||
}).bindWith(this.plugin.getCore());
|
||||
}
|
||||
|
||||
private void subscribeToPlayerDropItemEvent() {
|
||||
// Dropping pickaxe
|
||||
Events.subscribe(PlayerDropItemEvent.class, EventPriority.HIGHEST)
|
||||
.handler(e -> {
|
||||
if (this.plugin.getCore().isPickaxeSupported(e.getItemDrop().getItemStack())) {
|
||||
this.plugin.getEnchantsManager().handlePickaxeUnequip(e.getPlayer(), e.getItemDrop().getItemStack());
|
||||
}
|
||||
}).bindWith(this.plugin.getCore());
|
||||
}
|
||||
|
||||
private void subscribeToPlayerJoinEvent() {
|
||||
//First join pickaxe
|
||||
Events.subscribe(PlayerJoinEvent.class)
|
||||
.filter(e -> !e.getPlayer().hasPlayedBefore() && this.plugin.getEnchantsConfig().isFirstJoinPickaxeEnabled())
|
||||
.handler(e -> {
|
||||
ItemStack firstJoinPickaxe = this.plugin.getEnchantsManager().createFirstJoinPickaxe(e.getPlayer());
|
||||
e.getPlayer().getInventory().addItem(firstJoinPickaxe);
|
||||
}).bindWith(this.plugin.getCore());
|
||||
}
|
||||
|
||||
private void subscribeToPlayerRespawnEvent() {
|
||||
Events.subscribe(PlayerRespawnEvent.class, EventPriority.LOWEST)
|
||||
.handler(e -> this.plugin.getRespawnManager().handleRespawn(e.getPlayer())).bindWith(this.plugin.getCore());
|
||||
}
|
||||
|
||||
private void subscribeToInventoryClickEvent() {
|
||||
//Grindstone disenchanting - disable
|
||||
if (MinecraftVersion.atLeast(MinecraftVersion.V.v1_14)) {
|
||||
Events.subscribe(InventoryClickEvent.class)
|
||||
.filter(e -> e.getInventory() instanceof GrindstoneInventory)
|
||||
.handler(e -> {
|
||||
ItemStack item1 = e.getInventory().getItem(0);
|
||||
ItemStack item2 = e.getInventory().getItem(1);
|
||||
if (e.getSlot() == 2 && (this.plugin.getEnchantsManager().hasEnchants(item1) || this.plugin.getEnchantsManager().hasEnchants(item2))) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}).bindWith(this.plugin.getCore());
|
||||
}
|
||||
|
||||
Events.subscribe(InventoryClickEvent.class, EventPriority.MONITOR)
|
||||
.filter(e -> e.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY)
|
||||
.filter(e -> e.getWhoClicked() instanceof Player)
|
||||
.filter(e -> !e.isCancelled())
|
||||
.handler(e -> {
|
||||
ItemStack item = e.getCurrentItem();
|
||||
if (this.plugin.getCore().isPickaxeSupported(item)) {
|
||||
this.plugin.getEnchantsManager().handlePickaxeUnequip((Player) e.getWhoClicked(), item);
|
||||
}
|
||||
}).bindWith(this.plugin.getCore());
|
||||
}
|
||||
|
||||
private void subscribeToPlayerDeathEvent() {
|
||||
Events.subscribe(PlayerDeathEvent.class, EventPriority.LOWEST)
|
||||
.handler(e -> {
|
||||
|
||||
if (!this.plugin.getEnchantsConfig().isKeepPickaxesOnDeath()) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<ItemStack> pickaxes = e.getDrops().stream().filter(itemStack -> this.plugin.getCore().isPickaxeSupported(itemStack) &&
|
||||
this.plugin.getEnchantsManager().hasEnchants(itemStack)).collect(Collectors.toList());
|
||||
e.getDrops().removeAll(pickaxes);
|
||||
|
||||
this.plugin.getRespawnManager().addRespawnItems(e.getEntity(), pickaxes);
|
||||
|
||||
if (pickaxes.size() > 0) {
|
||||
this.plugin.getCore().debug("Removed " + e.getEntity().getName() + "'s pickaxes from drops (" + pickaxes.size() + "). Will be given back on respawn.", this.plugin);
|
||||
} else {
|
||||
this.plugin.getCore().debug("No Pickaxes found for player " + e.getEntity().getName() + " (PlayerDeathEvent)", this.plugin);
|
||||
}
|
||||
|
||||
}).bindWith(this.plugin.getCore());
|
||||
}
|
||||
|
||||
private Optional<IWrappedFlag<WrappedState>> getWGFlag() {
|
||||
return this.plugin.getCore().getWorldGuardWrapper().getFlag(Constants.ENCHANTS_WG_FLAG_NAME, WrappedState.class);
|
||||
}
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
package me.nvus.xprison.enchants.managers;
|
||||
|
||||
import me.nvus.xprison.enchants.XPrisonEnchants;
|
||||
import me.lucko.helper.cooldown.Cooldown;
|
||||
import me.lucko.helper.cooldown.CooldownMap;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class CooldownManager {
|
||||
|
||||
private final XPrisonEnchants plugin;
|
||||
private final CooldownMap<Player> valueCooldown;
|
||||
|
||||
public CooldownManager(XPrisonEnchants plugin) {
|
||||
this.plugin = plugin;
|
||||
this.valueCooldown = CooldownMap.create(Cooldown.of(30, TimeUnit.SECONDS));
|
||||
}
|
||||
|
||||
public boolean hasValueCooldown(Player sender) {
|
||||
return !valueCooldown.test(sender);
|
||||
}
|
||||
|
||||
public long getRemainingTime(Player sender) {
|
||||
return valueCooldown.get(sender).remainingTime(TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
|
@ -1,560 +0,0 @@
|
|||
package me.nvus.xprison.enchants.managers;
|
||||
|
||||
import com.saicone.rtag.util.ServerInstance;
|
||||
import me.nvus.xprison.api.enums.LostCause;
|
||||
import me.nvus.xprison.api.enums.ReceiveCause;
|
||||
import me.nvus.xprison.enchants.XPrisonEnchants;
|
||||
import me.nvus.xprison.enchants.api.events.XPrisonPlayerEnchantEvent;
|
||||
import me.nvus.xprison.enchants.gui.DisenchantGUI;
|
||||
import me.nvus.xprison.enchants.gui.EnchantGUI;
|
||||
import me.nvus.xprison.enchants.model.XPrisonEnchantment;
|
||||
import me.nvus.xprison.enchants.repo.EnchantsRepository;
|
||||
import me.nvus.xprison.enchants.utils.EnchantUtils;
|
||||
import me.nvus.xprison.pickaxelevels.XPrisonPickaxeLevels;
|
||||
import me.nvus.xprison.pickaxelevels.model.PickaxeLevel;
|
||||
import me.nvus.xprison.utils.Constants;
|
||||
import me.nvus.xprison.utils.compat.CompMaterial;
|
||||
import me.nvus.xprison.utils.item.ItemStackBuilder;
|
||||
import me.nvus.xprison.utils.item.PrisonItem;
|
||||
import me.nvus.xprison.utils.misc.RegionUtils;
|
||||
import me.nvus.xprison.utils.player.PlayerUtils;
|
||||
import me.nvus.xprison.utils.text.TextUtils;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import me.lucko.helper.Events;
|
||||
import me.lucko.helper.Schedulers;
|
||||
import me.lucko.helper.time.Time;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.codemc.worldguardwrapper.flag.WrappedState;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class EnchantsManager {
|
||||
|
||||
private static final String EXCLUDE_PERMISSION = "xprison.enchant.exclude.";
|
||||
private static final String UNBREAK_PERMISSION = "xprison.pickaxe.unbreakable";
|
||||
private static final boolean USE_META_UNBREAK = ServerInstance.verNumber >= 11;
|
||||
private static final Pattern PICKAXE_LORE_ENCHANT_PATTER = Pattern.compile("(?i)%Enchant-\\d+%");
|
||||
|
||||
private final XPrisonEnchants plugin;
|
||||
private final List<UUID> lockedPlayers;
|
||||
|
||||
public EnchantsManager(XPrisonEnchants plugin) {
|
||||
this.plugin = plugin;
|
||||
this.lockedPlayers = Collections.synchronizedList(new ArrayList<>());
|
||||
}
|
||||
|
||||
public Map<XPrisonEnchantment, Integer> getItemEnchants(ItemStack itemStack) {
|
||||
|
||||
if (itemStack == null || itemStack.getType() == Material.AIR) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
return new PrisonItem(itemStack).getEnchants(getEnchantsRepository());
|
||||
}
|
||||
|
||||
public ItemStack updatePickaxe(Player player, ItemStack item) {
|
||||
|
||||
if (item == null || !this.plugin.getCore().isPickaxeSupported(item.getType())) {
|
||||
return item;
|
||||
}
|
||||
|
||||
return this.applyLoreToPickaxe(player, item);
|
||||
}
|
||||
|
||||
private ItemStack applyLoreToPickaxe(Player player, ItemStack item) {
|
||||
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
List<String> lore = new ArrayList<>();
|
||||
|
||||
boolean pickaxeLevels = this.plugin.getCore().isModuleEnabled(XPrisonPickaxeLevels.MODULE_NAME);
|
||||
|
||||
PickaxeLevel currentLevel = null;
|
||||
PickaxeLevel nextLevel = null;
|
||||
String pickaxeProgressBar = "";
|
||||
|
||||
if (pickaxeLevels) {
|
||||
currentLevel = this.plugin.getCore().getPickaxeLevels().getPickaxeLevelsManager().getPickaxeLevel(item).orElse(null);
|
||||
nextLevel = this.plugin.getCore().getPickaxeLevels().getPickaxeLevelsManager().getNextPickaxeLevel(currentLevel).orElse(null);
|
||||
pickaxeProgressBar = this.plugin.getCore().getPickaxeLevels().getPickaxeLevelsManager().getProgressBar(item);
|
||||
}
|
||||
|
||||
long blocksBroken = getBlocksBroken(item);
|
||||
final PrisonItem prisonItem = new PrisonItem(item);
|
||||
Map<XPrisonEnchantment, Integer> enchants = prisonItem.getEnchants(getEnchantsRepository());
|
||||
|
||||
List<String> pickaxeLore = this.plugin.getEnchantsConfig().getPickaxeLore();
|
||||
|
||||
final boolean isUnbreakable;
|
||||
Boolean unbreakResult = null;
|
||||
if (USE_META_UNBREAK ? meta.isUnbreakable() : prisonItem.isUnbreakable()) {
|
||||
if (!this.plugin.getEnchantsConfig().isUseUnbreakablePermission() || player.hasPermission(UNBREAK_PERMISSION)) {
|
||||
isUnbreakable = true;
|
||||
} else {
|
||||
isUnbreakable = false;
|
||||
unbreakResult = false;
|
||||
}
|
||||
} else {
|
||||
if (this.plugin.getEnchantsConfig().isUseUnbreakablePermission() && player.hasPermission(UNBREAK_PERMISSION)) {
|
||||
isUnbreakable = true;
|
||||
unbreakResult = true;
|
||||
} else {
|
||||
isUnbreakable = false;
|
||||
}
|
||||
}
|
||||
final String durability = isUnbreakable ? "∞" : String.valueOf(item.getType().getMaxDurability() - EnchantUtils.getDurability(item, meta));
|
||||
if (unbreakResult != null) {
|
||||
if (USE_META_UNBREAK) {
|
||||
meta.setUnbreakable(unbreakResult);
|
||||
} else {
|
||||
if (unbreakResult) {
|
||||
prisonItem.setUnbreakable(true);
|
||||
} else {
|
||||
prisonItem.remove("Unbreakable");
|
||||
}
|
||||
prisonItem.load();
|
||||
meta = item.getItemMeta();
|
||||
}
|
||||
}
|
||||
|
||||
for (String s : pickaxeLore) {
|
||||
s = s.replace("%Blocks%", String.valueOf(blocksBroken));
|
||||
s = s.replace("%Durability%", durability);
|
||||
|
||||
if (pickaxeLevels) {
|
||||
s = s.replace("%Blocks_Required%", nextLevel == null ? "∞" : String.valueOf(nextLevel.getBlocksRequired()));
|
||||
s = s.replace("%PickaxeLevel%", currentLevel == null ? "0" : String.valueOf(currentLevel.getLevel()));
|
||||
s = s.replace("%PickaxeProgress%", pickaxeProgressBar);
|
||||
}
|
||||
|
||||
Matcher matcher = PICKAXE_LORE_ENCHANT_PATTER.matcher(s);
|
||||
|
||||
if (matcher.find()) {
|
||||
int enchId = Integer.parseInt(matcher.group().replaceAll("\\D", ""));
|
||||
XPrisonEnchantment enchantment = getEnchantsRepository().getEnchantById(enchId);
|
||||
|
||||
if (enchantment != null) {
|
||||
int enchLvl = enchants.getOrDefault(enchantment, 0);
|
||||
if (enchLvl > 0) {
|
||||
final String line;
|
||||
if (player.hasPermission(EXCLUDE_PERMISSION + enchantment.getRawName())) {
|
||||
line = this.plugin.getEnchantsConfig().getExcludedFormat()
|
||||
.replace("%Enchant%", enchantment.getNameUncolor())
|
||||
.replace("%Level%", this.plugin.getEnchantsConfig().getLevelFormat().format(enchLvl));
|
||||
} else {
|
||||
line = enchantment.getName() + " " + this.plugin.getEnchantsConfig().getLevelFormat().format(enchLvl);
|
||||
}
|
||||
s = s.replace(matcher.group(), line);
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.plugin.getCore().isPlaceholderAPIEnabled()) {
|
||||
s = PlaceholderAPI.setPlaceholders(player, s);
|
||||
}
|
||||
|
||||
lore.add(TextUtils.applyColor(s));
|
||||
}
|
||||
|
||||
meta.setLore(lore);
|
||||
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
private EnchantsRepository getEnchantsRepository() {
|
||||
return this.plugin.getEnchantsRepository();
|
||||
}
|
||||
|
||||
public long getBlocksBroken(ItemStack item) {
|
||||
|
||||
if (item == null || item.getType() == Material.AIR) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return new PrisonItem(item).getBrokenBlocks();
|
||||
}
|
||||
|
||||
public synchronized void addBlocksBrokenToItem(Player p, int amount) {
|
||||
|
||||
if (amount == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
final PrisonItem prisonItem = new PrisonItem(p.getItemInHand());
|
||||
prisonItem.addBrokenBlocks(amount);
|
||||
ItemStack item = prisonItem.loadCopy();
|
||||
applyLoreToPickaxe(p, item);
|
||||
p.setItemInHand(item);
|
||||
}
|
||||
|
||||
public synchronized void addBlocksBrokenToItem(Player player, ItemStack item, int amount) {
|
||||
|
||||
if (amount == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
final PrisonItem prisonItem = new PrisonItem(item);
|
||||
prisonItem.addBrokenBlocks(amount);
|
||||
player.setItemInHand(prisonItem.loadCopy());
|
||||
applyLoreToPickaxe(player, player.getItemInHand());
|
||||
}
|
||||
|
||||
public synchronized int getEnchantLevel(ItemStack itemStack, XPrisonEnchantment enchantment) {
|
||||
|
||||
if (enchantment == null || itemStack == null || itemStack.getType() == Material.AIR) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return Math.min(new PrisonItem(itemStack).getEnchantLevel(enchantment), enchantment.getMaxLevel());
|
||||
}
|
||||
|
||||
public void forEachEffectiveEnchant(Player player, ItemStack item, BiConsumer<XPrisonEnchantment, Integer> consumer) {
|
||||
for (var entry : this.getItemEnchants(item).entrySet()) {
|
||||
final XPrisonEnchantment enchant = entry.getKey();
|
||||
if (enchant.isEnabled() && !player.hasPermission(EXCLUDE_PERMISSION + enchant.getRawName())) {
|
||||
consumer.accept(enchant, entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void handleBlockBreak(BlockBreakEvent e, ItemStack pickAxe) {
|
||||
|
||||
this.addBlocksBrokenToItem(e.getPlayer(), 1);
|
||||
|
||||
if (RegionUtils.getRegionWithHighestPriorityAndFlag(e.getBlock().getLocation(), Constants.ENCHANTS_WG_FLAG_NAME, WrappedState.ALLOW) == null) {
|
||||
this.plugin.getCore().debug("EnchantsManager::handleBlockBreak >> No region with flag upc-enchants found. Enchants will not be triggered.", this.plugin);
|
||||
return;
|
||||
}
|
||||
|
||||
forEachEffectiveEnchant(e.getPlayer(), pickAxe, (enchant, level) -> enchant.onBlockBreak(e, level));
|
||||
}
|
||||
|
||||
public void handlePickaxeEquip(Player p, ItemStack newItem) {
|
||||
forEachEffectiveEnchant(p, newItem, (enchant, level) -> enchant.onEquip(p, newItem, level));
|
||||
}
|
||||
|
||||
public void handlePickaxeUnequip(Player p, ItemStack newItem) {
|
||||
forEachEffectiveEnchant(p, newItem, (enchant, level) -> enchant.onUnequip(p, newItem, level));
|
||||
}
|
||||
|
||||
public ItemStack setEnchantLevel(Player player, ItemStack item, XPrisonEnchantment enchantment, int level) {
|
||||
|
||||
if (enchantment == null || item == null) {
|
||||
return item;
|
||||
}
|
||||
|
||||
final PrisonItem prisonItem = new PrisonItem(item);
|
||||
prisonItem.setEnchant(enchantment, level);
|
||||
prisonItem.load();
|
||||
return this.applyLoreToPickaxe(player, item);
|
||||
}
|
||||
|
||||
public ItemStack removeEnchant(Player player, ItemStack item, XPrisonEnchantment enchantment) {
|
||||
return setEnchantLevel(player, item, enchantment, 0);
|
||||
}
|
||||
|
||||
public void buyEnchnant(XPrisonEnchantment enchantment, EnchantGUI gui, int currentLevel, int addition) {
|
||||
|
||||
if (currentLevel >= enchantment.getMaxLevel()) {
|
||||
PlayerUtils.sendMessage(gui.getPlayer(), plugin.getEnchantsConfig().getMessage("enchant_max_level"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentLevel + addition > enchantment.getMaxLevel()) {
|
||||
PlayerUtils.sendMessage(gui.getPlayer(), plugin.getEnchantsConfig().getMessage("enchant_max_level_exceed"));
|
||||
return;
|
||||
}
|
||||
|
||||
long totalCost = 0;
|
||||
|
||||
long startTime = Time.nowMillis();
|
||||
|
||||
for (int j = 0; j < addition; j++) {
|
||||
totalCost += enchantment.getCostOfLevel(currentLevel + j + 1);
|
||||
}
|
||||
|
||||
this.plugin.getCore().debug(String.format("Calculation of levels %,d - %,d of %s enchant took %dms", currentLevel + 1, currentLevel + addition + 1, enchantment.getRawName(), Time.nowMillis() - startTime), this.plugin);
|
||||
|
||||
if (!plugin.getCore().getTokens().getApi().hasEnough(gui.getPlayer(), totalCost)) {
|
||||
PlayerUtils.sendMessage(gui.getPlayer(), plugin.getEnchantsConfig().getMessage("not_enough_tokens"));
|
||||
return;
|
||||
}
|
||||
|
||||
XPrisonPlayerEnchantEvent event = new XPrisonPlayerEnchantEvent(gui.getPlayer(), totalCost, currentLevel + addition);
|
||||
|
||||
Events.callSync(event);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.getCore().getTokens().getApi().removeTokens(gui.getPlayer(), totalCost, LostCause.ENCHANT);
|
||||
|
||||
this.setEnchantLevel(gui.getPlayer(), gui.getPickAxe(), enchantment, currentLevel + addition);
|
||||
|
||||
enchantment.onUnequip(gui.getPlayer(), gui.getPickAxe(), currentLevel);
|
||||
enchantment.onEquip(gui.getPlayer(), gui.getPickAxe(), currentLevel + addition);
|
||||
|
||||
gui.getPlayer().getInventory().setItem(gui.getPickaxePlayerInventorySlot(), gui.getPickAxe());
|
||||
|
||||
if (addition == 1) {
|
||||
PlayerUtils.sendMessage(gui.getPlayer(), plugin.getEnchantsConfig().getMessage("enchant_bought").replace("%tokens%", String.format("%,d", totalCost)));
|
||||
} else {
|
||||
PlayerUtils.sendMessage(gui.getPlayer(), plugin.getEnchantsConfig().getMessage("enchant_bought_multiple")
|
||||
.replace("%amount%", String.valueOf(addition))
|
||||
.replace("%enchant%", enchantment.getName())
|
||||
.replace("%tokens%", String.format("%,d", totalCost)));
|
||||
}
|
||||
}
|
||||
|
||||
public void disenchant(XPrisonEnchantment enchantment, DisenchantGUI gui, int currentLevel, int substraction) {
|
||||
|
||||
if (currentLevel <= 0) {
|
||||
PlayerUtils.sendMessage(gui.getPlayer(), plugin.getEnchantsConfig().getMessage("enchant_no_level"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentLevel - substraction < 0) {
|
||||
PlayerUtils.sendMessage(gui.getPlayer(), plugin.getEnchantsConfig().getMessage("enchant_min_level_exceed"));
|
||||
return;
|
||||
}
|
||||
|
||||
long totalRefunded = 0;
|
||||
|
||||
for (int j = 0; j < substraction; j++) {
|
||||
totalRefunded += enchantment.getRefundForLevel(currentLevel - j);
|
||||
}
|
||||
|
||||
plugin.getCore().getTokens().getTokensManager().giveTokens(gui.getPlayer(), totalRefunded, null, ReceiveCause.REFUND);
|
||||
|
||||
this.setEnchantLevel(gui.getPlayer(), gui.getPickAxe(), enchantment, currentLevel - substraction);
|
||||
|
||||
enchantment.onUnequip(gui.getPlayer(), gui.getPickAxe(), currentLevel);
|
||||
enchantment.onEquip(gui.getPlayer(), gui.getPickAxe(), currentLevel - substraction);
|
||||
|
||||
gui.getPlayer().getInventory().setItem(gui.getPickaxePlayerInventorySlot(), gui.getPickAxe());
|
||||
|
||||
PlayerUtils.sendMessage(gui.getPlayer(), plugin.getEnchantsConfig().getMessage("enchant_refunded").replace("%amount%", String.format("%,d", substraction)).replace("%enchant%", enchantment.getName()));
|
||||
PlayerUtils.sendMessage(gui.getPlayer(), plugin.getEnchantsConfig().getMessage("enchant_tokens_back").replace("%tokens%", String.format("%,d", totalRefunded)));
|
||||
}
|
||||
|
||||
public void disenchantMax(XPrisonEnchantment enchantment, DisenchantGUI gui, int currentLevel) {
|
||||
|
||||
if (currentLevel <= 0) {
|
||||
PlayerUtils.sendMessage(gui.getPlayer(), plugin.getEnchantsConfig().getMessage("enchant_no_level"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.lockedPlayers.contains(gui.getPlayer().getUniqueId())) {
|
||||
PlayerUtils.sendMessage(gui.getPlayer(), plugin.getEnchantsConfig().getMessage("transaction_in_progress"));
|
||||
return;
|
||||
}
|
||||
|
||||
this.lockedPlayers.add(gui.getPlayer().getUniqueId());
|
||||
|
||||
|
||||
Schedulers.async().run(() -> {
|
||||
int current = currentLevel;
|
||||
int levelsToRefund = current;
|
||||
|
||||
long totalRefunded = 0;
|
||||
|
||||
while (gui.getPlayer().isOnline() && current > 0) {
|
||||
totalRefunded += enchantment.getRefundForLevel(current);
|
||||
current--;
|
||||
}
|
||||
|
||||
if (!gui.getPlayer().isOnline()) {
|
||||
this.lockedPlayers.remove(gui.getPlayer().getUniqueId());
|
||||
return;
|
||||
}
|
||||
|
||||
int finalCurrent = current;
|
||||
|
||||
this.lockedPlayers.remove(gui.getPlayer().getUniqueId());
|
||||
|
||||
Schedulers.sync().run(() -> {
|
||||
enchantment.onUnequip(gui.getPlayer(), gui.getPickAxe(), currentLevel);
|
||||
this.setEnchantLevel(gui.getPlayer(), gui.getPickAxe(), enchantment, finalCurrent);
|
||||
gui.getPlayer().getInventory().setItem(gui.getPickaxePlayerInventorySlot(), gui.getPickAxe());
|
||||
enchantment.onEquip(gui.getPlayer(), gui.getPickAxe(), finalCurrent);
|
||||
gui.redraw();
|
||||
});
|
||||
|
||||
plugin.getCore().getTokens().getTokensManager().giveTokens(gui.getPlayer(), totalRefunded, null, ReceiveCause.REFUND);
|
||||
|
||||
PlayerUtils.sendMessage(gui.getPlayer(), plugin.getEnchantsConfig().getMessage("enchant_refunded").replace("%amount%", String.format("%,d", levelsToRefund)).replace("%enchant%", enchantment.getName()));
|
||||
PlayerUtils.sendMessage(gui.getPlayer(), plugin.getEnchantsConfig().getMessage("enchant_tokens_back").replace("%tokens%", String.format("%,d", totalRefunded)));
|
||||
});
|
||||
}
|
||||
|
||||
public void buyMaxEnchant(XPrisonEnchantment enchantment, EnchantGUI gui, int currentLevel) {
|
||||
|
||||
if (currentLevel >= enchantment.getMaxLevel()) {
|
||||
PlayerUtils.sendMessage(gui.getPlayer(), plugin.getEnchantsConfig().getMessage("enchant_max_level"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.lockedPlayers.contains(gui.getPlayer().getUniqueId())) {
|
||||
PlayerUtils.sendMessage(gui.getPlayer(), plugin.getEnchantsConfig().getMessage("transaction_in_progress"));
|
||||
return;
|
||||
}
|
||||
|
||||
this.lockedPlayers.add(gui.getPlayer().getUniqueId());
|
||||
|
||||
Schedulers.async().run(() -> {
|
||||
int levelsToBuy = 0;
|
||||
long totalCost = 0;
|
||||
|
||||
while (gui.getPlayer().isOnline() && (currentLevel + levelsToBuy + 1) <= enchantment.getMaxLevel() && this.plugin.getCore().getTokens().getApi().hasEnough(gui.getPlayer(), totalCost + enchantment.getCostOfLevel(currentLevel + levelsToBuy + 1))) {
|
||||
levelsToBuy += 1;
|
||||
totalCost += enchantment.getCostOfLevel(currentLevel + levelsToBuy + 1);
|
||||
}
|
||||
|
||||
if (!gui.getPlayer().isOnline()) {
|
||||
this.lockedPlayers.remove(gui.getPlayer().getUniqueId());
|
||||
return;
|
||||
}
|
||||
|
||||
if (levelsToBuy == 0) {
|
||||
this.lockedPlayers.remove(gui.getPlayer().getUniqueId());
|
||||
PlayerUtils.sendMessage(gui.getPlayer(), plugin.getEnchantsConfig().getMessage("not_enough_tokens"));
|
||||
return;
|
||||
}
|
||||
|
||||
XPrisonPlayerEnchantEvent event = new XPrisonPlayerEnchantEvent(gui.getPlayer(), totalCost, currentLevel + levelsToBuy);
|
||||
|
||||
Events.callSync(event);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
this.lockedPlayers.remove(gui.getPlayer().getUniqueId());
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.getCore().getTokens().getApi().removeTokens(gui.getPlayer(), totalCost, LostCause.ENCHANT);
|
||||
|
||||
int finalLevelsToBuy = levelsToBuy;
|
||||
|
||||
this.lockedPlayers.remove(gui.getPlayer().getUniqueId());
|
||||
Schedulers.sync().run(() -> {
|
||||
enchantment.onUnequip(gui.getPlayer(), gui.getPickAxe(), currentLevel);
|
||||
this.setEnchantLevel(gui.getPlayer(), gui.getPickAxe(), enchantment, currentLevel + finalLevelsToBuy);
|
||||
enchantment.onEquip(gui.getPlayer(), gui.getPickAxe(), currentLevel + finalLevelsToBuy);
|
||||
gui.getPlayer().getInventory().setItem(gui.getPickaxePlayerInventorySlot(), gui.getPickAxe());
|
||||
gui.redraw();
|
||||
});
|
||||
|
||||
if (levelsToBuy == 1) {
|
||||
PlayerUtils.sendMessage(gui.getPlayer(), plugin.getEnchantsConfig().getMessage("enchant_bought").replace("%tokens%", String.format("%,d", totalCost)));
|
||||
} else {
|
||||
PlayerUtils.sendMessage(gui.getPlayer(), plugin.getEnchantsConfig().getMessage("enchant_bought_multiple")
|
||||
.replace("%amount%", String.valueOf(levelsToBuy))
|
||||
.replace("%enchant%", enchantment.getName())
|
||||
.replace("%tokens%", String.format("%,d", totalCost)));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public long getPickaxeValue(ItemStack pickAxe) {
|
||||
|
||||
long sum = 0;
|
||||
|
||||
Map<XPrisonEnchantment, Integer> playerEnchants = this.getItemEnchants(pickAxe);
|
||||
|
||||
for (XPrisonEnchantment enchantment : playerEnchants.keySet()) {
|
||||
for (int i = 1; i <= playerEnchants.get(enchantment); i++) {
|
||||
sum += enchantment.getCostOfLevel(i);
|
||||
}
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
// /givepickaxe <player> <enchant:18=1;...> <name>
|
||||
public void givePickaxe(Player target, Map<XPrisonEnchantment, Integer> enchants, String pickaxeName, CommandSender sender) {
|
||||
ItemStackBuilder pickaxeBuilder = ItemStackBuilder.of(Material.DIAMOND_PICKAXE);
|
||||
|
||||
if (pickaxeName != null) {
|
||||
pickaxeBuilder.name(pickaxeName);
|
||||
}
|
||||
|
||||
ItemStack pickaxe = pickaxeBuilder.build();
|
||||
|
||||
for (Map.Entry<XPrisonEnchantment, Integer> entry : enchants.entrySet()) {
|
||||
this.setEnchantLevel(target, pickaxe, entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
pickaxe = this.applyLoreToPickaxe(target, pickaxe);
|
||||
|
||||
if (target == null && sender instanceof Player) {
|
||||
target = (Player) sender;
|
||||
}
|
||||
|
||||
if (target != null) {
|
||||
if (target.getInventory().firstEmpty() == -1) {
|
||||
PlayerUtils.sendMessage(sender, this.plugin.getEnchantsConfig().getMessage("pickaxe_inventory_full").replace("%player%", target.getName()));
|
||||
return;
|
||||
}
|
||||
|
||||
target.getInventory().addItem(pickaxe);
|
||||
PlayerUtils.sendMessage(sender, this.plugin.getEnchantsConfig().getMessage("pickaxe_given").replace("%player%", target.getName()));
|
||||
PlayerUtils.sendMessage(target, this.plugin.getEnchantsConfig().getMessage("pickaxe_received").replace("%sender%", sender.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
public ItemStack createFirstJoinPickaxe(Player player) {
|
||||
|
||||
String pickaxeName = this.plugin.getEnchantsConfig().getFirstJoinPickaxeName();
|
||||
pickaxeName = pickaxeName.replace("%player%", player.getName());
|
||||
|
||||
if (this.plugin.getCore().isPlaceholderAPIEnabled()) {
|
||||
pickaxeName = PlaceholderAPI.setPlaceholders(player, pickaxeName);
|
||||
}
|
||||
|
||||
CompMaterial material = this.plugin.getEnchantsConfig().getFirstJoinPickaxeMaterial();
|
||||
ItemStack item = ItemStackBuilder.of(material.toItem()).name(pickaxeName).build();
|
||||
|
||||
List<String> firstJoinPickaxeEnchants = this.plugin.getEnchantsConfig().getFirstJoinPickaxeEnchants();
|
||||
|
||||
for (String s : firstJoinPickaxeEnchants) {
|
||||
try {
|
||||
String[] data = s.split(" ");
|
||||
XPrisonEnchantment enchantment = getEnchantsRepository().getEnchantByName(data[0]);
|
||||
int level = Integer.parseInt(data[1]);
|
||||
this.setEnchantLevel(player, item, enchantment, level);
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return this.applyLoreToPickaxe(player, item);
|
||||
}
|
||||
|
||||
public boolean hasEnchants(ItemStack item) {
|
||||
return item != null && !this.getItemEnchants(item).isEmpty();
|
||||
}
|
||||
|
||||
public void enable() {
|
||||
|
||||
}
|
||||
|
||||
public void disable() {
|
||||
|
||||
}
|
||||
|
||||
public void giveFirstJoinPickaxe(Player target) {
|
||||
target.getInventory().addItem(this.createFirstJoinPickaxe(target));
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
package me.nvus.xprison.enchants.managers;
|
||||
|
||||
import me.nvus.xprison.enchants.XPrisonEnchants;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class RespawnManager {
|
||||
|
||||
private final XPrisonEnchants plugin;
|
||||
private final Map<UUID, List<ItemStack>> respawnItems;
|
||||
|
||||
|
||||
public RespawnManager(XPrisonEnchants plugin) {
|
||||
this.plugin = plugin;
|
||||
this.respawnItems = new HashMap<>();
|
||||
}
|
||||
|
||||
public void addRespawnItems(Player player, List<ItemStack> items) {
|
||||
this.respawnItems.put(player.getUniqueId(), items);
|
||||
}
|
||||
|
||||
public void handleRespawn(Player player) {
|
||||
if (this.respawnItems.containsKey(player.getUniqueId())) {
|
||||
this.respawnItems.remove(player.getUniqueId()).forEach(itemStack -> {
|
||||
player.getInventory().addItem(itemStack);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
package me.nvus.xprison.enchants.model;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public enum LevelFormat {
|
||||
|
||||
NUMBER, ROMAN, FIXED;
|
||||
|
||||
private static final Map<Integer, String> FIXED_NUMBERS = Map.of(
|
||||
1, "I",
|
||||
2, "II",
|
||||
3, "III",
|
||||
4, "IV",
|
||||
5, "V",
|
||||
6, "VI",
|
||||
7, "VII",
|
||||
8, "VIII",
|
||||
9, "IX",
|
||||
10, "X"
|
||||
);
|
||||
|
||||
private static final TreeMap<Integer, String> ROMAN_NUMBERS = new TreeMap<>();
|
||||
|
||||
static {
|
||||
ROMAN_NUMBERS.put(1000, "M");
|
||||
ROMAN_NUMBERS.put(900, "CM");
|
||||
ROMAN_NUMBERS.put(500, "D");
|
||||
ROMAN_NUMBERS.put(400, "CD");
|
||||
ROMAN_NUMBERS.put(100, "C");
|
||||
ROMAN_NUMBERS.put(90, "XC");
|
||||
ROMAN_NUMBERS.put(50, "L");
|
||||
ROMAN_NUMBERS.put(40, "XL");
|
||||
ROMAN_NUMBERS.put(10, "X");
|
||||
ROMAN_NUMBERS.put(9, "IX");
|
||||
ROMAN_NUMBERS.put(5, "V");
|
||||
ROMAN_NUMBERS.put(4, "IV");
|
||||
ROMAN_NUMBERS.put(1, "I");
|
||||
}
|
||||
|
||||
public static LevelFormat of(String name) {
|
||||
if (name == null) {
|
||||
return LevelFormat.NUMBER;
|
||||
}
|
||||
switch (name.trim().toUpperCase()) {
|
||||
case "ROMAN":
|
||||
return LevelFormat.ROMAN;
|
||||
case "FIXED":
|
||||
return LevelFormat.FIXED;
|
||||
case "NUMBER":
|
||||
default:
|
||||
return LevelFormat.NUMBER;
|
||||
}
|
||||
}
|
||||
|
||||
public String format(int level) {
|
||||
if (this == NUMBER || level < 1) {
|
||||
return String.valueOf(level);
|
||||
}
|
||||
if (level <= 10) {
|
||||
return FIXED_NUMBERS.get(level);
|
||||
}
|
||||
if (this == ROMAN) {
|
||||
return toRoman(level);
|
||||
}
|
||||
return String.valueOf(level);
|
||||
}
|
||||
|
||||
private String toRoman(int level) {
|
||||
final int mapLevel = ROMAN_NUMBERS.floorKey(level);
|
||||
if (mapLevel == level) {
|
||||
return ROMAN_NUMBERS.get(level);
|
||||
}
|
||||
return ROMAN_NUMBERS.get(mapLevel) + toRoman(level - mapLevel);
|
||||
}
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
package me.nvus.xprison.enchants.model;
|
||||
|
||||
public interface Refundable {
|
||||
|
||||
boolean isRefundEnabled();
|
||||
|
||||
int getRefundGuiSlot();
|
||||
|
||||
double getRefundPercentage();
|
||||
}
|
|
@ -1,116 +0,0 @@
|
|||
package me.nvus.xprison.enchants.model;
|
||||
|
||||
import me.nvus.xprison.enchants.XPrisonEnchants;
|
||||
import me.nvus.xprison.pickaxelevels.XPrisonPickaxeLevels;
|
||||
import me.nvus.xprison.pickaxelevels.model.PickaxeLevel;
|
||||
import me.nvus.xprison.utils.compat.CompMaterial;
|
||||
import me.nvus.xprison.utils.text.TextUtils;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Getter
|
||||
public abstract class XPrisonEnchantment implements Refundable {
|
||||
|
||||
protected final XPrisonEnchants plugin;
|
||||
|
||||
protected final int id;
|
||||
private String rawName;
|
||||
private String name;
|
||||
private String nameUncolor;
|
||||
private String guiName;
|
||||
private String base64;
|
||||
private Material material;
|
||||
private List<String> description;
|
||||
private boolean enabled;
|
||||
private int guiSlot;
|
||||
private int maxLevel;
|
||||
private long cost;
|
||||
private long increaseCost;
|
||||
private int requiredPickaxeLevel;
|
||||
private boolean messagesEnabled;
|
||||
private boolean refundEnabled;
|
||||
private int refundGuiSlot;
|
||||
private double refundPercentage;
|
||||
|
||||
public XPrisonEnchantment(XPrisonEnchants plugin, int id) {
|
||||
this.plugin = plugin;
|
||||
this.id = id;
|
||||
this.reloadDefaultAttributes();
|
||||
this.reload();
|
||||
}
|
||||
|
||||
private void reloadDefaultAttributes() {
|
||||
this.rawName = this.plugin.getEnchantsConfig().getYamlConfig().getString("enchants." + id + ".RawName");
|
||||
this.name = TextUtils.applyColor(this.plugin.getEnchantsConfig().getYamlConfig().getString("enchants." + id + ".Name"));
|
||||
this.nameUncolor = this.name.replaceAll("§.", "");
|
||||
this.guiName = TextUtils.applyColor(this.plugin.getEnchantsConfig().getYamlConfig().getString("enchants." + id + ".GuiName"));
|
||||
this.material = CompMaterial.fromString(this.plugin.getEnchantsConfig().getYamlConfig().getString("enchants." + id + ".Material")).toMaterial();
|
||||
this.description = TextUtils.applyColor(this.plugin.getEnchantsConfig().getYamlConfig().getStringList("enchants." + id + ".Description"));
|
||||
this.enabled = this.plugin.getEnchantsConfig().getYamlConfig().getBoolean("enchants." + id + ".Enabled");
|
||||
this.guiSlot = this.plugin.getEnchantsConfig().getYamlConfig().getInt("enchants." + id + ".InGuiSlot");
|
||||
this.maxLevel = this.plugin.getEnchantsConfig().getYamlConfig().getInt("enchants." + id + ".Max");
|
||||
this.cost = this.plugin.getEnchantsConfig().getYamlConfig().getLong("enchants." + id + ".Cost");
|
||||
this.increaseCost = this.plugin.getEnchantsConfig().getYamlConfig().getLong("enchants." + id + ".Increase-Cost-by");
|
||||
this.requiredPickaxeLevel = this.plugin.getEnchantsConfig().getYamlConfig().getInt("enchants." + id + ".Pickaxe-Level-Required");
|
||||
this.messagesEnabled = this.plugin.getEnchantsConfig().getYamlConfig().getBoolean("enchants." + id + ".Messages-Enabled", true);
|
||||
this.base64 = this.plugin.getEnchantsConfig().getYamlConfig().getString("enchants." + id + ".Base64", null);
|
||||
this.refundEnabled = this.plugin.getEnchantsConfig().getYamlConfig().getBoolean("enchants." + this.id + ".Refund.Enabled", true);
|
||||
this.refundGuiSlot = this.plugin.getEnchantsConfig().getYamlConfig().getInt("enchants." + this.id + ".Refund.InGuiSlot");
|
||||
this.refundPercentage = this.plugin.getEnchantsConfig().getYamlConfig().getDouble("enchants." + this.id + ".Refund.Percentage", 100.0d);
|
||||
}
|
||||
|
||||
public abstract String getAuthor();
|
||||
|
||||
public abstract void onEquip(Player p, ItemStack pickAxe, int level);
|
||||
|
||||
public abstract void onUnequip(Player p, ItemStack pickAxe, int level);
|
||||
|
||||
public abstract void onBlockBreak(BlockBreakEvent e, int enchantLevel);
|
||||
|
||||
public abstract double getChanceToTrigger(int enchantLevel);
|
||||
|
||||
public void reload() {
|
||||
this.reloadDefaultAttributes();
|
||||
}
|
||||
|
||||
public long getCostOfLevel(int level) {
|
||||
return (this.cost + (this.increaseCost * (level - 1)));
|
||||
}
|
||||
|
||||
public long getRefundForLevel(int level) {
|
||||
return (long) (this.getCostOfLevel(level) * (this.getRefundPercentage() / 100.0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRefundEnabled() {
|
||||
return refundEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getRefundPercentage() {
|
||||
return refundPercentage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRefundGuiSlot() {
|
||||
return refundGuiSlot;
|
||||
}
|
||||
|
||||
public int getMaxLevel() {
|
||||
return this.maxLevel == -1 ? Integer.MAX_VALUE : this.maxLevel;
|
||||
}
|
||||
|
||||
public boolean canBeBought(ItemStack pickAxe) {
|
||||
if (!this.plugin.getCore().isModuleEnabled(XPrisonPickaxeLevels.MODULE_NAME)) {
|
||||
return true;
|
||||
}
|
||||
Optional<PickaxeLevel> pickaxeLevelOptional = this.plugin.getCore().getPickaxeLevels().getApi().getPickaxeLevel(pickAxe);
|
||||
return pickaxeLevelOptional.map(level -> level.getLevel() >= this.requiredPickaxeLevel).orElse(true);
|
||||
}
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
package me.nvus.xprison.enchants.model.impl;
|
||||
|
||||
import me.nvus.xprison.autosell.XPrisonAutoSell;
|
||||
import me.nvus.xprison.enchants.XPrisonEnchants;
|
||||
import me.nvus.xprison.enchants.model.XPrisonEnchantment;
|
||||
import me.nvus.xprison.utils.misc.RegionUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public final class AutoSellEnchant extends XPrisonEnchantment {
|
||||
|
||||
private double chance;
|
||||
|
||||
public AutoSellEnchant(XPrisonEnchants instance) {
|
||||
super(instance, 19);
|
||||
this.chance = plugin.getEnchantsConfig().getYamlConfig().getDouble("enchants." + id + ".Chance");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthor() {
|
||||
return "Drawethree";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEquip(Player p, ItemStack pickAxe, int level) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnequip(Player p, ItemStack pickAxe, int level) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockBreak(BlockBreakEvent e, int enchantLevel) {
|
||||
|
||||
if (!this.plugin.getCore().isModuleEnabled(XPrisonAutoSell.MODULE_NAME)) {
|
||||
return;
|
||||
}
|
||||
|
||||
double chance = getChanceToTrigger(enchantLevel);
|
||||
if (chance < ThreadLocalRandom.current().nextDouble(100)) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.plugin.getCore().getAutoSell().getManager().sellAll(e.getPlayer(), RegionUtils.getRegionWithHighestPriority(e.getPlayer().getLocation()));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getChanceToTrigger(int enchantLevel) {
|
||||
return chance * enchantLevel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
super.reload();
|
||||
this.chance = plugin.getEnchantsConfig().getYamlConfig().getDouble("enchants." + id + ".Chance");
|
||||
}
|
||||
}
|
|
@ -1,69 +0,0 @@
|
|||
package me.nvus.xprison.enchants.model.impl;
|
||||
|
||||
import dev.drawethree.ultrabackpacks.api.UltraBackpacksAPI;
|
||||
import dev.drawethree.ultrabackpacks.api.exception.BackpackNotFoundException;
|
||||
import me.nvus.xprison.XPrison;
|
||||
import me.nvus.xprison.enchants.XPrisonEnchants;
|
||||
import me.nvus.xprison.enchants.model.XPrisonEnchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public final class BackpackAutoSellEnchant extends XPrisonEnchantment {
|
||||
|
||||
private double chance;
|
||||
|
||||
public BackpackAutoSellEnchant(XPrisonEnchants instance) {
|
||||
super(instance, 19);
|
||||
this.chance = plugin.getEnchantsConfig().getYamlConfig().getDouble("enchants." + id + ".Chance");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthor() {
|
||||
return "Drawethree";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEquip(Player p, ItemStack pickAxe, int level) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnequip(Player p, ItemStack pickAxe, int level) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockBreak(BlockBreakEvent e, int enchantLevel) {
|
||||
|
||||
if (!XPrison.getInstance().isUltraBackpacksEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
double chance = getChanceToTrigger(enchantLevel);
|
||||
|
||||
if (chance < ThreadLocalRandom.current().nextDouble(100)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
UltraBackpacksAPI.sellBackpack(e.getPlayer(), true);
|
||||
} catch (BackpackNotFoundException ignored) {
|
||||
this.plugin.getCore().debug("BackpackAutoSellEnchant::onBlockBreak > Player " + e.getPlayer().getName() + " does not have backpack.", this.plugin);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getChanceToTrigger(int enchantLevel) {
|
||||
return this.chance * enchantLevel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
super.reload();
|
||||
this.chance = plugin.getEnchantsConfig().getYamlConfig().getDouble("enchants." + id + ".Chance");
|
||||
}
|
||||
}
|
|
@ -1,92 +0,0 @@
|
|||
package me.nvus.xprison.enchants.model.impl;
|
||||
|
||||
import me.nvus.xprison.api.enums.ReceiveCause;
|
||||
import me.nvus.xprison.enchants.XPrisonEnchants;
|
||||
import me.nvus.xprison.enchants.model.XPrisonEnchantment;
|
||||
import me.nvus.xprison.tokens.XPrisonTokens;
|
||||
import me.nvus.xprison.utils.player.PlayerUtils;
|
||||
import me.lucko.helper.utils.Players;
|
||||
import net.objecthunter.exp4j.Expression;
|
||||
import net.objecthunter.exp4j.ExpressionBuilder;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public final class BlessingEnchant extends XPrisonEnchantment {
|
||||
|
||||
private double chance;
|
||||
private String amountToGiveExpression;
|
||||
|
||||
public BlessingEnchant(XPrisonEnchants instance) {
|
||||
super(instance, 13);
|
||||
this.chance = plugin.getEnchantsConfig().getYamlConfig().getDouble("enchants." + id + ".Chance");
|
||||
this.amountToGiveExpression = plugin.getEnchantsConfig().getYamlConfig().getString("enchants." + id + ".Amount-To-Give");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthor() {
|
||||
return "Drawethree";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEquip(Player p, ItemStack pickAxe, int level) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnequip(Player p, ItemStack pickAxe, int level) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockBreak(BlockBreakEvent e, int enchantLevel) {
|
||||
|
||||
if (!this.plugin.getCore().isModuleEnabled(XPrisonTokens.MODULE_NAME)) {
|
||||
return;
|
||||
}
|
||||
|
||||
double chance = getChanceToTrigger(enchantLevel);
|
||||
|
||||
if (chance < ThreadLocalRandom.current().nextDouble(100)) {
|
||||
return;
|
||||
}
|
||||
|
||||
long amount = (long) createExpression(enchantLevel).evaluate();
|
||||
|
||||
for (Player p : Players.all()) {
|
||||
plugin.getCore().getTokens().getTokensManager().giveTokens(p, amount, null, ReceiveCause.MINING_OTHERS);
|
||||
|
||||
if (!this.isMessagesEnabled()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (p.equals(e.getPlayer())) {
|
||||
PlayerUtils.sendMessage(p, plugin.getEnchantsConfig().getMessage("blessing_your").replace("%amount%", String.format("%,d", amount)));
|
||||
} else {
|
||||
PlayerUtils.sendMessage(p, plugin.getEnchantsConfig().getMessage("blessing_other").replace("%amount%", String.format("%,d", amount)).replace("%player%", e.getPlayer().getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getChanceToTrigger(int enchantLevel) {
|
||||
return chance * enchantLevel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
super.reload();
|
||||
this.chance = plugin.getEnchantsConfig().getYamlConfig().getDouble("enchants." + id + ".Chance");
|
||||
this.amountToGiveExpression = plugin.getEnchantsConfig().getYamlConfig().getString("enchants." + id + ".Amount-To-Give");
|
||||
}
|
||||
|
||||
private Expression createExpression(int level) {
|
||||
return new ExpressionBuilder(this.amountToGiveExpression)
|
||||
.variables("level")
|
||||
.build()
|
||||
.setVariable("level", level);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,127 +0,0 @@
|
|||
package me.nvus.xprison.enchants.model.impl;
|
||||
|
||||
import me.nvus.xprison.enchants.XPrisonEnchants;
|
||||
import me.nvus.xprison.enchants.model.XPrisonEnchantment;
|
||||
import me.nvus.xprison.tokens.api.events.XPrisonBlockBreakEvent;
|
||||
import me.nvus.xprison.utils.player.PlayerUtils;
|
||||
import me.lucko.helper.Events;
|
||||
import me.lucko.helper.Schedulers;
|
||||
import me.lucko.helper.time.Time;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public final class BlockBoosterEnchant extends XPrisonEnchantment {
|
||||
|
||||
private static final Map<UUID, Long> BOOSTED_PLAYERS = new HashMap<>();
|
||||
private double chance;
|
||||
|
||||
public BlockBoosterEnchant(XPrisonEnchants instance) {
|
||||
super(instance, 17);
|
||||
this.chance = plugin.getEnchantsConfig().getYamlConfig().getDouble("enchants." + id + ".Chance");
|
||||
|
||||
Events.subscribe(XPrisonBlockBreakEvent.class)
|
||||
.handler(e -> {
|
||||
if (BOOSTED_PLAYERS.containsKey(e.getPlayer().getUniqueId())) {
|
||||
List<Block> blocks = new ArrayList<>();
|
||||
for (Block b : e.getBlocks()) {
|
||||
blocks.add(b);
|
||||
blocks.add(b);
|
||||
}
|
||||
e.setBlocks(blocks);
|
||||
}
|
||||
}).bindWith(instance.getCore());
|
||||
}
|
||||
|
||||
public static boolean hasBlockBoosterRunning(Player p) {
|
||||
return BOOSTED_PLAYERS.containsKey(p.getUniqueId());
|
||||
}
|
||||
|
||||
public static String getTimeLeft(Player p) {
|
||||
|
||||
if (!BOOSTED_PLAYERS.containsKey(p.getUniqueId())) {
|
||||
return "";
|
||||
}
|
||||
|
||||
long endTime = BOOSTED_PLAYERS.get(p.getUniqueId());
|
||||
|
||||
if (System.currentTimeMillis() > endTime) {
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
long timeLeft = endTime - System.currentTimeMillis();
|
||||
|
||||
long days = timeLeft / (24 * 60 * 60 * 1000);
|
||||
timeLeft -= days * (24 * 60 * 60 * 1000);
|
||||
|
||||
long hours = timeLeft / (60 * 60 * 1000);
|
||||
timeLeft -= hours * (60 * 60 * 1000);
|
||||
|
||||
long minutes = timeLeft / (60 * 1000);
|
||||
timeLeft -= minutes * (60 * 1000);
|
||||
|
||||
long seconds = timeLeft / (1000);
|
||||
|
||||
timeLeft -= seconds * 1000;
|
||||
|
||||
return ChatColor.GRAY + "(" + ChatColor.WHITE + days + "d " + hours + "h " + minutes + "m " + seconds + "s" + ChatColor.GRAY + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEquip(Player p, ItemStack pickAxe, int level) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnequip(Player p, ItemStack pickAxe, int level) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockBreak(BlockBreakEvent e, int enchantLevel) {
|
||||
if (hasBlockBoosterRunning(e.getPlayer())) {
|
||||
return;
|
||||
}
|
||||
|
||||
double chance = getChanceToTrigger(enchantLevel);
|
||||
|
||||
if (chance < ThreadLocalRandom.current().nextDouble(100)) {
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerUtils.sendMessage(e.getPlayer(), this.plugin.getEnchantsConfig().getMessage("block_booster_on"));
|
||||
|
||||
BOOSTED_PLAYERS.put(e.getPlayer().getUniqueId(), Time.nowMillis() + TimeUnit.MINUTES.toMillis(1));
|
||||
|
||||
Schedulers.sync().runLater(() -> {
|
||||
if (e.getPlayer().isOnline()) {
|
||||
PlayerUtils.sendMessage(e.getPlayer(), this.plugin.getEnchantsConfig().getMessage("block_booster_off"));
|
||||
}
|
||||
BOOSTED_PLAYERS.remove(e.getPlayer().getUniqueId());
|
||||
}, 5, TimeUnit.MINUTES);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getChanceToTrigger(int enchantLevel) {
|
||||
return chance * enchantLevel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
super.reload();
|
||||
this.chance = plugin.getEnchantsConfig().getYamlConfig().getDouble("enchants." + id + ".Chance");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthor() {
|
||||
return "Drawethree";
|
||||
}
|
||||
}
|
|
@ -1,91 +0,0 @@
|
|||
package me.nvus.xprison.enchants.model.impl;
|
||||
|
||||
import me.nvus.xprison.enchants.XPrisonEnchants;
|
||||
import me.nvus.xprison.enchants.model.XPrisonEnchantment;
|
||||
import me.nvus.xprison.tokens.XPrisonTokens;
|
||||
import me.nvus.xprison.utils.player.PlayerUtils;
|
||||
import me.lucko.helper.utils.Players;
|
||||
import net.objecthunter.exp4j.Expression;
|
||||
import net.objecthunter.exp4j.ExpressionBuilder;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public final class CharityEnchant extends XPrisonEnchantment {
|
||||
|
||||
private double chance;
|
||||
private String amountToGiveExpression;
|
||||
|
||||
public CharityEnchant(XPrisonEnchants instance) {
|
||||
super(instance, 11);
|
||||
this.chance = plugin.getEnchantsConfig().getYamlConfig().getDouble("enchants." + id + ".Chance");
|
||||
this.amountToGiveExpression = plugin.getEnchantsConfig().getYamlConfig().getString("enchants." + id + ".Amount-To-Give");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthor() {
|
||||
return "Drawethree";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEquip(Player p, ItemStack pickAxe, int level) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnequip(Player p, ItemStack pickAxe, int level) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockBreak(BlockBreakEvent e, int enchantLevel) {
|
||||
|
||||
if (!this.plugin.getCore().isModuleEnabled(XPrisonTokens.MODULE_NAME)) {
|
||||
return;
|
||||
}
|
||||
|
||||
double chance = getChanceToTrigger(enchantLevel);
|
||||
|
||||
if (chance < ThreadLocalRandom.current().nextDouble(100)) {
|
||||
return;
|
||||
}
|
||||
|
||||
long amount = (long) createExpression(enchantLevel).evaluate();
|
||||
|
||||
for (Player p : Players.all()) {
|
||||
plugin.getCore().getEconomy().depositPlayer(p, amount);
|
||||
|
||||
if (!this.isMessagesEnabled()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (p.equals(e.getPlayer())) {
|
||||
PlayerUtils.sendMessage(p, plugin.getEnchantsConfig().getMessage("charity_your").replace("%amount%", String.format("%,d", amount)));
|
||||
} else {
|
||||
PlayerUtils.sendMessage(p, plugin.getEnchantsConfig().getMessage("charity_other").replace("%amount%", String.format("%,d", amount)).replace("%player%", e.getPlayer().getName()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getChanceToTrigger(int enchantLevel) {
|
||||
return chance * enchantLevel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
super.reload();
|
||||
this.chance = plugin.getEnchantsConfig().getYamlConfig().getDouble("enchants." + id + ".Chance");
|
||||
this.amountToGiveExpression = plugin.getEnchantsConfig().getYamlConfig().getString("enchants." + id + ".Amount-To-Give");
|
||||
}
|
||||
|
||||
private Expression createExpression(int level) {
|
||||
return new ExpressionBuilder(this.amountToGiveExpression)
|
||||
.variables("level")
|
||||
.build()
|
||||
.setVariable("level", level);
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
package me.nvus.xprison.enchants.model.impl;
|
||||
|
||||
import me.nvus.xprison.enchants.XPrisonEnchants;
|
||||
import me.nvus.xprison.enchants.model.XPrisonEnchantment;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
public final class EfficiencyEnchant extends XPrisonEnchantment {
|
||||
public EfficiencyEnchant(XPrisonEnchants instance) {
|
||||
super(instance, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEquip(Player p, ItemStack pickAxe, int level) {
|
||||
ItemMeta meta = pickAxe.getItemMeta();
|
||||
meta.addEnchant(Enchantment.DIG_SPEED, level, true);
|
||||
pickAxe.setItemMeta(meta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnequip(Player p, ItemStack pickAxe, int level) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockBreak(BlockBreakEvent e, int enchantLevel) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getChanceToTrigger(int enchantLevel) {
|
||||
return 100.0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
super.reload();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthor() {
|
||||
return "Drawethree";
|
||||
}
|
||||
}
|
|
@ -1,209 +0,0 @@
|
|||
package me.nvus.xprison.enchants.model.impl;
|
||||
|
||||
import dev.drawethree.ultrabackpacks.api.UltraBackpacksAPI;
|
||||
import me.nvus.xprison.enchants.XPrisonEnchants;
|
||||
import me.nvus.xprison.enchants.api.events.ExplosionTriggerEvent;
|
||||
import me.nvus.xprison.enchants.model.XPrisonEnchantment;
|
||||
import me.nvus.xprison.enchants.utils.EnchantUtils;
|
||||
import me.nvus.xprison.mines.model.mine.Mine;
|
||||
import me.nvus.xprison.multipliers.enums.MultiplierType;
|
||||
import me.nvus.xprison.utils.Constants;
|
||||
import me.nvus.xprison.utils.block.CuboidExplosionBlockProvider;
|
||||
import me.nvus.xprison.utils.block.ExplosionBlockProvider;
|
||||
import me.nvus.xprison.utils.block.SpheroidExplosionBlockProvider;
|
||||
import me.nvus.xprison.utils.compat.CompMaterial;
|
||||
import me.nvus.xprison.utils.misc.RegionUtils;
|
||||
import me.lucko.helper.Events;
|
||||
import me.lucko.helper.time.Time;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.codemc.worldguardwrapper.flag.WrappedState;
|
||||
import org.codemc.worldguardwrapper.region.IWrappedRegion;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public final class ExplosiveEnchant extends XPrisonEnchantment {
|
||||
|
||||
private double chance;
|
||||
private boolean countBlocksBroken;
|
||||
private boolean soundsEnabled;
|
||||
private boolean useEvents;
|
||||
private ExplosionBlockProvider blockProvider;
|
||||
|
||||
public ExplosiveEnchant(XPrisonEnchants instance) {
|
||||
super(instance, 9);
|
||||
this.chance = plugin.getEnchantsConfig().getYamlConfig().getDouble("enchants." + id + ".Chance");
|
||||
this.countBlocksBroken = plugin.getEnchantsConfig().getYamlConfig().getBoolean("enchants." + id + ".Count-Blocks-Broken");
|
||||
this.soundsEnabled = plugin.getEnchantsConfig().getYamlConfig().getBoolean("enchants." + id + ".Sounds");
|
||||
this.useEvents = plugin.getEnchantsConfig().getYamlConfig().getBoolean("enchants." + id + ".Use-Events");
|
||||
this.blockProvider = this.loadBlockProvider();
|
||||
}
|
||||
|
||||
private ExplosionBlockProvider loadBlockProvider() {
|
||||
String explosionType = plugin.getEnchantsConfig().getYamlConfig().getString("enchants." + id + ".Explosion-Type", "CUBE");
|
||||
|
||||
if ("CUBE".equalsIgnoreCase(explosionType)) {
|
||||
return CuboidExplosionBlockProvider.instance();
|
||||
} else if ("SPHERE".equalsIgnoreCase(explosionType)) {
|
||||
return SpheroidExplosionBlockProvider.instance();
|
||||
} else {
|
||||
return CuboidExplosionBlockProvider.instance();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthor() {
|
||||
return "Drawethree";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onEquip(Player p, ItemStack pickAxe, int level) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnequip(Player p, ItemStack pickAxe, int level) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockBreak(BlockBreakEvent e, int enchantLevel) {
|
||||
double chance = getChanceToTrigger(enchantLevel);
|
||||
|
||||
if (chance < ThreadLocalRandom.current().nextDouble(100)) {
|
||||
return;
|
||||
}
|
||||
|
||||
long timeStart = Time.nowMillis();
|
||||
final Player p = e.getPlayer();
|
||||
final Block b = e.getBlock();
|
||||
|
||||
IWrappedRegion region = RegionUtils.getRegionWithHighestPriorityAndFlag(b.getLocation(), Constants.ENCHANTS_WG_FLAG_NAME, WrappedState.ALLOW);
|
||||
|
||||
if (region == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.plugin.getCore().debug("ExplosiveEnchant::onBlockBreak >> WG Region used: " + region.getId(), this.plugin);
|
||||
int radius = this.calculateRadius(enchantLevel);
|
||||
|
||||
List<Block> blocksAffected = this.blockProvider.provide(b, radius).stream().filter(block -> region.contains(block.getLocation()) && block.getType() != Material.AIR).collect(Collectors.toList());
|
||||
|
||||
ExplosionTriggerEvent event = this.callExplosionTriggerEvent(e.getPlayer(), region, e.getBlock(), blocksAffected);
|
||||
|
||||
if (event.isCancelled() || event.getBlocksAffected().isEmpty()) {
|
||||
this.plugin.getCore().debug("ExplosiveEnchant::onBlockBreak >> ExplosiveTriggerEvent was cancelled. (Blocks affected size: " + event.getBlocksAffected().size(), this.plugin);
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.soundsEnabled) {
|
||||
b.getWorld().createExplosion(b.getLocation().getX(), b.getLocation().getY(), b.getLocation().getZ(), 0F, false, false);
|
||||
}
|
||||
|
||||
if (this.useEvents) {
|
||||
final List<BlockBreakEvent> ignored = this.plugin.getEnchantsListener().getIgnoredEvents();
|
||||
blocksAffected = event.getBlocksAffected().stream().filter(block -> {
|
||||
final BlockBreakEvent blockEvent = new BlockBreakEvent(block, p);
|
||||
ignored.add(blockEvent);
|
||||
Bukkit.getPluginManager().callEvent(blockEvent);
|
||||
ignored.remove(blockEvent);
|
||||
return !e.isCancelled();
|
||||
}).collect(Collectors.toList());
|
||||
} else {
|
||||
blocksAffected = event.getBlocksAffected();
|
||||
}
|
||||
|
||||
if (!this.plugin.getCore().isUltraBackpacksEnabled()) {
|
||||
handleAffectedBlocks(p, region, blocksAffected);
|
||||
} else {
|
||||
UltraBackpacksAPI.handleBlocksBroken(p, blocksAffected);
|
||||
}
|
||||
|
||||
if (!this.useEvents && this.plugin.isMinesModuleEnabled()) {
|
||||
Mine mine = plugin.getCore().getMines().getApi().getMineAtLocation(e.getBlock().getLocation());
|
||||
if (mine != null) {
|
||||
mine.handleBlockBreak(blocksAffected);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.countBlocksBroken) {
|
||||
plugin.getEnchantsManager().addBlocksBrokenToItem(p, blocksAffected.size());
|
||||
}
|
||||
|
||||
if (!this.useEvents) {
|
||||
plugin.getCore().getTokens().getTokensManager().handleBlockBreak(p, blocksAffected, countBlocksBroken);
|
||||
}
|
||||
|
||||
long timeEnd = Time.nowMillis();
|
||||
this.plugin.getCore().debug("ExplosiveEnchant::onBlockBreak >> Took " + (timeEnd - timeStart) + " ms.", this.plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getChanceToTrigger(int enchantLevel) {
|
||||
return chance * enchantLevel;
|
||||
}
|
||||
|
||||
private void handleAffectedBlocks(Player p, IWrappedRegion region, List<Block> blocksAffected) {
|
||||
double totalDeposit = 0.0;
|
||||
int fortuneLevel = EnchantUtils.getItemFortuneLevel(p.getItemInHand());
|
||||
boolean autoSellPlayerEnabled = this.plugin.isAutoSellModuleEnabled() && plugin.getCore().getAutoSell().getManager().hasAutoSellEnabled(p);
|
||||
|
||||
for (Block block : blocksAffected) {
|
||||
|
||||
int amplifier = fortuneLevel;
|
||||
|
||||
if (FortuneEnchant.isBlockBlacklisted(block)) {
|
||||
amplifier = 1;
|
||||
}
|
||||
|
||||
if (autoSellPlayerEnabled) {
|
||||
totalDeposit += ((plugin.getCore().getAutoSell().getManager().getPriceForBlock(region.getId(), block) + 0.0) * amplifier);
|
||||
} else {
|
||||
ItemStack itemToGive = CompMaterial.fromBlock(block).toItem(amplifier);
|
||||
p.getInventory().addItem(itemToGive);
|
||||
}
|
||||
block.setType(Material.AIR, true);
|
||||
}
|
||||
this.giveEconomyRewardToPlayer(p, totalDeposit);
|
||||
}
|
||||
|
||||
private void giveEconomyRewardToPlayer(Player p, double totalDeposit) {
|
||||
|
||||
double total = this.plugin.isMultipliersModuleEnabled() ? plugin.getCore().getMultipliers().getApi().getTotalToDeposit(p, totalDeposit, MultiplierType.SELL) : totalDeposit;
|
||||
|
||||
plugin.getCore().getEconomy().depositPlayer(p, total);
|
||||
|
||||
if (this.plugin.isAutoSellModuleEnabled()) {
|
||||
plugin.getCore().getAutoSell().getManager().addToCurrentEarnings(p, total);
|
||||
}
|
||||
}
|
||||
|
||||
private int calculateRadius(int enchantLevel) {
|
||||
int threshold = this.getMaxLevel() / 3;
|
||||
return enchantLevel <= threshold ? 3 : enchantLevel <= threshold * 2 ? 4 : 5;
|
||||
}
|
||||
|
||||
private ExplosionTriggerEvent callExplosionTriggerEvent(Player p, IWrappedRegion mineRegion, Block originBlock, List<Block> blocks) {
|
||||
ExplosionTriggerEvent event = new ExplosionTriggerEvent(p, mineRegion, originBlock, blocks);
|
||||
Events.callSync(event);
|
||||
this.plugin.getCore().debug("ExplosiveEnchant::callExplosiveTriggerEvent >> ExplosiveTriggerEvent called.", this.plugin);
|
||||
return event;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
super.reload();
|
||||
this.chance = plugin.getEnchantsConfig().getYamlConfig().getDouble("enchants." + id + ".Chance");
|
||||
this.countBlocksBroken = plugin.getEnchantsConfig().getYamlConfig().getBoolean("enchants." + id + ".Count-Blocks-Broken");
|
||||
this.soundsEnabled = plugin.getEnchantsConfig().getYamlConfig().getBoolean("enchants." + id + ".Sounds");
|
||||
this.useEvents = plugin.getEnchantsConfig().getYamlConfig().getBoolean("enchants." + id + ".Use-Events");
|
||||
this.blockProvider = this.loadBlockProvider();
|
||||
}
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
package me.nvus.xprison.enchants.model.impl;
|
||||
|
||||
import me.nvus.xprison.enchants.XPrisonEnchants;
|
||||
import me.nvus.xprison.enchants.model.XPrisonEnchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public final class FlyEnchant extends XPrisonEnchantment {
|
||||
|
||||
|
||||
|
||||
public FlyEnchant(XPrisonEnchants instance) {
|
||||
super(instance, 8);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEquip(Player p, ItemStack pickAxe, int level) {
|
||||
p.setAllowFlight(true);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnequip(Player p, ItemStack pickAxe, int level) {
|
||||
p.setAllowFlight(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockBreak(BlockBreakEvent e, int enchantLevel) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getChanceToTrigger(int enchantLevel) {
|
||||
return 100.0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
super.reload();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthor() {
|
||||
return "Drawethree";
|
||||
}
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
package me.nvus.xprison.enchants.model.impl;
|
||||
|
||||
import me.nvus.xprison.enchants.XPrisonEnchants;
|
||||
import me.nvus.xprison.enchants.model.XPrisonEnchantment;
|
||||
import me.nvus.xprison.utils.compat.CompMaterial;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public final class FortuneEnchant extends XPrisonEnchantment {
|
||||
|
||||
private static List<CompMaterial> blackListedBlocks;
|
||||
|
||||
public FortuneEnchant(XPrisonEnchants instance) {
|
||||
super(instance, 3);
|
||||
blackListedBlocks = plugin.getEnchantsConfig().getYamlConfig().getStringList("enchants." + id + ".Blacklist").stream().map(CompMaterial::fromString).filter(Objects::nonNull).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEquip(Player p, ItemStack pickAxe, int level) {
|
||||
ItemMeta meta = pickAxe.getItemMeta();
|
||||
meta.removeEnchant(Enchantment.LOOT_BONUS_BLOCKS);
|
||||
pickAxe.setItemMeta(meta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnequip(Player p, ItemStack pickAxe, int level) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockBreak(BlockBreakEvent e, int enchantLevel) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getChanceToTrigger(int enchantLevel) {
|
||||
return 100.0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
super.reload();
|
||||
blackListedBlocks = plugin.getEnchantsConfig().getYamlConfig().getStringList("enchants." + id + ".Blacklist").stream().map(CompMaterial::fromString).filter(Objects::nonNull).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthor() {
|
||||
return "Drawethree";
|
||||
}
|
||||
|
||||
public static boolean isBlockBlacklisted(Block block) {
|
||||
CompMaterial blockMaterial = CompMaterial.fromBlock(block);
|
||||
return blackListedBlocks.contains(blockMaterial);
|
||||
}
|
||||
}
|
|
@ -1,77 +0,0 @@
|
|||
package me.nvus.xprison.enchants.model.impl;
|
||||
|
||||
import me.nvus.xprison.enchants.XPrisonEnchants;
|
||||
import me.nvus.xprison.enchants.model.XPrisonEnchantment;
|
||||
import me.nvus.xprison.gangs.XPrisonGangs;
|
||||
import net.objecthunter.exp4j.Expression;
|
||||
import net.objecthunter.exp4j.ExpressionBuilder;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public final class GangValueFinderEnchant extends XPrisonEnchantment {
|
||||
|
||||
private double chance;
|
||||
private String amountToGiveExpression;
|
||||
|
||||
|
||||
public GangValueFinderEnchant(XPrisonEnchants instance) {
|
||||
super(instance, 23);
|
||||
this.amountToGiveExpression = plugin.getEnchantsConfig().getYamlConfig().getString("enchants." + id + ".Amount-To-Give");
|
||||
this.chance = plugin.getEnchantsConfig().getYamlConfig().getDouble("enchants." + id + ".Chance");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEquip(Player p, ItemStack pickAxe, int level) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnequip(Player p, ItemStack pickAxe, int level) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockBreak(BlockBreakEvent e, int enchantLevel) {
|
||||
|
||||
if (!this.plugin.getCore().isModuleEnabled(XPrisonGangs.MODULE_NAME)) {
|
||||
return;
|
||||
}
|
||||
|
||||
double chance = getChanceToTrigger(enchantLevel);
|
||||
|
||||
if (chance < ThreadLocalRandom.current().nextDouble(100)) {
|
||||
return;
|
||||
}
|
||||
|
||||
int amount = (int) createExpression(enchantLevel).evaluate();
|
||||
plugin.getCore().getGangs().getGangsManager().getPlayerGang(e.getPlayer()).ifPresent(gang -> gang.setValue(gang.getValue() + amount));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getChanceToTrigger(int enchantLevel) {
|
||||
return chance * enchantLevel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
super.reload();
|
||||
this.amountToGiveExpression = plugin.getEnchantsConfig().getYamlConfig().getString("enchants." + id + ".Amount-To-Give");
|
||||
this.chance = plugin.getEnchantsConfig().getYamlConfig().getDouble("enchants." + id + ".Chance");
|
||||
}
|
||||
|
||||
private Expression createExpression(int level) {
|
||||
return new ExpressionBuilder(this.amountToGiveExpression)
|
||||
.variables("level")
|
||||
.build()
|
||||
.setVariable("level", level);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthor() {
|
||||
return "Drawethree";
|
||||
}
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
package me.nvus.xprison.enchants.model.impl;
|
||||
|
||||
import me.nvus.xprison.api.enums.ReceiveCause;
|
||||
import me.nvus.xprison.enchants.XPrisonEnchants;
|
||||
import me.nvus.xprison.enchants.model.XPrisonEnchantment;
|
||||
import me.nvus.xprison.gems.XPrisonGems;
|
||||
import net.objecthunter.exp4j.Expression;
|
||||
import net.objecthunter.exp4j.ExpressionBuilder;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public final class GemFinderEnchant extends XPrisonEnchantment {
|
||||
|
||||
private double chance;
|
||||
private String amountToGiveExpression;
|
||||
|
||||
public GemFinderEnchant(XPrisonEnchants instance) {
|
||||
super(instance, 22);
|
||||
this.chance = plugin.getEnchantsConfig().getYamlConfig().getDouble("enchants." + id + ".Chance");
|
||||
this.amountToGiveExpression = plugin.getEnchantsConfig().getYamlConfig().getString("enchants." + id + ".Amount-To-Give");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEquip(Player p, ItemStack pickAxe, int level) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnequip(Player p, ItemStack pickAxe, int level) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockBreak(BlockBreakEvent e, int enchantLevel) {
|
||||
|
||||
if (!this.plugin.getCore().isModuleEnabled(XPrisonGems.MODULE_NAME)) {
|
||||
return;
|
||||
}
|
||||
|
||||
double chance = getChanceToTrigger(enchantLevel);
|
||||
|
||||
if (chance < ThreadLocalRandom.current().nextDouble(100)) {
|
||||
return;
|
||||
}
|
||||
|
||||
long amount = (long) createExpression(enchantLevel).evaluate();
|
||||
plugin.getCore().getGems().getGemsManager().giveGems(e.getPlayer(), amount, null, ReceiveCause.MINING);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getChanceToTrigger(int enchantLevel) {
|
||||
return chance * enchantLevel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
super.reload();
|
||||
this.amountToGiveExpression = plugin.getEnchantsConfig().getYamlConfig().getString("enchants." + id + ".Amount-To-Give");
|
||||
this.chance = plugin.getEnchantsConfig().getYamlConfig().getDouble("enchants." + id + ".Chance");
|
||||
}
|
||||
|
||||
private Expression createExpression(int level) {
|
||||
return new ExpressionBuilder(this.amountToGiveExpression)
|
||||
.variables("level")
|
||||
.build()
|
||||
.setVariable("level", level);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthor() {
|
||||
return "Drawethree";
|
||||
}
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
package me.nvus.xprison.enchants.model.impl;
|
||||
|
||||
import me.nvus.xprison.enchants.XPrisonEnchants;
|
||||
import me.nvus.xprison.enchants.model.XPrisonEnchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
public final class HasteEnchant extends XPrisonEnchantment {
|
||||
|
||||
public HasteEnchant(XPrisonEnchants instance) {
|
||||
super(instance, 4);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEquip(Player p, ItemStack pickAxe, int level) {
|
||||
if (level == 0) {
|
||||
this.onUnequip(p, pickAxe, level);
|
||||
return;
|
||||
}
|
||||
p.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, Integer.MAX_VALUE, level - 1, true, true), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnequip(Player p, ItemStack pickAxe, int level) {
|
||||
p.removePotionEffect(PotionEffectType.FAST_DIGGING);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockBreak(BlockBreakEvent e, int enchantLevel) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getChanceToTrigger(int enchantLevel) {
|
||||
return 100.0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
super.reload();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthor() {
|
||||
return "Drawethree";
|
||||
}
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
package me.nvus.xprison.enchants.model.impl;
|
||||
|
||||
import me.nvus.xprison.enchants.XPrisonEnchants;
|
||||
import me.nvus.xprison.enchants.model.XPrisonEnchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
public final class JumpBoostEnchant extends XPrisonEnchantment {
|
||||
public JumpBoostEnchant(XPrisonEnchants instance) {
|
||||
super(instance, 6);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEquip(Player p, ItemStack pickAxe, int level) {
|
||||
if (level == 0) {
|
||||
this.onUnequip(p, pickAxe, level);
|
||||
return;
|
||||
}
|
||||
p.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, Integer.MAX_VALUE, level - 1, true, true), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnequip(Player p, ItemStack pickAxe, int level) {
|
||||
p.removePotionEffect(PotionEffectType.JUMP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockBreak(BlockBreakEvent e, int enchantLevel) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getChanceToTrigger(int enchantLevel) {
|
||||
return 100.0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
super.reload();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthor() {
|
||||
return "Drawethree";
|
||||
}
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
package me.nvus.xprison.enchants.model.impl;
|
||||
|
||||
import me.nvus.xprison.enchants.XPrisonEnchants;
|
||||
import me.nvus.xprison.enchants.model.XPrisonEnchantment;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public final class KeyFinderEnchant extends XPrisonEnchantment {
|
||||
|
||||
private double chance;
|
||||
private List<String> commandsToExecute;
|
||||
|
||||
public KeyFinderEnchant(XPrisonEnchants instance) {
|
||||
super(instance, 15);
|
||||
this.chance = plugin.getEnchantsConfig().getYamlConfig().getDouble("enchants." + id + ".Chance");
|
||||
this.commandsToExecute = plugin.getEnchantsConfig().getYamlConfig().getStringList("enchants." + id + ".Commands");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEquip(Player p, ItemStack pickAxe, int level) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnequip(Player p, ItemStack pickAxe, int level) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockBreak(BlockBreakEvent e, int enchantLevel) {
|
||||
double chance = getChanceToTrigger(enchantLevel);
|
||||
|
||||
if (chance < ThreadLocalRandom.current().nextDouble(100)) {
|
||||
return;
|
||||
}
|
||||
|
||||
String randomCmd = this.getRandomCommandToExecute();
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), randomCmd.replace("%player%", e.getPlayer().getName()));
|
||||
}
|
||||
|
||||
|
||||
private String getRandomCommandToExecute() {
|
||||
return this.commandsToExecute.get(ThreadLocalRandom.current().nextInt(commandsToExecute.size()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getChanceToTrigger(int enchantLevel) {
|
||||
return this.chance * enchantLevel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
super.reload();
|
||||
this.chance = plugin.getEnchantsConfig().getYamlConfig().getDouble("enchants." + id + ".Chance");
|
||||
this.commandsToExecute = plugin.getEnchantsConfig().getYamlConfig().getStringList("enchants." + id + ".Commands");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthor() {
|
||||
return "Drawethree";
|
||||
}
|
||||
}
|
|
@ -1,66 +0,0 @@
|
|||
package me.nvus.xprison.enchants.model.impl;
|
||||
|
||||
import me.nvus.xprison.enchants.XPrisonEnchants;
|
||||
import me.nvus.xprison.enchants.model.XPrisonEnchantment;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public final class KeyallsEnchant extends XPrisonEnchantment {
|
||||
|
||||
private double chance;
|
||||
private List<String> commandsToExecute;
|
||||
|
||||
public KeyallsEnchant(XPrisonEnchants instance) {
|
||||
super(instance, 18);
|
||||
this.chance = plugin.getEnchantsConfig().getYamlConfig().getDouble("enchants." + id + ".Chance");
|
||||
this.commandsToExecute = plugin.getEnchantsConfig().getYamlConfig().getStringList("enchants." + id + ".Commands");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEquip(Player p, ItemStack pickAxe, int level) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnequip(Player p, ItemStack pickAxe, int level) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockBreak(BlockBreakEvent e, int enchantLevel) {
|
||||
double chance = getChanceToTrigger(enchantLevel);
|
||||
|
||||
if (chance < ThreadLocalRandom.current().nextDouble(100)) {
|
||||
return;
|
||||
}
|
||||
|
||||
String randomCmd = getRandomCommandToExecute();
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), randomCmd.replace("%player%", e.getPlayer().getName()));
|
||||
}
|
||||
|
||||
private String getRandomCommandToExecute() {
|
||||
return this.commandsToExecute.get(ThreadLocalRandom.current().nextInt(commandsToExecute.size()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getChanceToTrigger(int enchantLevel) {
|
||||
return chance * enchantLevel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
super.reload();
|
||||
this.chance = plugin.getEnchantsConfig().getYamlConfig().getDouble("enchants." + id + ".Chance");
|
||||
this.commandsToExecute = plugin.getEnchantsConfig().getYamlConfig().getStringList("enchants." + id + ".Commands");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthor() {
|
||||
return "Drawethree";
|
||||
}
|
||||
}
|
|
@ -1,193 +0,0 @@
|
|||
package me.nvus.xprison.enchants.model.impl;
|
||||
|
||||
import dev.drawethree.ultrabackpacks.api.UltraBackpacksAPI;
|
||||
import me.nvus.xprison.enchants.XPrisonEnchants;
|
||||
import me.nvus.xprison.enchants.api.events.LayerTriggerEvent;
|
||||
import me.nvus.xprison.enchants.model.XPrisonEnchantment;
|
||||
import me.nvus.xprison.enchants.utils.EnchantUtils;
|
||||
import me.nvus.xprison.mines.model.mine.Mine;
|
||||
import me.nvus.xprison.multipliers.enums.MultiplierType;
|
||||
import me.nvus.xprison.utils.Constants;
|
||||
import me.nvus.xprison.utils.compat.CompMaterial;
|
||||
import me.nvus.xprison.utils.misc.RegionUtils;
|
||||
import me.lucko.helper.Events;
|
||||
import me.lucko.helper.time.Time;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.codemc.worldguardwrapper.flag.WrappedState;
|
||||
import org.codemc.worldguardwrapper.region.IWrappedRegion;
|
||||
import org.codemc.worldguardwrapper.selection.ICuboidSelection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public final class LayerEnchant extends XPrisonEnchantment {
|
||||
|
||||
private double chance;
|
||||
private boolean countBlocksBroken;
|
||||
private boolean useEvents;
|
||||
|
||||
public LayerEnchant(XPrisonEnchants instance) {
|
||||
super(instance, 10);
|
||||
this.chance = plugin.getEnchantsConfig().getYamlConfig().getDouble("enchants." + id + ".Chance");
|
||||
this.countBlocksBroken = plugin.getEnchantsConfig().getYamlConfig().getBoolean("enchants." + id + ".Count-Blocks-Broken");
|
||||
this.useEvents = plugin.getEnchantsConfig().getYamlConfig().getBoolean("enchants." + id + ".Use-Events");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEquip(Player p, ItemStack pickAxe, int level) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnequip(Player p, ItemStack pickAxe, int level) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockBreak(BlockBreakEvent e, int enchantLevel) {
|
||||
double chance = getChanceToTrigger(enchantLevel);
|
||||
|
||||
if (chance < ThreadLocalRandom.current().nextDouble(100)) {
|
||||
return;
|
||||
}
|
||||
|
||||
long startTime = Time.nowMillis();
|
||||
final Player p = e.getPlayer();
|
||||
final Block b = e.getBlock();
|
||||
|
||||
IWrappedRegion region = RegionUtils.getRegionWithHighestPriorityAndFlag(b.getLocation(), Constants.ENCHANTS_WG_FLAG_NAME, WrappedState.ALLOW);
|
||||
|
||||
if (region == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.plugin.getCore().debug("LayerEnchant::onBlockBreak >> WG Region used: " + region.getId(), this.plugin);
|
||||
List<Block> blocksAffected = this.getAffectedBlocks(b, region);
|
||||
|
||||
LayerTriggerEvent event = this.callLayerTriggerEvent(e.getPlayer(), region, e.getBlock(), blocksAffected);
|
||||
|
||||
if (event.isCancelled() || event.getBlocksAffected().isEmpty()) {
|
||||
this.plugin.getCore().debug("LayerEnchant::onBlockBreak >> LayerTriggerEvent was cancelled. (Blocks affected size: " + event.getBlocksAffected().size(), this.plugin);
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.useEvents) {
|
||||
final List<BlockBreakEvent> ignored = this.plugin.getEnchantsListener().getIgnoredEvents();
|
||||
blocksAffected = event.getBlocksAffected().stream().filter(block -> {
|
||||
final BlockBreakEvent blockEvent = new BlockBreakEvent(block, p);
|
||||
ignored.add(blockEvent);
|
||||
Bukkit.getPluginManager().callEvent(blockEvent);
|
||||
ignored.remove(blockEvent);
|
||||
return !e.isCancelled();
|
||||
}).collect(Collectors.toList());
|
||||
} else {
|
||||
blocksAffected = event.getBlocksAffected();
|
||||
}
|
||||
|
||||
if (!this.plugin.getCore().isUltraBackpacksEnabled()) {
|
||||
handleAffectedBlocks(p, region, blocksAffected);
|
||||
} else {
|
||||
UltraBackpacksAPI.handleBlocksBroken(p, blocksAffected);
|
||||
}
|
||||
|
||||
if (!this.useEvents && this.plugin.isMinesModuleEnabled()) {
|
||||
Mine mine = plugin.getCore().getMines().getApi().getMineAtLocation(e.getBlock().getLocation());
|
||||
if (mine != null) {
|
||||
mine.handleBlockBreak(blocksAffected);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.countBlocksBroken) {
|
||||
plugin.getEnchantsManager().addBlocksBrokenToItem(p, blocksAffected.size());
|
||||
}
|
||||
|
||||
if (!this.useEvents) {
|
||||
plugin.getCore().getTokens().getTokensManager().handleBlockBreak(p, blocksAffected, countBlocksBroken);
|
||||
}
|
||||
|
||||
long timeEnd = Time.nowMillis();
|
||||
this.plugin.getCore().debug("LayerEnchant::onBlockBreak >> Took " + (timeEnd - startTime) + " ms.", this.plugin);
|
||||
}
|
||||
|
||||
private List<Block> getAffectedBlocks(Block startBlock, IWrappedRegion region) {
|
||||
List<Block> blocksAffected = new ArrayList<>();
|
||||
ICuboidSelection selection = (ICuboidSelection) region.getSelection();
|
||||
for (int x = selection.getMinimumPoint().getBlockX(); x <= selection.getMaximumPoint().getBlockX(); x++) {
|
||||
for (int z = selection.getMinimumPoint().getBlockZ(); z <= selection.getMaximumPoint().getBlockZ(); z++) {
|
||||
Block b1 = startBlock.getWorld().getBlockAt(x, startBlock.getY(), z);
|
||||
if (b1.getType() == Material.AIR) {
|
||||
continue;
|
||||
}
|
||||
blocksAffected.add(b1);
|
||||
}
|
||||
}
|
||||
return blocksAffected;
|
||||
}
|
||||
|
||||
private void handleAffectedBlocks(Player p, IWrappedRegion region, List<Block> blocksAffected) {
|
||||
double totalDeposit = 0.0;
|
||||
int fortuneLevel = EnchantUtils.getItemFortuneLevel(p.getItemInHand());
|
||||
boolean autoSellPlayerEnabled = this.plugin.isAutoSellModuleEnabled() && plugin.getCore().getAutoSell().getManager().hasAutoSellEnabled(p);
|
||||
|
||||
for (Block block : blocksAffected) {
|
||||
|
||||
int amplifier = fortuneLevel;
|
||||
if (FortuneEnchant.isBlockBlacklisted(block)) {
|
||||
amplifier = 1;
|
||||
}
|
||||
|
||||
if (autoSellPlayerEnabled) {
|
||||
totalDeposit += ((plugin.getCore().getAutoSell().getManager().getPriceForBlock(region.getId(), block) + 0.0) * amplifier);
|
||||
} else {
|
||||
ItemStack itemToGive = CompMaterial.fromBlock(block).toItem(amplifier);
|
||||
p.getInventory().addItem(itemToGive);
|
||||
}
|
||||
block.setType(Material.AIR, true);
|
||||
}
|
||||
this.giveEconomyRewardToPlayer(p, totalDeposit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getChanceToTrigger(int enchantLevel) {
|
||||
return chance * enchantLevel;
|
||||
}
|
||||
|
||||
private void giveEconomyRewardToPlayer(Player p, double totalDeposit) {
|
||||
double total = this.plugin.isMultipliersModuleEnabled() ? plugin.getCore().getMultipliers().getApi().getTotalToDeposit(p, totalDeposit, MultiplierType.SELL) : totalDeposit;
|
||||
|
||||
plugin.getCore().getEconomy().depositPlayer(p, total);
|
||||
|
||||
if (plugin.isAutoSellModuleEnabled()) {
|
||||
plugin.getCore().getAutoSell().getManager().addToCurrentEarnings(p, total);
|
||||
}
|
||||
}
|
||||
|
||||
private LayerTriggerEvent callLayerTriggerEvent(Player player, IWrappedRegion region, Block originBlock, List<Block> blocksAffected) {
|
||||
LayerTriggerEvent event = new LayerTriggerEvent(player, region, originBlock, blocksAffected);
|
||||
Events.callSync(event);
|
||||
this.plugin.getCore().debug("LayerEnchant::callLayerTriggerEvent >> LayerTriggerEvent called.", this.plugin);
|
||||
return event;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
super.reload();
|
||||
this.chance = plugin.getEnchantsConfig().getYamlConfig().getDouble("enchants." + id + ".Chance");
|
||||
this.countBlocksBroken = plugin.getEnchantsConfig().getYamlConfig().getBoolean("enchants." + id + ".Count-Blocks-Broken");
|
||||
this.useEvents = plugin.getEnchantsConfig().getYamlConfig().getBoolean("enchants." + id + ".Use-Events");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthor() {
|
||||
return "Drawethree";
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
package me.nvus.xprison.enchants.model.impl;
|
||||
|
||||
import me.nvus.xprison.enchants.XPrisonEnchants;
|
||||
import me.nvus.xprison.enchants.model.XPrisonEnchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
public final class NightVisionEnchant extends XPrisonEnchantment {
|
||||
public NightVisionEnchant(XPrisonEnchants instance) {
|
||||
super(instance, 7);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEquip(Player p, ItemStack pickAxe, int level) {
|
||||
if (level == 0) {
|
||||
this.onUnequip(p, pickAxe, level);
|
||||
return;
|
||||
}
|
||||
p.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, Integer.MAX_VALUE, level - 1, true, true), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnequip(Player p, ItemStack pickAxe, int level) {
|
||||
p.removePotionEffect(PotionEffectType.NIGHT_VISION);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockBreak(BlockBreakEvent e, int enchantLevel) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getChanceToTrigger(int enchantLevel) {
|
||||
return 100.0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
super.reload();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthor() {
|
||||
return "Drawethree";
|
||||
}
|
||||
}
|
|
@ -1,213 +0,0 @@
|
|||
package me.nvus.xprison.enchants.model.impl;
|
||||
|
||||
import dev.drawethree.ultrabackpacks.api.UltraBackpacksAPI;
|
||||
import me.nvus.xprison.enchants.XPrisonEnchants;
|
||||
import me.nvus.xprison.enchants.api.events.NukeTriggerEvent;
|
||||
import me.nvus.xprison.enchants.model.XPrisonEnchantment;
|
||||
import me.nvus.xprison.enchants.utils.EnchantUtils;
|
||||
import me.nvus.xprison.mines.model.mine.Mine;
|
||||
import me.nvus.xprison.multipliers.enums.MultiplierType;
|
||||
import me.nvus.xprison.utils.Constants;
|
||||
import me.nvus.xprison.utils.compat.CompMaterial;
|
||||
import me.nvus.xprison.utils.misc.MathUtils;
|
||||
import me.nvus.xprison.utils.misc.RegionUtils;
|
||||
import me.nvus.xprison.utils.player.PlayerUtils;
|
||||
import me.nvus.xprison.utils.text.TextUtils;
|
||||
import me.lucko.helper.Events;
|
||||
import me.lucko.helper.time.Time;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.codemc.worldguardwrapper.flag.WrappedState;
|
||||
import org.codemc.worldguardwrapper.region.IWrappedRegion;
|
||||
import org.codemc.worldguardwrapper.selection.ICuboidSelection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public final class NukeEnchant extends XPrisonEnchantment {
|
||||
|
||||
private double chance;
|
||||
private boolean countBlocksBroken;
|
||||
private boolean removeBlocks;
|
||||
private boolean useEvents;
|
||||
private String message;
|
||||
|
||||
public NukeEnchant(XPrisonEnchants instance) {
|
||||
super(instance, 21);
|
||||
this.chance = plugin.getEnchantsConfig().getYamlConfig().getDouble("enchants." + id + ".Chance");
|
||||
this.countBlocksBroken = plugin.getEnchantsConfig().getYamlConfig().getBoolean("enchants." + id + ".Count-Blocks-Broken");
|
||||
this.removeBlocks = plugin.getEnchantsConfig().getYamlConfig().getBoolean("enchants." + id + ".Remove-Blocks");
|
||||
this.useEvents = plugin.getEnchantsConfig().getYamlConfig().getBoolean("enchants." + id + ".Use-Events");
|
||||
this.message = TextUtils.applyColor(plugin.getEnchantsConfig().getYamlConfig().getString("enchants." + id + ".Message"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEquip(Player p, ItemStack pickAxe, int level) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnequip(Player p, ItemStack pickAxe, int level) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockBreak(BlockBreakEvent e, int enchantLevel) {
|
||||
double chance = getChanceToTrigger(enchantLevel);
|
||||
|
||||
if (chance < ThreadLocalRandom.current().nextDouble(100)) {
|
||||
return;
|
||||
}
|
||||
|
||||
long startTime = Time.nowMillis();
|
||||
final Player p = e.getPlayer();
|
||||
final Block b = e.getBlock();
|
||||
|
||||
IWrappedRegion region = RegionUtils.getRegionWithHighestPriorityAndFlag(b.getLocation(), Constants.ENCHANTS_WG_FLAG_NAME, WrappedState.ALLOW);
|
||||
|
||||
if (region == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.plugin.getCore().debug("NukeEnchant::onBlockBreak >> WG Region used: " + region.getId(), this.plugin);
|
||||
List<Block> blocksAffected = this.getAffectedBlocks(b, region);
|
||||
|
||||
NukeTriggerEvent event = this.callNukeTriggerEvent(e.getPlayer(), region, e.getBlock(), blocksAffected);
|
||||
|
||||
if (event.isCancelled() || event.getBlocksAffected().isEmpty()) {
|
||||
this.plugin.getCore().debug("NukeEnchant::onBlockBreak >> NukeTriggerEvent was cancelled. (Blocks affected size: " + event.getBlocksAffected().size(), this.plugin);
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.useEvents) {
|
||||
final List<BlockBreakEvent> ignored = this.plugin.getEnchantsListener().getIgnoredEvents();
|
||||
blocksAffected = event.getBlocksAffected().stream().filter(block -> {
|
||||
final BlockBreakEvent blockEvent = new BlockBreakEvent(block, p);
|
||||
ignored.add(blockEvent);
|
||||
Bukkit.getPluginManager().callEvent(blockEvent);
|
||||
ignored.remove(blockEvent);
|
||||
return !e.isCancelled();
|
||||
}).collect(Collectors.toList());
|
||||
} else {
|
||||
blocksAffected = event.getBlocksAffected();
|
||||
}
|
||||
|
||||
if (!this.plugin.getCore().isUltraBackpacksEnabled()) {
|
||||
handleAffectedBlocks(p, region, blocksAffected);
|
||||
} else {
|
||||
UltraBackpacksAPI.handleBlocksBroken(p, blocksAffected);
|
||||
}
|
||||
|
||||
if (!this.useEvents && this.plugin.isMinesModuleEnabled() && removeBlocks) {
|
||||
Mine mine = plugin.getCore().getMines().getApi().getMineAtLocation(e.getBlock().getLocation());
|
||||
|
||||
if (mine != null) {
|
||||
mine.handleBlockBreak(blocksAffected);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.countBlocksBroken) {
|
||||
plugin.getEnchantsManager().addBlocksBrokenToItem(p, blocksAffected.size());
|
||||
}
|
||||
|
||||
if (!this.useEvents) {
|
||||
plugin.getCore().getTokens().getTokensManager().handleBlockBreak(p, blocksAffected, countBlocksBroken);
|
||||
}
|
||||
|
||||
long timeEnd = Time.nowMillis();
|
||||
this.plugin.getCore().debug("NukeEnchant::onBlockBreak >> Took " + (timeEnd - startTime) + " ms.", this.plugin);
|
||||
}
|
||||
|
||||
private void handleAffectedBlocks(Player p, IWrappedRegion region, List<Block> blocksAffected) {
|
||||
double totalDeposit = 0.0;
|
||||
int fortuneLevel = EnchantUtils.getItemFortuneLevel(p.getItemInHand());
|
||||
boolean autoSellPlayerEnabled = this.plugin.isAutoSellModuleEnabled() && plugin.getCore().getAutoSell().getManager().hasAutoSellEnabled(p);
|
||||
|
||||
for (Block block : blocksAffected) {
|
||||
|
||||
int amplifier = fortuneLevel;
|
||||
|
||||
if (FortuneEnchant.isBlockBlacklisted(block)) {
|
||||
amplifier = 1;
|
||||
}
|
||||
|
||||
if (autoSellPlayerEnabled) {
|
||||
totalDeposit += ((plugin.getCore().getAutoSell().getManager().getPriceForBlock(region.getId(), block) + 0.0) * amplifier);
|
||||
} else {
|
||||
ItemStack itemToGive = CompMaterial.fromBlock(block).toItem(amplifier);
|
||||
p.getInventory().addItem(itemToGive);
|
||||
}
|
||||
|
||||
if (this.removeBlocks) {
|
||||
block.setType(Material.AIR, true);
|
||||
}
|
||||
|
||||
}
|
||||
this.giveEconomyRewardsToPlayer(p, totalDeposit);
|
||||
}
|
||||
|
||||
private List<Block> getAffectedBlocks(Block b, IWrappedRegion region) {
|
||||
List<Block> blocksAffected = new ArrayList<>();
|
||||
ICuboidSelection selection = (ICuboidSelection) region.getSelection();
|
||||
for (int x = selection.getMinimumPoint().getBlockX(); x <= selection.getMaximumPoint().getBlockX(); x++) {
|
||||
for (int z = selection.getMinimumPoint().getBlockZ(); z <= selection.getMaximumPoint().getBlockZ(); z++) {
|
||||
for (int y = selection.getMinimumPoint().getBlockY(); y <= selection.getMaximumPoint().getBlockY(); y++) {
|
||||
Block b1 = b.getWorld().getBlockAt(x, y, z);
|
||||
if (b1.getType() == Material.AIR) {
|
||||
continue;
|
||||
}
|
||||
blocksAffected.add(b1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return blocksAffected;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getChanceToTrigger(int enchantLevel) {
|
||||
return chance * enchantLevel;
|
||||
}
|
||||
|
||||
private void giveEconomyRewardsToPlayer(Player p, double totalDeposit) {
|
||||
double total = this.plugin.isMultipliersModuleEnabled() ? plugin.getCore().getMultipliers().getApi().getTotalToDeposit(p, totalDeposit, MultiplierType.SELL) : totalDeposit;
|
||||
|
||||
plugin.getCore().getEconomy().depositPlayer(p, total);
|
||||
|
||||
if (plugin.isAutoSellModuleEnabled()) {
|
||||
plugin.getCore().getAutoSell().getManager().addToCurrentEarnings(p, total);
|
||||
}
|
||||
|
||||
if (message != null || !message.isEmpty()) {
|
||||
PlayerUtils.sendMessage(p,message.replace("%money%", MathUtils.formatNumber(total)));
|
||||
}
|
||||
}
|
||||
|
||||
private NukeTriggerEvent callNukeTriggerEvent(Player p, IWrappedRegion region, Block startBlock, List<Block> affectedBlocks) {
|
||||
NukeTriggerEvent event = new NukeTriggerEvent(p, region, startBlock, affectedBlocks);
|
||||
Events.callSync(event);
|
||||
this.plugin.getCore().debug("NukeEnchant::callNukeTriggerEvent >> NukeTriggerEvent called.", this.plugin);
|
||||
return event;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
super.reload();
|
||||
this.chance = plugin.getEnchantsConfig().getYamlConfig().getDouble("enchants." + id + ".Chance");
|
||||
this.countBlocksBroken = plugin.getEnchantsConfig().getYamlConfig().getBoolean("enchants." + id + ".Count-Blocks-Broken");
|
||||
this.removeBlocks = plugin.getEnchantsConfig().getYamlConfig().getBoolean("enchants." + id + ".Remove-Blocks");
|
||||
this.useEvents = plugin.getEnchantsConfig().getYamlConfig().getBoolean("enchants." + id + ".Use-Events");
|
||||
this.message = TextUtils.applyColor(plugin.getEnchantsConfig().getYamlConfig().getString("enchants." + id + ".Message"));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthor() {
|
||||
return "Drawethree";
|
||||
}
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
package me.nvus.xprison.enchants.model.impl;
|
||||
|
||||
import me.nvus.xprison.enchants.XPrisonEnchants;
|
||||
import me.nvus.xprison.enchants.model.XPrisonEnchantment;
|
||||
import net.objecthunter.exp4j.Expression;
|
||||
import net.objecthunter.exp4j.ExpressionBuilder;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public final class PrestigeFinderEnchant extends XPrisonEnchantment {
|
||||
|
||||
private double chance;
|
||||
private String commandToExecute;
|
||||
private String amountToGiveExpression;
|
||||
|
||||
public PrestigeFinderEnchant(XPrisonEnchants instance) {
|
||||
super(instance, 16);
|
||||
this.chance = plugin.getEnchantsConfig().getYamlConfig().getDouble("enchants." + id + ".Chance");
|
||||
this.commandToExecute = plugin.getEnchantsConfig().getYamlConfig().getString("enchants." + id + ".Command");
|
||||
this.amountToGiveExpression = plugin.getEnchantsConfig().getYamlConfig().getString("enchants." + id + ".Amount-To-Give");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEquip(Player p, ItemStack pickAxe, int level) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnequip(Player p, ItemStack pickAxe, int level) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockBreak(BlockBreakEvent e, int enchantLevel) {
|
||||
double chance = getChanceToTrigger(enchantLevel);
|
||||
if (chance < ThreadLocalRandom.current().nextDouble(100)) {
|
||||
return;
|
||||
}
|
||||
int levels = (int) createExpression(enchantLevel).evaluate();
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), commandToExecute.replace("%player%", e.getPlayer().getName()).replace("%amount%", String.valueOf(levels)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getChanceToTrigger(int enchantLevel) {
|
||||
return chance * enchantLevel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
super.reload();
|
||||
this.chance = plugin.getEnchantsConfig().getYamlConfig().getDouble("enchants." + id + ".Chance");
|
||||
this.commandToExecute = plugin.getEnchantsConfig().getYamlConfig().getString("enchants." + id + ".Command");
|
||||
this.amountToGiveExpression = plugin.getEnchantsConfig().getYamlConfig().getString("enchants." + id + ".Amount-To-Give");
|
||||
}
|
||||
|
||||
private Expression createExpression(int level) {
|
||||
return new ExpressionBuilder(this.amountToGiveExpression)
|
||||
.variables("level")
|
||||
.build()
|
||||
.setVariable("level", level);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthor() {
|
||||
return "Drawethree";
|
||||
}
|
||||
}
|
|
@ -1,75 +0,0 @@
|
|||
package me.nvus.xprison.enchants.model.impl;
|
||||
|
||||
import me.nvus.xprison.enchants.XPrisonEnchants;
|
||||
import me.nvus.xprison.enchants.model.XPrisonEnchantment;
|
||||
import net.objecthunter.exp4j.Expression;
|
||||
import net.objecthunter.exp4j.ExpressionBuilder;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public final class SalaryEnchant extends XPrisonEnchantment {
|
||||
|
||||
private double chance;
|
||||
private String amountToGiveExpression;
|
||||
|
||||
public SalaryEnchant(XPrisonEnchants instance) {
|
||||
super(instance, 12);
|
||||
this.chance = plugin.getEnchantsConfig().getYamlConfig().getDouble("enchants." + id + ".Chance");
|
||||
this.amountToGiveExpression = plugin.getEnchantsConfig().getYamlConfig().getString("enchants." + id + ".Amount-To-Give");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEquip(Player p, ItemStack pickAxe, int level) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnequip(Player p, ItemStack pickAxe, int level) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockBreak(BlockBreakEvent e, int enchantLevel) {
|
||||
double chance = getChanceToTrigger(enchantLevel);
|
||||
|
||||
if (chance < ThreadLocalRandom.current().nextDouble(100)) {
|
||||
return;
|
||||
}
|
||||
|
||||
double randAmount = createExpression(enchantLevel).evaluate();
|
||||
|
||||
plugin.getCore().getEconomy().depositPlayer(e.getPlayer(), randAmount);
|
||||
|
||||
if (this.plugin.isAutoSellModuleEnabled()) {
|
||||
plugin.getCore().getAutoSell().getManager().addToCurrentEarnings(e.getPlayer(), randAmount);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getChanceToTrigger(int enchantLevel) {
|
||||
return this.chance * enchantLevel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
super.reload();
|
||||
this.chance = plugin.getEnchantsConfig().getYamlConfig().getDouble("enchants." + id + ".Chance");
|
||||
this.amountToGiveExpression = plugin.getEnchantsConfig().getYamlConfig().getString("enchants." + id + ".Amount-To-Give");
|
||||
}
|
||||
|
||||
private Expression createExpression(int level) {
|
||||
return new ExpressionBuilder(this.amountToGiveExpression)
|
||||
.variables("level")
|
||||
.build()
|
||||
.setVariable("level", level);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthor() {
|
||||
return "Drawethree";
|
||||
}
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
package me.nvus.xprison.enchants.model.impl;
|
||||
|
||||
import me.nvus.xprison.enchants.XPrisonEnchants;
|
||||
import me.nvus.xprison.enchants.model.XPrisonEnchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
public final class SpeedEnchant extends XPrisonEnchantment {
|
||||
public SpeedEnchant(XPrisonEnchants instance) {
|
||||
super(instance, 5);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEquip(Player p, ItemStack pickAxe, int level) {
|
||||
if (level == 0) {
|
||||
this.onUnequip(p, pickAxe, level);
|
||||
return;
|
||||
}
|
||||
p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, level - 1, true, true), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnequip(Player p, ItemStack pickAxe, int level) {
|
||||
p.removePotionEffect(PotionEffectType.SPEED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockBreak(BlockBreakEvent e, int enchantLevel) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getChanceToTrigger(int enchantLevel) {
|
||||
return 100.0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
super.reload();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthor() {
|
||||
return "Drawethree";
|
||||
}
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
package me.nvus.xprison.enchants.model.impl;
|
||||
|
||||
import me.nvus.xprison.api.enums.ReceiveCause;
|
||||
import me.nvus.xprison.enchants.XPrisonEnchants;
|
||||
import me.nvus.xprison.enchants.model.XPrisonEnchantment;
|
||||
import me.nvus.xprison.tokens.XPrisonTokens;
|
||||
import net.objecthunter.exp4j.Expression;
|
||||
import net.objecthunter.exp4j.ExpressionBuilder;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public final class TokenatorEnchant extends XPrisonEnchantment {
|
||||
|
||||
private double chance;
|
||||
private String amountToGiveExpression;
|
||||
|
||||
|
||||
public TokenatorEnchant(XPrisonEnchants instance) {
|
||||
super(instance, 14);
|
||||
this.chance = plugin.getEnchantsConfig().getYamlConfig().getDouble("enchants." + id + ".Chance");
|
||||
this.amountToGiveExpression = plugin.getEnchantsConfig().getYamlConfig().getString("enchants." + id + ".Amount-To-Give");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEquip(Player p, ItemStack pickAxe, int level) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnequip(Player p, ItemStack pickAxe, int level) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockBreak(BlockBreakEvent e, int enchantLevel) {
|
||||
if (!this.plugin.getCore().isModuleEnabled(XPrisonTokens.MODULE_NAME)) {
|
||||
return;
|
||||
}
|
||||
|
||||
double chance = getChanceToTrigger(enchantLevel);
|
||||
|
||||
if (chance < ThreadLocalRandom.current().nextDouble(100)) {
|
||||
return;
|
||||
}
|
||||
|
||||
long randAmount = (long) createExpression(enchantLevel).evaluate();
|
||||
plugin.getCore().getTokens().getTokensManager().giveTokens(e.getPlayer(), randAmount, null, ReceiveCause.MINING);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getChanceToTrigger(int enchantLevel) {
|
||||
return chance * enchantLevel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
super.reload();
|
||||
this.chance = plugin.getEnchantsConfig().getYamlConfig().getDouble("enchants." + id + ".Chance");
|
||||
this.amountToGiveExpression = plugin.getEnchantsConfig().getYamlConfig().getString("enchants." + id + ".Amount-To-Give");
|
||||
}
|
||||
|
||||
private Expression createExpression(int level) {
|
||||
return new ExpressionBuilder(this.amountToGiveExpression)
|
||||
.variables("level")
|
||||
.build()
|
||||
.setVariable("level", level);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthor() {
|
||||
return "Drawethree";
|
||||
}
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
package me.nvus.xprison.enchants.model.impl;
|
||||
|
||||
import me.nvus.xprison.enchants.XPrisonEnchants;
|
||||
import me.nvus.xprison.enchants.model.XPrisonEnchantment;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
public final class UnbreakingEnchant extends XPrisonEnchantment {
|
||||
|
||||
public UnbreakingEnchant(XPrisonEnchants instance) {
|
||||
super(instance, 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEquip(Player p, ItemStack pickAxe, int level) {
|
||||
ItemMeta meta = pickAxe.getItemMeta();
|
||||
meta.addEnchant(Enchantment.DURABILITY, level, true);
|
||||
pickAxe.setItemMeta(meta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnequip(Player p, ItemStack pickAxe, int level) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockBreak(BlockBreakEvent e, int enchantLevel) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getChanceToTrigger(int enchantLevel) {
|
||||
return 100.0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
super.reload();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthor() {
|
||||
return "Drawethree";
|
||||
}
|
||||
}
|
|
@ -1,87 +0,0 @@
|
|||
package me.nvus.xprison.enchants.model.impl;
|
||||
|
||||
import me.nvus.xprison.enchants.XPrisonEnchants;
|
||||
import me.nvus.xprison.enchants.model.XPrisonEnchantment;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import me.lucko.helper.random.RandomSelector;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public final class VoucherFinderEnchant extends XPrisonEnchantment {
|
||||
|
||||
private double chance;
|
||||
private List<CommandWithChance> commandsToExecute;
|
||||
|
||||
public VoucherFinderEnchant(XPrisonEnchants instance) {
|
||||
super(instance, 20);
|
||||
this.chance = plugin.getEnchantsConfig().getYamlConfig().getDouble("enchants." + id + ".Chance");
|
||||
this.commandsToExecute = this.loadCommands();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEquip(Player p, ItemStack pickAxe, int level) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnequip(Player p, ItemStack pickAxe, int level) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockBreak(BlockBreakEvent e, int enchantLevel) {
|
||||
double chance = getChanceToTrigger(enchantLevel);
|
||||
|
||||
if (chance < ThreadLocalRandom.current().nextDouble(100)) {
|
||||
return;
|
||||
}
|
||||
|
||||
CommandWithChance randomCmd = getRandomCommandToExecute();
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), randomCmd.getCommand().replace("%player%", e.getPlayer().getName()));
|
||||
}
|
||||
|
||||
private CommandWithChance getRandomCommandToExecute() {
|
||||
return RandomSelector.weighted(this.commandsToExecute, CommandWithChance::getChance).pick();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getChanceToTrigger(int enchantLevel) {
|
||||
return this.chance * enchantLevel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
super.reload();
|
||||
this.chance = plugin.getEnchantsConfig().getYamlConfig().getDouble("enchants." + id + ".Chance");
|
||||
this.commandsToExecute = this.loadCommands();
|
||||
}
|
||||
|
||||
private List<CommandWithChance> loadCommands() {
|
||||
List<CommandWithChance> returnList = new ArrayList<>();
|
||||
for (String key : this.plugin.getEnchantsConfig().getYamlConfig().getConfigurationSection("enchants." + id + ".Commands").getKeys(false)) {
|
||||
String cmd = this.plugin.getEnchantsConfig().getYamlConfig().getString("enchants." + id + ".Commands." + key + ".command");
|
||||
double chance = this.plugin.getEnchantsConfig().getYamlConfig().getDouble("enchants." + id + ".Commands." + key + ".chance");
|
||||
returnList.add(new CommandWithChance(cmd, chance));
|
||||
}
|
||||
return returnList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthor() {
|
||||
return "Drawethree";
|
||||
}
|
||||
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
private static class CommandWithChance {
|
||||
private final String command;
|
||||
private final double chance;
|
||||
}
|
||||
}
|
|
@ -1,118 +0,0 @@
|
|||
package me.nvus.xprison.enchants.repo;
|
||||
|
||||
import me.nvus.xprison.XPrison;
|
||||
import me.nvus.xprison.enchants.XPrisonEnchants;
|
||||
import me.nvus.xprison.enchants.model.XPrisonEnchantment;
|
||||
import me.nvus.xprison.enchants.model.impl.*;
|
||||
import me.nvus.xprison.utils.text.TextUtils;
|
||||
import org.apache.commons.lang.Validate;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class EnchantsRepository {
|
||||
|
||||
private final XPrisonEnchants plugin;
|
||||
|
||||
private final Map<Integer, XPrisonEnchantment> enchantsById;
|
||||
private final Map<String, XPrisonEnchantment> enchantsByName;
|
||||
|
||||
public EnchantsRepository(XPrisonEnchants plugin) {
|
||||
this.plugin = plugin;
|
||||
this.enchantsById = new HashMap<>();
|
||||
this.enchantsByName = new HashMap<>();
|
||||
}
|
||||
|
||||
public Collection<XPrisonEnchantment> getAll() {
|
||||
return enchantsById.values();
|
||||
}
|
||||
|
||||
public XPrisonEnchantment getEnchantBy(Object object) {
|
||||
if (object instanceof Integer) {
|
||||
return getEnchantById((int) object);
|
||||
} else {
|
||||
final String s = String.valueOf(object);
|
||||
try {
|
||||
return getEnchantById(Integer.parseInt(s));
|
||||
} catch (NumberFormatException e) {
|
||||
return getEnchantByName(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public XPrisonEnchantment getEnchantById(int id) {
|
||||
return enchantsById.get(id);
|
||||
}
|
||||
|
||||
public XPrisonEnchantment getEnchantByName(String name) {
|
||||
return enchantsByName.get(name.toLowerCase());
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
|
||||
enchantsById.values().forEach(XPrisonEnchantment::reload);
|
||||
|
||||
XPrison.getInstance().getLogger().info(TextUtils.applyColor("&aSuccessfully reloaded all enchants."));
|
||||
}
|
||||
|
||||
public void loadDefaultEnchantments() {
|
||||
register(new EfficiencyEnchant(this.plugin));
|
||||
register(new UnbreakingEnchant(this.plugin));
|
||||
register(new FortuneEnchant(this.plugin));
|
||||
register(new HasteEnchant(this.plugin));
|
||||
register(new SpeedEnchant(this.plugin));
|
||||
register(new JumpBoostEnchant(this.plugin));
|
||||
register(new NightVisionEnchant(this.plugin));
|
||||
register(new FlyEnchant(this.plugin));
|
||||
register(new ExplosiveEnchant(this.plugin));
|
||||
register(new LayerEnchant(this.plugin));
|
||||
register(new CharityEnchant(this.plugin));
|
||||
register(new SalaryEnchant(this.plugin));
|
||||
register(new BlessingEnchant(this.plugin));
|
||||
register(new TokenatorEnchant(this.plugin));
|
||||
register(new KeyFinderEnchant(this.plugin));
|
||||
register(new PrestigeFinderEnchant(this.plugin));
|
||||
register(new BlockBoosterEnchant(this.plugin));
|
||||
register(new KeyallsEnchant(this.plugin));
|
||||
if (XPrison.getInstance().isUltraBackpacksEnabled()) {
|
||||
register(new BackpackAutoSellEnchant(this.plugin));
|
||||
} else {
|
||||
register(new AutoSellEnchant(this.plugin));
|
||||
}
|
||||
register(new VoucherFinderEnchant(this.plugin));
|
||||
register(new NukeEnchant(this.plugin));
|
||||
register(new GemFinderEnchant(this.plugin));
|
||||
register(new GangValueFinderEnchant(this.plugin));
|
||||
}
|
||||
|
||||
public boolean register(XPrisonEnchantment enchantment) {
|
||||
|
||||
if (enchantsById.containsKey(enchantment.getId()) || enchantsByName.containsKey(enchantment.getRawName())) {
|
||||
XPrison.getInstance().getLogger().warning(TextUtils.applyColor("&cUnable to register enchant " + enchantment.getName() + "&c created by " + enchantment.getAuthor() + ". That enchant is already registered."));
|
||||
return false;
|
||||
}
|
||||
|
||||
Validate.notNull(enchantment.getRawName());
|
||||
|
||||
enchantsById.put(enchantment.getId(), enchantment);
|
||||
enchantsByName.put(enchantment.getRawName().toLowerCase(), enchantment);
|
||||
|
||||
XPrison.getInstance().getLogger().info(TextUtils.applyColor("&aSuccessfully registered enchant " + enchantment.getName() + "&a created by " + enchantment.getAuthor()));
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean unregister(XPrisonEnchantment enchantment) {
|
||||
|
||||
if (!enchantsById.containsKey(enchantment.getId()) && !enchantsByName.containsKey(enchantment.getRawName())) {
|
||||
XPrison.getInstance().getLogger().warning(TextUtils.applyColor("&cUnable to unregister enchant " + enchantment.getName() + "&c created by " + enchantment.getAuthor() + ". That enchant is not registered."));
|
||||
return false;
|
||||
}
|
||||
|
||||
enchantsById.remove(enchantment.getId());
|
||||
enchantsByName.remove(enchantment.getRawName());
|
||||
|
||||
XPrison.getInstance().getLogger().info(TextUtils.applyColor("&aSuccessfully unregistered enchant " + enchantment.getName() + "&a created by " + enchantment.getAuthor()));
|
||||
return true;
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue