mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2024-11-25 15:35:11 +01:00
Added autosell extension
This commit is contained in:
parent
e2fcf6ad3b
commit
a4e6cbcd62
12
eco-extensions/autosell/build.gradle
Normal file
12
eco-extensions/autosell/build.gradle
Normal file
@ -0,0 +1,12 @@
|
||||
group 'com.willfp'
|
||||
version '1.0.0'
|
||||
description = 'Autosell Extension'
|
||||
|
||||
shadowJar {
|
||||
archiveFileName = project.getDescription() + " v" + project.version + ".jar"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly 'com.github.brcdev-minecraft:shopgui-api:2.2.0'
|
||||
compileOnly 'com.github.MilkBowl:VaultAPI:1.7'
|
||||
}
|
@ -0,0 +1,112 @@
|
||||
package com.willfp.ecoenchants.autosell;
|
||||
|
||||
|
||||
import com.willfp.eco.core.drops.DropQueue;
|
||||
import com.willfp.eco.core.integrations.antigrief.AntigriefManager;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantChecks;
|
||||
import net.brcdev.shopgui.ShopGuiPlusApi;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Container;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.block.BlockDropItemEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class Autosell extends EcoEnchant {
|
||||
private static final Set<Material> FORTUNE_MATERIALS = new HashSet<>(
|
||||
Arrays.asList(
|
||||
Material.GOLD_INGOT,
|
||||
Material.IRON_INGOT
|
||||
)
|
||||
);
|
||||
|
||||
public Autosell() {
|
||||
super(
|
||||
"autosell", EnchantmentType.NORMAL
|
||||
);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void infernalTouchBreak(@NotNull final BlockDropItemEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
Block block = event.getBlock();
|
||||
|
||||
if (!this.areRequirementsMet(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!EnchantChecks.mainhand(player, this)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getBlockState() instanceof Container) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!AntigriefManager.canBreakBlock(player, block)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.getDisabledWorlds().contains(player.getWorld())) {
|
||||
return;
|
||||
}
|
||||
|
||||
Collection<ItemStack> drops = new ArrayList<>();
|
||||
|
||||
for (Item item : event.getItems()) {
|
||||
drops.add(item.getItemStack());
|
||||
}
|
||||
|
||||
int experience = 0;
|
||||
int fortune = EnchantChecks.getMainhandLevel(player, Enchantment.LOOT_BONUS_BLOCKS);
|
||||
|
||||
for (ItemStack itemStack : drops) {
|
||||
if (fortune > 0 && FORTUNE_MATERIALS.contains(itemStack.getType())) {
|
||||
itemStack.setAmount((int) Math.round((Math.random() * ((double) fortune - 1)) + 1.1));
|
||||
}
|
||||
|
||||
double price = ShopGuiPlusApi.getItemStackPriceSell(player, itemStack);
|
||||
if (price <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
EconomyHandler.getInstance().depositPlayer(player, price);
|
||||
|
||||
drops.remove(itemStack);
|
||||
}
|
||||
|
||||
event.getItems().clear();
|
||||
|
||||
if (!this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "drop-xp")) {
|
||||
experience = 0;
|
||||
}
|
||||
|
||||
new DropQueue(player)
|
||||
.setLocation(block.getLocation())
|
||||
.addItems(drops)
|
||||
.addXP(experience)
|
||||
.push();
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package com.willfp.ecoenchants.autosell;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.extensions.Extension;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class AutosellMain extends Extension {
|
||||
/**
|
||||
* Autosell enchantment.
|
||||
*/
|
||||
public static final EcoEnchant AUTOSELL = new Autosell();
|
||||
|
||||
public AutosellMain(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
EconomyHandler.setEnabled(EconomyHandler.init());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
// Handled by super
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package com.willfp.ecoenchants.autosell;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
@UtilityClass
|
||||
public class EconomyHandler {
|
||||
/**
|
||||
* The instance.
|
||||
*/
|
||||
@Getter
|
||||
private static Economy instance = null;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private static boolean enabled = false;
|
||||
|
||||
/**
|
||||
* Initialize the economy manager.
|
||||
*
|
||||
* @return If was successful.
|
||||
*/
|
||||
public boolean init() {
|
||||
RegisteredServiceProvider<Economy> rsp = Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
|
||||
if (rsp == null) {
|
||||
return false;
|
||||
}
|
||||
instance = rsp.getProvider();
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
#
|
||||
# Autosell EcoEnchant
|
||||
#
|
||||
|
||||
name: "Autosell"
|
||||
description: Drops are instantly sold to the shop
|
||||
enabled: true
|
||||
|
||||
obtaining:
|
||||
table: true
|
||||
villager: true
|
||||
loot: true
|
||||
rarity: legendary
|
||||
|
||||
general-config:
|
||||
flags: [ ]
|
||||
targets:
|
||||
- pickaxe
|
||||
- axe
|
||||
grindstoneable: true
|
||||
disabled-in-worlds: [ ]
|
||||
requirements:
|
||||
list: [ ]
|
||||
not-met-lore: [ ]
|
||||
conflicts:
|
||||
- silk_touch
|
||||
|
||||
config:
|
||||
drop-xp: true
|
4
eco-extensions/autosell/src/main/resources/extension.yml
Normal file
4
eco-extensions/autosell/src/main/resources/extension.yml
Normal file
@ -0,0 +1,4 @@
|
||||
name: Autosell
|
||||
main: com.willfp.ecoenchants.autosell.AutosellMain
|
||||
version: ${projectVersion}
|
||||
author: Auxilor
|
@ -11,6 +11,7 @@ include ':eco-core:core-plugin'
|
||||
// Extensions
|
||||
include ':eco-extensions'
|
||||
include ':eco-extensions:alchemy'
|
||||
include ':eco-extensions:autosell'
|
||||
include ':eco-extensions:biomes'
|
||||
include ':eco-extensions:citizen'
|
||||
include ':eco-extensions:countereffects'
|
||||
|
Loading…
Reference in New Issue
Block a user