mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
Add create conflict item.
This commit is contained in:
parent
bf320e1ffc
commit
081266accf
5 changed files with 147 additions and 22 deletions
|
|
@ -7,14 +7,14 @@ import org.bukkit.plugin.java.JavaPlugin
|
|||
import xyz.alexcrea.cuanvil.command.EditConfigExecutor
|
||||
import xyz.alexcrea.cuanvil.command.ReloadExecutor
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder
|
||||
import xyz.alexcrea.cuanvil.listener.ChatEventListener
|
||||
import xyz.alexcrea.cuanvil.util.Metrics
|
||||
import xyz.alexcrea.cuanvil.util.MetricsUtil
|
||||
import java.io.File
|
||||
import java.io.FileReader
|
||||
|
||||
/**
|
||||
* Bukkit/Spigot/Paper plugin to alter enchantment max
|
||||
* levels and allow unsafe enchantment combinations
|
||||
* Bukkit/Spigot/Paper plugin to alter anvil feature
|
||||
*/
|
||||
class CustomAnvil : JavaPlugin() {
|
||||
|
||||
|
|
@ -41,6 +41,9 @@ class CustomAnvil : JavaPlugin() {
|
|||
// Current plugin instance
|
||||
lateinit var instance: CustomAnvil
|
||||
|
||||
// Chat message listener
|
||||
lateinit var chatListener: ChatEventListener
|
||||
|
||||
/**
|
||||
* Logging handler
|
||||
*/
|
||||
|
|
@ -74,8 +77,11 @@ class CustomAnvil : JavaPlugin() {
|
|||
logger.warning("Please note CustomAnvil is a more recent version of UnsafeEnchantsPlus")
|
||||
}
|
||||
|
||||
// Load config
|
||||
// Load chat listener
|
||||
chatListener = ChatEventListener()
|
||||
Bukkit.getPluginManager().registerEvents(chatListener, this)
|
||||
|
||||
// Load config
|
||||
val success = ConfigHolder.loadConfig()
|
||||
if(!success) return
|
||||
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ class ReloadExecutor : CommandExecutor {
|
|||
BasicConfigGui.INSTANCE.updateGuiValues()
|
||||
EnchantCostConfigGui.INSTANCE.updateGuiValues()
|
||||
EnchantLimitConfigGui.INSTANCE.updateGuiValues()
|
||||
EnchantCostConfigGui.INSTANCE.updateGuiValues()
|
||||
|
||||
// & update metric
|
||||
MetricsUtil.testIfConfigIsDefault()
|
||||
|
|
|
|||
|
|
@ -18,8 +18,6 @@ class EnchantConflictManager {
|
|||
// Path for a flag: if the enchantment will be used in the last supported version
|
||||
// TODO maybe replace this system by a list of "future" enchantment.
|
||||
private const val FUTURE_USE_PATH = "useInFuture"
|
||||
// Default name for an empty Material group
|
||||
private val DEFAULT_EMPTY_GROUP = IncludeGroup("empty")
|
||||
// Default name for a joining group
|
||||
private const val DEFAULT_GROUP_NAME = "joinedGroup"
|
||||
}
|
||||
|
|
@ -106,17 +104,11 @@ class EnchantConflictManager {
|
|||
}
|
||||
// Find or create the selected group for the conflict
|
||||
val groupList = section.getStringList(CONFLICT_GROUP_PATH)
|
||||
val finalGroup: AbstractMaterialGroup
|
||||
if(groupList.size < 1){
|
||||
finalGroup = DEFAULT_EMPTY_GROUP
|
||||
}else if(groupList.size == 1){
|
||||
finalGroup = findGroup(groupList[0], itemManager, conflictName)
|
||||
}else{
|
||||
finalGroup = IncludeGroup(DEFAULT_GROUP_NAME)
|
||||
for (groupName in groupList) {
|
||||
finalGroup.addToPolicy(findGroup(groupName, itemManager, conflictName))
|
||||
}
|
||||
val finalGroup = IncludeGroup(DEFAULT_GROUP_NAME)
|
||||
for (groupName in groupList) {
|
||||
finalGroup.addToPolicy(findGroup(groupName, itemManager, conflictName))
|
||||
}
|
||||
|
||||
// Return conflict
|
||||
return EnchantConflictGroup(conflictName, finalGroup, minBeforeBlock)
|
||||
}
|
||||
|
|
@ -125,7 +117,7 @@ class EnchantConflictManager {
|
|||
val group = itemManager.get(groupName)
|
||||
if(group == null){
|
||||
CustomAnvil.instance.logger.warning("Group $groupName do not exist but is ask by conflict $conflictName")
|
||||
return DEFAULT_EMPTY_GROUP
|
||||
return IncludeGroup("error_placeholder")
|
||||
}
|
||||
|
||||
return group
|
||||
|
|
|
|||
|
|
@ -0,0 +1,47 @@
|
|||
package xyz.alexcrea.cuanvil.listener
|
||||
|
||||
import io.delilaheve.CustomAnvil
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.entity.HumanEntity
|
||||
import org.bukkit.event.EventHandler
|
||||
import org.bukkit.event.Listener
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent
|
||||
import org.bukkit.event.player.PlayerQuitEvent
|
||||
import java.util.*
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import java.util.function.Consumer
|
||||
|
||||
class ChatEventListener : Listener{
|
||||
|
||||
private val playerListenMap: ConcurrentHashMap<UUID, Consumer<String?>> = ConcurrentHashMap()
|
||||
|
||||
fun setListenedCallback(playeruuid: UUID, callback: Consumer<String?>) {
|
||||
playerListenMap[playeruuid] = callback
|
||||
}
|
||||
|
||||
fun setListenedCallback(player: HumanEntity, callback: Consumer<String?>) {
|
||||
setListenedCallback(player.uniqueId, callback)
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
fun onQuit(event: PlayerQuitEvent) {
|
||||
val eventCallback = playerListenMap.remove(event.player.uniqueId) ?: return
|
||||
eventCallback.accept(null)
|
||||
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
fun onChat(event: AsyncPlayerChatEvent) {
|
||||
if (event.isCancelled) return
|
||||
val player = event.player
|
||||
val eventCallback = playerListenMap.remove(player.uniqueId) ?: return
|
||||
|
||||
event.isCancelled = true
|
||||
|
||||
// sync callback with default server thread
|
||||
Bukkit.getScheduler().runTask(CustomAnvil.instance, Runnable {
|
||||
eventCallback.accept(event.message)
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue