Compare commits

..

21 Commits

Author SHA1 Message Date
Auxilor
9a703f6190 One more held item slot fix 2022-09-26 14:02:20 +01:00
Auxilor
f8fec7eec4 Updated to 6.41.3 2022-09-26 13:57:50 +01:00
Auxilor
f6aadda4ed Fixed PacketHeldItemSlot 2022-09-26 13:57:39 +01:00
Auxilor
d8fca0f348 Switched KingdomsX to local jar 2022-09-26 12:52:46 +01:00
Auxilor
65ff4c4a31 PR Codestyle 2022-09-26 12:36:34 +01:00
Auxilor
90702bc7aa Merge remote-tracking branch 'origin/develop' into develop 2022-09-26 12:34:53 +01:00
Will FP
e81b788a1b Merge pull request #199 from mani1232/master
Update KingdomsX dependence
2022-09-26 12:34:46 +01:00
Auxilor
ebc0ee7940 Updated to 6.41.2 2022-09-26 12:33:25 +01:00
Auxilor
82d269daf1 Improved PacketWindowItems and DisplayFrame 2022-09-26 12:32:07 +01:00
Auxilor
9d5300d6ae Began display system fixes 2022-09-26 12:10:22 +01:00
mani1232
8870e4d6fb Update KingdomsX dependence 2022-09-25 21:26:21 +02:00
Auxilor
d826a9f71f Switched FabledSkyblock to local jar 2022-09-14 21:18:55 +01:00
Auxilor
7ec3355237 Updated to 6.41.1 2022-09-14 21:18:28 +01:00
Auxilor
e59a8cc2e6 Oops 2022-09-14 21:13:33 +01:00
Auxilor
88f974fd10 Fixed long standing bug with ItemProvider (and scyther integration) 2022-09-14 21:08:14 +01:00
Auxilor
dfe2f1361b Updated to 6.41.0 2022-09-14 13:58:10 +01:00
Auxilor
3826f9f713 Added item price API 2022-09-14 13:57:01 +01:00
Auxilor
c2d2303c91 Added scyther integration and BigDecimal economy support 2022-09-14 13:45:32 +01:00
Auxilor
b1158ceb3d Added configurable host to Paste 2022-09-12 14:39:15 +01:00
Auxilor
af4048afbe Updated to 6.40.2 2022-09-12 13:53:51 +01:00
Auxilor
fce12020d5 Fixed bug with old MySQL versions 2022-09-12 13:53:35 +01:00
25 changed files with 295 additions and 70 deletions

View File

@@ -77,9 +77,6 @@ allprojects {
// LibsDisguises
maven("https://repo.md-5.net/content/groups/public/")
// FabledSkyblock
maven("https://repo.songoda.com/repository/public/")
}
dependencies {

View File

@@ -4,6 +4,8 @@ import com.willfp.eco.core.integrations.Integration;
import org.bukkit.OfflinePlayer;
import org.jetbrains.annotations.NotNull;
import java.math.BigDecimal;
/**
* Wrapper class for economy integrations.
*/
@@ -45,4 +47,14 @@ public interface EconomyIntegration extends Integration {
* @return The balance.
*/
double getBalance(@NotNull OfflinePlayer player);
/**
* Get the balance of a player.
*
* @param player The player.
* @return The balance.
*/
default BigDecimal getExactBalance(@NotNull OfflinePlayer player) {
return BigDecimal.valueOf(getBalance(player));
}
}

View File

@@ -3,6 +3,7 @@ package com.willfp.eco.core.integrations.economy;
import org.bukkit.OfflinePlayer;
import org.jetbrains.annotations.NotNull;
import java.math.BigDecimal;
import java.util.HashSet;
import java.util.Set;
@@ -96,6 +97,20 @@ public final class EconomyManager {
return 0;
}
/**
* Get the balance of a player.
*
* @param player The player.
* @return The balance.
*/
public static BigDecimal getExactBalance(@NotNull final OfflinePlayer player) {
for (EconomyIntegration integration : REGISTERED) {
return integration.getExactBalance(player);
}
return BigDecimal.ZERO;
}
private EconomyManager() {
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
}

View File

@@ -1,7 +1,10 @@
package com.willfp.eco.core.integrations.shop;
import com.willfp.eco.core.integrations.Integration;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
@@ -25,4 +28,27 @@ public interface ShopIntegration extends Integration {
// Do nothing unless overridden.
return null;
}
/**
* Get the price of an item.
*
* @param itemStack The item.
* @return The price.
*/
default double getPrice(@NotNull final ItemStack itemStack) {
// Do nothing unless overridden.
return 0.0;
}
/**
* Get the price of an item.
*
* @param itemStack The item.
* @param player The player.
* @return The price.
*/
default double getPrice(@NotNull final ItemStack itemStack,
@NotNull final Player player) {
return getPrice(itemStack);
}
}

View File

@@ -1,9 +1,12 @@
package com.willfp.eco.core.integrations.shop;
import com.willfp.eco.core.EcoPlugin;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.HashSet;
import java.util.Set;
@@ -52,6 +55,40 @@ public final class ShopManager {
}
}
/**
* Get the price of an item.
*
* @param itemStack The item.
* @return The price.
*/
public static double getItemPrice(@Nullable final ItemStack itemStack) {
return getItemPrice(itemStack, null);
}
/**
* Get the price of an item.
*
* @param itemStack The item.
* @param player The player.
* @return The price.
*/
public static double getItemPrice(@Nullable final ItemStack itemStack,
@Nullable final Player player) {
if (itemStack == null) {
return 0.0;
}
for (ShopIntegration shopIntegration : REGISTERED) {
if (player == null) {
return shopIntegration.getPrice(itemStack);
} else {
return shopIntegration.getPrice(itemStack, player);
}
}
return 0.0;
}
private ShopManager() {
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
}

View File

@@ -230,11 +230,11 @@ public final class Items {
String reformattedKey = keyID.replace("__", ":");
item = provider.provideForKey(reformattedKey);
if (item instanceof EmptyTestableItem || item == null) {
part = provider.provideForKey(reformattedKey);
if (part instanceof EmptyTestableItem || part == null) {
return new EmptyTestableItem();
}
registerCustomItem(namespacedKey, item);
registerCustomItem(namespacedKey, part);
}
/*

View File

@@ -25,13 +25,30 @@ public class Paste {
*/
private final String contents;
/**
* The host.
*/
private final String host;
/**
* Create a new paste.
*
* @param contents The contents.
*/
public Paste(@NotNull final String contents) {
this(contents, "https://paste.willfp.com");
}
/**
* Create a new paste.
*
* @param contents The contents.
* @param host The host.
*/
public Paste(@NotNull final String contents,
@NotNull final String host) {
this.contents = contents;
this.host = host;
}
/**
@@ -47,7 +64,7 @@ public class Paste {
byte[] postData = URLEncoder.encode(contents, StandardCharsets.UTF_8).getBytes(StandardCharsets.UTF_8);
int postDataLength = postData.length;
String requestURL = "https://paste.willfp.com/documents";
String requestURL = this.host + "/documents";
URL url = new URL(requestURL);
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
conn.setDoOutput(true);
@@ -85,14 +102,26 @@ public class Paste {
* @return The paste.
*/
public static Paste getFromHastebin(@NotNull final String token) {
return getFromHastebin(token, "https://paste.willfp.com");
}
/**
* Get paste from hastebin.
*
* @param token The token.
* @param host The host.
* @return The paste.
*/
public static Paste getFromHastebin(@NotNull final String token,
@NotNull final String host) {
try {
StringBuilder result = new StringBuilder();
URL url = new URL("https://paste.willfp.com/raw/" + token);
URL url = new URL(host + "/raw/" + token);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
try (var reader = new BufferedReader(
new InputStreamReader(conn.getInputStream()))) {
for (String line; (line = reader.readLine()) != null;) {
for (String line; (line = reader.readLine()) != null; ) {
result.append(line);
}
}

View File

@@ -3,6 +3,7 @@
package com.willfp.eco.core.integrations.economy
import org.bukkit.OfflinePlayer
import java.math.BigDecimal
/** @see EconomyManager */
var OfflinePlayer.balance: Double
@@ -21,3 +22,21 @@ var OfflinePlayer.balance: Double
EconomyManager.giveMoney(this, -diff)
}
}
/** @see EconomyManager */
var OfflinePlayer.exactBalance: BigDecimal
get() = EconomyManager.getBalance(this).toBigDecimal()
set(value) {
if (value <= BigDecimal.ZERO) {
EconomyManager.removeMoney(this, this.balance)
return
}
val diff = this.exactBalance - value
if (diff > BigDecimal.ZERO) {
EconomyManager.removeMoney(this, diff.toDouble())
} else if (diff < BigDecimal.ZERO) {
EconomyManager.giveMoney(this, -diff.toDouble())
}
}

View File

@@ -0,0 +1,14 @@
@file:JvmName("ShopExtensions")
package com.willfp.eco.core.integrations.shop
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack
/** @see ShopManager.getItemPrice **/
val ItemStack.price: Double
get() = ShopManager.getItemPrice(this)
/** @see ShopManager.getItemPrice **/
fun ItemStack.getPrice(player: Player): Double =
ShopManager.getItemPrice(this, player)

View File

@@ -25,7 +25,6 @@ dependencies {
compileOnly 'com.comphenix.protocol:ProtocolLib:5.0.0-SNAPSHOT'
compileOnly 'com.sk89q.worldguard:worldguard-bukkit:7.0.7-SNAPSHOT'
compileOnly 'com.github.TechFortress:GriefPrevention:16.17.1'
compileOnly 'com.github.cryptomorin:kingdoms:1.12.3'
compileOnly('com.github.TownyAdvanced:Towny:0.97.2.6') {
exclude group: 'com.zaxxer', module: 'HikariCP'
}
@@ -41,12 +40,12 @@ dependencies {
compileOnly 'com.gmail.filoghost.holographicdisplays:holographicdisplays-api:2.4.0'
compileOnly 'com.github.EssentialsX:Essentials:2.18.2'
compileOnly 'com.bgsoftware:SuperiorSkyblockAPI:1.8.3'
compileOnly 'com.songoda:skyblock:2.3.30'
compileOnly 'com.github.MilkBowl:VaultAPI:1.7'
compileOnly 'com.github.WhipDevelopment:CrashClaim:f9cd7d92eb'
compileOnly 'com.wolfyscript.wolfyutilities:wolfyutilities:3.16.0.0'
compileOnly 'com.github.decentsoftware-eu:decentholograms:2.1.2'
compileOnly 'com.github.Gypopo:EconomyShopGUI-API:1.1.0'
compileOnly 'com.github.N0RSKA:ScytherAPI:55a'
// MythicMobs
compileOnly 'io.lumine:Mythic:5.0.1'

View File

@@ -56,7 +56,7 @@ import com.willfp.eco.internal.spigot.data.PlayerBlockListener
import com.willfp.eco.internal.spigot.data.storage.ProfileSaver
import com.willfp.eco.internal.spigot.display.PacketAutoRecipe
import com.willfp.eco.internal.spigot.display.PacketChat
import com.willfp.eco.internal.spigot.display.PacketHeldWindowItems
import com.willfp.eco.internal.spigot.display.PacketHeldItemSlot
import com.willfp.eco.internal.spigot.display.PacketOpenWindowMerchant
import com.willfp.eco.internal.spigot.display.PacketSetCreativeSlot
import com.willfp.eco.internal.spigot.display.PacketSetSlot
@@ -101,6 +101,7 @@ import com.willfp.eco.internal.spigot.integrations.customitems.CustomItemsHeadDa
import com.willfp.eco.internal.spigot.integrations.customitems.CustomItemsItemsAdder
import com.willfp.eco.internal.spigot.integrations.customitems.CustomItemsMythicMobs
import com.willfp.eco.internal.spigot.integrations.customitems.CustomItemsOraxen
import com.willfp.eco.internal.spigot.integrations.customitems.CustomItemsScyther
import com.willfp.eco.internal.spigot.integrations.customrecipes.CustomRecipeCustomCrafting
import com.willfp.eco.internal.spigot.integrations.economy.EconomyVault
import com.willfp.eco.internal.spigot.integrations.hologram.HologramCMI
@@ -313,6 +314,7 @@ abstract class EcoSpigotPlugin : EcoPlugin() {
CraftingRecipeListener.registerValidator(CustomRecipeCustomCrafting())
},
IntegrationLoader("MythicMobs") { CustomItemsManager.register(CustomItemsMythicMobs(this)) },
IntegrationLoader("Scyther") { CustomItemsManager.register(CustomItemsScyther()) },
// Shop
IntegrationLoader("ShopGUIPlus") { ShopManager.register(ShopShopGuiPlus()) },
@@ -355,7 +357,7 @@ abstract class EcoSpigotPlugin : EcoPlugin() {
PacketSetCreativeSlot(this),
PacketSetSlot(this),
PacketWindowItems(this),
PacketHeldWindowItems(this),
PacketHeldItemSlot(this),
PacketOpenWindowMerchant(this)
)
}

View File

@@ -67,7 +67,6 @@ class MySQLDataHandler(
table.apply {
registerColumn<String>("json_data", TextColumnType())
.default("{}")
}
SchemaUtils.createMissingTablesAndColumns(table, withLogs = false)
@@ -124,7 +123,7 @@ class MySQLDataHandler(
}
}
row[dataColumn]
row.getOrNull(dataColumn) ?: "{}"
}

View File

@@ -0,0 +1,29 @@
package com.willfp.eco.internal.spigot.display
import com.comphenix.protocol.PacketType
import com.comphenix.protocol.events.PacketContainer
import com.comphenix.protocol.events.PacketEvent
import com.willfp.eco.core.AbstractPacketAdapter
import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.internal.spigot.display.frame.DisplayFrame
import com.willfp.eco.internal.spigot.display.frame.lastDisplayFrame
import org.bukkit.entity.Player
class PacketHeldItemSlot(plugin: EcoPlugin) :
AbstractPacketAdapter(plugin, PacketType.Play.Server.HELD_ITEM_SLOT, false) {
override fun onSend(
packet: PacketContainer,
player: Player,
event: PacketEvent
) {
player.lastDisplayFrame = DisplayFrame.EMPTY
}
override fun onReceive(
packet: PacketContainer,
player: Player,
event: PacketEvent
) {
player.lastDisplayFrame = DisplayFrame.EMPTY
}
}

View File

@@ -1,25 +0,0 @@
package com.willfp.eco.internal.spigot.display
import com.comphenix.protocol.PacketType
import com.comphenix.protocol.events.PacketContainer
import com.comphenix.protocol.events.PacketEvent
import com.willfp.eco.core.AbstractPacketAdapter
import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.display.Display
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack
class PacketHeldWindowItems(plugin: EcoPlugin) :
AbstractPacketAdapter(plugin, PacketType.Play.Server.WINDOW_ITEMS, false) {
override fun onSend(
packet: PacketContainer,
player: Player,
event: PacketEvent
) {
packet.itemModifier.modify(0) { item: ItemStack? ->
Display.display(
item!!, player
)
}
}
}

View File

@@ -9,7 +9,6 @@ import com.willfp.eco.core.display.Display
import com.willfp.eco.internal.spigot.display.frame.DisplayFrame
import com.willfp.eco.internal.spigot.display.frame.lastDisplayFrame
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack
class PacketSetSlot(plugin: EcoPlugin) : AbstractPacketAdapter(plugin, PacketType.Play.Server.SET_SLOT, false) {
override fun onSend(
@@ -17,14 +16,13 @@ class PacketSetSlot(plugin: EcoPlugin) : AbstractPacketAdapter(plugin, PacketTyp
player: Player,
event: PacketEvent
) {
packet.itemModifier.modify(0, object : VersionCompatiblePLibFunction<ItemStack> {
override fun apply(item: ItemStack) =
Display.display(
item,
player
)
})
packet.itemModifier.modify(0) {
Display.display(
it,
player
)
}
player.lastDisplayFrame = DisplayFrame.EMPTY
}
}
}

View File

@@ -14,21 +14,32 @@ import org.bukkit.inventory.ItemStack
import java.util.concurrent.ConcurrentHashMap
class PacketWindowItems(plugin: EcoPlugin) : AbstractPacketAdapter(plugin, PacketType.Play.Server.WINDOW_ITEMS, false) {
private val ignorePacketList = ConcurrentHashMap.newKeySet<String>()
private val lastKnownWindowIDs = ConcurrentHashMap<String, Int>()
override fun onSend(
packet: PacketContainer,
player: Player,
event: PacketEvent
) {
if (ignorePacketList.contains(player.name)) {
ignorePacketList.remove(player.name)
return
packet.itemModifier.modify(0) {
Display.display(
it, player
)
}
val windowId = packet.integers.read(0)
if (windowId != 0) {
// Using name because UUID is unreliable with ProtocolLib players.
val name = player.name
val lastKnownID = lastKnownWindowIDs[name]
lastKnownWindowIDs[name] = windowId
// If there is any change in window ID at any point,
// Remove the last display frame to prevent any potential conflicts.
// If the window ID is not zero (not a player inventory), then remove too,
// as GUIs are not player inventories.
if (lastKnownID != windowId || windowId != 0) {
player.lastDisplayFrame = DisplayFrame.EMPTY
}

View File

@@ -1,8 +0,0 @@
package com.willfp.eco.internal.spigot.display
import com.google.common.base.Function
import java.util.function.UnaryOperator
interface VersionCompatiblePLibFunction<T> : Function<T, T>, UnaryOperator<T> {
}

View File

@@ -6,10 +6,10 @@ import org.bukkit.block.Block
import org.bukkit.entity.LivingEntity
import org.bukkit.entity.Player
import org.kingdoms.constants.group.Kingdom
import org.kingdoms.constants.group.model.KingdomRelation
import org.kingdoms.constants.group.model.relationships.StandardRelationAttribute
import org.kingdoms.constants.land.Land
import org.kingdoms.constants.player.DefaultKingdomPermission
import org.kingdoms.constants.player.KingdomPlayer
import org.kingdoms.constants.player.StandardKingdomPermission
import org.kingdoms.managers.PvPManager
class AntigriefKingdoms : AntigriefIntegration {
@@ -23,11 +23,13 @@ class AntigriefKingdoms : AntigriefIntegration {
}
val kingdom: Kingdom = kp.kingdom ?: return false
val land = Land.getLand(block) ?: return true
val permission: DefaultKingdomPermission =
if (land.isNexusLand) DefaultKingdomPermission.NEXUS_BUILD else DefaultKingdomPermission.BUILD
val permission = if (land.isNexusLand) {
StandardKingdomPermission.NEXUS_BUILD
} else StandardKingdomPermission.BUILD
return if (!kp.hasPermission(permission)) {
false
} else kingdom.hasAttribute(land.kingdom, KingdomRelation.Attribute.BUILD)
} else kingdom.hasAttribute(land.kingdom, StandardRelationAttribute.BUILD)
}
override fun canCreateExplosion(
@@ -84,4 +86,4 @@ class AntigriefKingdoms : AntigriefIntegration {
override fun hashCode(): Int {
return this.pluginName.hashCode()
}
}
}

View File

@@ -0,0 +1,48 @@
package com.willfp.eco.internal.spigot.integrations.customitems
import com.willfp.eco.core.integrations.customitems.CustomItemsIntegration
import com.willfp.eco.core.items.CustomItem
import com.willfp.eco.core.items.Items
import com.willfp.eco.core.items.TestableItem
import com.willfp.eco.core.items.provider.ItemProvider
import com.willfp.eco.util.NamespacedKeyUtils
import dev.norska.scyther.Scyther
import dev.norska.scyther.api.ScytherAPI
import org.bukkit.Material
class CustomItemsScyther : CustomItemsIntegration {
override fun registerProvider() {
Items.registerItemProvider(ScytherProvider())
}
override fun getPluginName(): String {
return "Scyther"
}
private class ScytherProvider : ItemProvider("scyther") {
override fun provideForKey(key: String): TestableItem? {
val material = Material.matchMaterial(key.uppercase()) ?: Material.WOODEN_HOE
val hoe = ScytherAPI.createHarvesterHoe(
Scyther.getInstance(),
material,
0,
1.0,
1,
Int.MAX_VALUE,
"AUTOSELL",
true
)
val namespacedKey = NamespacedKeyUtils.create("scyther", key)
return CustomItem(
namespacedKey,
{
ScytherAPI.isHarvesterItem(it) && it.type == material
},
hoe
)
}
}
}

View File

@@ -2,16 +2,27 @@ package com.willfp.eco.internal.spigot.integrations.shop
import com.willfp.eco.core.integrations.shop.ShopIntegration
import com.willfp.eco.core.integrations.shop.ShopSellEvent
import me.gypopo.economyshopgui.api.EconomyShopGUIHook
import me.gypopo.economyshopgui.api.events.PreTransactionEvent
import org.bukkit.Bukkit
import org.bukkit.entity.Player
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.inventory.ItemStack
class ShopEconomyShopGUI : ShopIntegration {
override fun getSellEventAdapter(): Listener {
return EconomyShopGUISellEventListeners
}
override fun getPrice(itemStack: ItemStack, player: Player): Double {
return EconomyShopGUIHook.getItemSellPrice(player, itemStack)
}
override fun getPrice(itemStack: ItemStack): Double {
return EconomyShopGUIHook.getItemSellPrice(itemStack)
}
object EconomyShopGUISellEventListeners : Listener {
@EventHandler
fun shopEventToEcoEvent(event: PreTransactionEvent) {

View File

@@ -9,6 +9,7 @@ import net.brcdev.shopgui.provider.item.ItemProvider
import net.brcdev.shopgui.shop.ShopManager
import org.bukkit.Bukkit
import org.bukkit.configuration.ConfigurationSection
import org.bukkit.entity.Player
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.inventory.ItemStack
@@ -22,6 +23,14 @@ class ShopShopGuiPlus : ShopIntegration {
return ShopGuiPlusSellEventListeners
}
override fun getPrice(itemStack: ItemStack): Double {
return ShopGuiPlusApi.getItemStackPriceSell(itemStack)
}
override fun getPrice(itemStack: ItemStack, player: Player): Double {
return ShopGuiPlusApi.getItemStackPriceSell(player, itemStack)
}
class EcoShopGuiPlusProvider : ItemProvider("eco") {
override fun isValidItem(itemStack: ItemStack?): Boolean {
itemStack ?: return false

View File

@@ -46,4 +46,5 @@ softdepend:
- RPGHorses
- EconomyShopGUI
- zShop
- DeluxeSellwands
- DeluxeSellwands
- Scyther

View File

@@ -1,3 +1,3 @@
version = 6.40.1
version = 6.41.3
plugin-name = eco
kotlin.code.style = official

Binary file not shown.

Binary file not shown.