Compare commits

..

15 Commits

Author SHA1 Message Date
Auxilor
710cec4bc1 Merge branch 'develop' 2023-05-19 13:17:05 +01:00
Auxilor
fa0ec7d6b0 Updated to 6.60.4 2023-05-19 13:16:20 +01:00
Auxilor
5093799775 Merge remote-tracking branch 'origin/develop' into develop 2023-05-19 13:15:34 +01:00
Will FP
8535f23ede Merge pull request #274
Fix PvPManager integration
2023-05-19 13:15:24 +01:00
Will FP
8e09ae7f4c Merge pull request #275
Add RoyaleEconomy to prices system
2023-05-19 13:14:54 +01:00
Sen2000
bbc2513b40 Fix RoyaleEconomy integration 2023-05-19 16:54:05 +07:00
Sen2000
c7f8063a3a Add RoyaleEconomy to prices system 2023-05-19 09:11:17 +07:00
ChanceSD
14b0f1be0c Fix PvPManager integration 2023-05-18 22:42:49 +01:00
Auxilor
af20bb315b Updated to 6.60.3 2023-05-18 15:35:54 +01:00
Auxilor
6645e216d5 Fixed stupid profile saver bug 2023-05-18 15:35:47 +01:00
Auxilor
eddf240f0c Updated to 6.60.2 2023-05-18 14:33:21 +01:00
Auxilor
4f406353ba Fixed data bug 2023-05-18 14:33:14 +01:00
Auxilor
095494dd2e Fixed PersistentDataKeyType.BIG_DECIMAL and javadoc 2023-05-17 18:39:48 +01:00
Auxilor
fd92645500 Updated to 6.60.1 2023-05-17 17:27:00 +01:00
Auxilor
1a6ac29083 Fixed PersistentDataKeyType.BIG_DECIMAL 2023-05-17 17:26:48 +01:00
17 changed files with 119 additions and 48 deletions

View File

@@ -401,15 +401,6 @@ public interface Eco {
@NotNull
ServerProfile getServerProfile();
/**
* Unload a player profile from memory.
* <p>
* This will not save the profile first.
*
* @param uuid The uuid.
*/
void unloadPlayerProfile(@NotNull UUID uuid);
/**
* Create dummy entity - never spawned, exists purely in code.
*

View File

@@ -17,6 +17,13 @@ import java.util.function.Supplier;
* @param <T> The type of integration.
*/
public class IntegrationRegistry<T extends Integration> extends Registry<T> {
/**
* Create a new integration registry.
*/
public IntegrationRegistry() {
super();
}
@Override
public @NotNull T register(@NotNull final T element) {
return executeSafely(() -> super.register(element), element);

View File

@@ -286,9 +286,6 @@ class EcoImpl : EcoSpigotPlugin(), Eco {
override fun loadPlayerProfile(uuid: UUID) =
profileHandler.load(uuid)
override fun unloadPlayerProfile(uuid: UUID) =
profileHandler.unloadPlayer(uuid)
override fun createDummyEntity(location: Location): Entity =
getProxy(DummyEntityFactoryProxy::class.java).createDummyEntity(location)

View File

@@ -112,6 +112,7 @@ import com.willfp.eco.internal.spigot.integrations.mcmmo.McmmoIntegrationImpl
import com.willfp.eco.internal.spigot.integrations.multiverseinventories.MultiverseInventoriesIntegration
import com.willfp.eco.internal.spigot.integrations.placeholder.PlaceholderIntegrationPAPI
import com.willfp.eco.internal.spigot.integrations.price.PriceFactoryPlayerPoints
import com.willfp.eco.internal.spigot.integrations.price.PriceFactoryRoyaleEconomy
import com.willfp.eco.internal.spigot.integrations.price.PriceFactoryUltraEconomy
import com.willfp.eco.internal.spigot.integrations.shop.ShopDeluxeSellwands
import com.willfp.eco.internal.spigot.integrations.shop.ShopEconomyShopGUI
@@ -127,6 +128,7 @@ import com.willfp.eco.internal.spigot.recipes.stackhandlers.ShapedCraftingRecipe
import com.willfp.eco.internal.spigot.recipes.stackhandlers.ShapelessCraftingRecipeStackHandler
import com.willfp.eco.util.ClassUtils
import me.TechsCode.UltraEconomy.UltraEconomy
import me.qKing12.RoyaleEconomy.MultiCurrency.MultiCurrencyHandler
import net.kyori.adventure.platform.bukkit.BukkitAudiences
import net.milkbowl.vault.economy.Economy
import org.bukkit.Bukkit
@@ -219,8 +221,6 @@ abstract class EcoSpigotPlugin : EcoPlugin() {
this.logger.info("No conflicts found!")
}
CollatedRunnable(this)
CustomItemsManager.registerProviders() // Do it again here
// Register events for ShopSellEvent
@@ -251,7 +251,7 @@ abstract class EcoSpigotPlugin : EcoPlugin() {
Eco.get().adventure?.close()
}
override fun handleReload() {
override fun createTasks() {
CollatedRunnable(this)
this.scheduler.runLater(3) {
@@ -360,6 +360,11 @@ abstract class EcoSpigotPlugin : EcoPlugin() {
}
},
IntegrationLoader("PlayerPoints") { Prices.registerPriceFactory(PriceFactoryPlayerPoints()) },
IntegrationLoader("RoyaleEconomy") {
for (currency in MultiCurrencyHandler.getCurrencies()) {
Prices.registerPriceFactory(PriceFactoryRoyaleEconomy(currency))
}
},
// Placeholder
IntegrationLoader("PlaceholderAPI") { PlaceholderManager.addIntegration(PlaceholderIntegrationPAPI()) },
@@ -384,7 +389,7 @@ abstract class EcoSpigotPlugin : EcoPlugin() {
GUIListener(this),
ArrowDataListener(this),
ArmorChangeEventListeners(this),
DataListener(this),
DataListener(this, profileHandler),
PlayerBlockListener(this),
ServerLocking
)

View File

@@ -1,6 +1,5 @@
package com.willfp.eco.internal.spigot.data
import com.willfp.eco.core.Eco
import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.util.PlayerUtils
import org.bukkit.event.EventHandler
@@ -11,11 +10,14 @@ import org.bukkit.event.player.PlayerLoginEvent
import org.bukkit.event.player.PlayerQuitEvent
class DataListener(
private val plugin: EcoPlugin
private val plugin: EcoPlugin,
private val handler: ProfileHandler
) : Listener {
@EventHandler(priority = EventPriority.HIGHEST)
fun onLeave(event: PlayerQuitEvent) {
Eco.get().unloadPlayerProfile(event.player.uniqueId)
val profile = handler.accessLoadedProfile(event.player.uniqueId) ?: return
handler.saveKeysFor(event.player.uniqueId, profile.data.keys)
handler.unloadPlayer(event.player.uniqueId)
}
@EventHandler
@@ -27,6 +29,6 @@ class DataListener(
@EventHandler(priority = EventPriority.LOWEST)
fun onLogin(event: PlayerLoginEvent) {
Eco.get().unloadPlayerProfile(event.player.uniqueId)
handler.unloadPlayer(event.player.uniqueId)
}
}

View File

@@ -4,6 +4,7 @@ import com.willfp.eco.core.config.interfaces.Config
import com.willfp.eco.core.data.keys.PersistentDataKey
import com.willfp.eco.core.data.keys.PersistentDataKeyType
import org.bukkit.NamespacedKey
import java.math.BigDecimal
object KeyRegistry {
private val registry = mutableMapOf<NamespacedKey, PersistentDataKey<*>>()
@@ -44,6 +45,9 @@ object KeyRegistry {
PersistentDataKeyType.CONFIG -> if (default !is Config) {
throw IllegalArgumentException("Invalid Data Type! Should be Config")
}
PersistentDataKeyType.BIG_DECIMAL -> if (default !is BigDecimal) {
throw IllegalArgumentException("Invalid Data Type! Should be BigDecimal")
}
else -> throw NullPointerException("Null value found!")
}

View File

@@ -58,11 +58,18 @@ class ProfileHandler(
}
fun saveKeysFor(uuid: UUID, keys: Set<PersistentDataKey<*>>) {
handler.saveKeysFor(uuid, keys)
val profile = accessLoadedProfile(uuid) ?: return
val map = mutableMapOf<PersistentDataKey<*>, Any>()
for (key in keys) {
map[key] = profile.data[key] ?: continue
}
handler.saveKeysFor(uuid, map)
// Don't save to local handler if it's the same handler.
if (localHandler != handler) {
localHandler.saveKeysFor(uuid, keys)
localHandler.saveKeysFor(uuid, map)
}
}

View File

@@ -19,7 +19,7 @@ abstract class DataHandler(
/**
* Save a set of keys for a given UUID.
*/
abstract fun saveKeysFor(uuid: UUID, keys: Set<PersistentDataKey<*>>)
abstract fun saveKeysFor(uuid: UUID, keys: Map<PersistentDataKey<*>, Any>)
// Everything below this are methods that are only needed for certain implementations.

View File

@@ -1,6 +1,5 @@
package com.willfp.eco.internal.spigot.data.storage
import com.willfp.eco.core.data.Profile
import com.willfp.eco.core.data.keys.PersistentDataKey
import com.willfp.eco.internal.spigot.EcoSpigotPlugin
import com.willfp.eco.internal.spigot.data.ProfileHandler
@@ -51,18 +50,16 @@ class MongoDataHandler(
}
}
override fun saveKeysFor(uuid: UUID, keys: Set<PersistentDataKey<*>>) {
val profile = handler.loadGenericProfile(uuid)
override fun saveKeysFor(uuid: UUID, keys: Map<PersistentDataKey<*>, Any>) {
scope.launch {
for (key in keys) {
saveKey(profile, uuid, key)
for ((key, value) in keys) {
saveKey(uuid, key, value)
}
}
}
private suspend fun <T : Any> saveKey(profile: Profile, uuid: UUID, key: PersistentDataKey<T>) {
val data = profile.read(key)
private suspend fun <T : Any> saveKey(uuid: UUID, key: PersistentDataKey<T>, value: Any) {
val data = value as T
doWrite(uuid, key, data)
}

View File

@@ -101,16 +101,15 @@ class MySQLDataHandler(
setData(uuid, data)
}
override fun saveKeysFor(uuid: UUID, keys: Set<PersistentDataKey<*>>) {
val profile = handler.loadGenericProfile(uuid)
override fun saveKeysFor(uuid: UUID, keys: Map<PersistentDataKey<*>, Any>) {
executor.submit {
val data = getData(uuid)
for (key in keys) {
data.set(key.key.toString(), profile.read(key))
for ((key, value) in keys) {
data.set(key.key.toString(), value)
}
setData(uuid, data)
doSetData(uuid, data)
}
}
@@ -140,10 +139,14 @@ class MySQLDataHandler(
private fun setData(uuid: UUID, config: Config) {
executor.submit {
transaction(database) {
table.update({ table.id eq uuid }) {
it[dataColumn] = config.toPlaintext()
}
doSetData(uuid, config)
}
}
private fun doSetData(uuid: UUID, config: Config) {
transaction(database) {
table.update({ table.id eq uuid }) {
it[dataColumn] = config.toPlaintext()
}
}
}

View File

@@ -41,11 +41,9 @@ class YamlDataHandler(
doWrite(uuid, key.key, value)
}
override fun saveKeysFor(uuid: UUID, keys: Set<PersistentDataKey<*>>) {
val profile = handler.loadGenericProfile(uuid)
for (key in keys) {
doWrite(uuid, key.key, profile.read(key))
override fun saveKeysFor(uuid: UUID, keys: Map<PersistentDataKey<*>, Any>) {
for ((key, value) in keys) {
doWrite(uuid, key.key, value)
}
}

View File

@@ -27,7 +27,8 @@ class AntigriefPvPManager: AntigriefIntegration {
override fun canInjure(player: Player, victim: LivingEntity): Boolean {
return when(victim) {
is Player -> {
(PvPlayer.get(victim).isInCombat)}
val defender = PvPlayer.get(victim)
(defender.hasPvPEnabled() && !defender.isNewbie || defender.isInCombat)}
else -> true
}
}

View File

@@ -0,0 +1,54 @@
package com.willfp.eco.internal.spigot.integrations.price
import com.willfp.eco.core.placeholder.context.PlaceholderContext
import com.willfp.eco.core.placeholder.context.PlaceholderContextSupplier
import com.willfp.eco.core.price.Price
import com.willfp.eco.core.price.PriceFactory
import com.willfp.eco.util.toSingletonList
import me.qKing12.RoyaleEconomy.MultiCurrency.Currency
import org.bukkit.entity.Player
import java.util.*
class PriceFactoryRoyaleEconomy(private val currency: Currency) : PriceFactory {
override fun getNames(): List<String> {
return currency.currencyId.lowercase().toSingletonList()
}
override fun create(baseContext: PlaceholderContext, function: PlaceholderContextSupplier<Double>): Price {
return PriceRoyaleEconomy(currency, baseContext) { function.get(it) }
}
private class PriceRoyaleEconomy(
private val currency: Currency,
private val baseContext: PlaceholderContext,
private val function: (PlaceholderContext) -> Double
) : Price {
private val multipliers = mutableMapOf<UUID, Double>()
override fun canAfford(player: Player, multiplier: Double): Boolean {
return currency.getAmount(player.uniqueId.toString()) >= getValue(player, multiplier)
}
override fun pay(player: Player, multiplier: Double) {
currency.removeAmount(player.uniqueId.toString(), getValue(player, multiplier))
}
override fun giveTo(player: Player, multiplier: Double) {
currency.addAmount(player.uniqueId.toString(), getValue(player, multiplier))
}
override fun getValue(player: Player, multiplier: Double): Double {
return function(baseContext.copyWithPlayer(player)) * getMultiplier(player) * multiplier
}
override fun getMultiplier(player: Player): Double {
return multipliers[player.uniqueId] ?: 1.0
}
override fun setMultiplier(player: Player, multiplier: Double) {
multipliers[player.uniqueId] = multiplier
}
}
}

View File

@@ -194,5 +194,9 @@ dependencies:
bootstrap: false
- name: Denizen
required: false
bootstrap: false
- name: RoyaleEconomy
required: false
bootstrap: false

View File

@@ -54,3 +54,4 @@ softdepend:
- UltraEconomy
- PlayerPoints
- Denizen
- RoyaleEconomy

View File

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

BIN
lib/RoyaleEconomyAPI.jar Normal file

Binary file not shown.