Fix player config stuff and test event stuff

- The chat tests work!
This commit is contained in:
Norbi Peti 2023-06-27 01:29:20 +02:00
parent 4f0e05892a
commit ddd24a73f6
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
5 changed files with 13 additions and 16 deletions

View file

@ -29,13 +29,13 @@ class PlayerListener(val plugin: MainPlugin) : Listener {
fun onPlayerJoin(event: PlayerJoinEvent) { fun onPlayerJoin(event: PlayerJoinEvent) {
val p = event.player val p = event.player
val player = TBMCPlayerBase.getPlayer(p.uniqueId, TBMCPlayer::class.java) val player = TBMCPlayerBase.getPlayer(p.uniqueId, TBMCPlayer::class.java)
val pname = player.playerName.get() val pname = player.playerName
if (pname.isEmpty()) { if (pname.isEmpty()) {
player.playerName.set(p.name) player.playerName = p.name
plugin.logger.info("Player name saved: " + player.playerName.get()) plugin.logger.info("Player name saved: " + player.playerName)
} else if (p.name != pname) { } else if (p.name != pname) {
plugin.logger.info(pname + " renamed to " + p.name) plugin.logger.info(pname + " renamed to " + p.name)
player.playerName.set(p.name) player.playerName = p.name
} }
} }

View file

@ -19,8 +19,7 @@ import java.util.stream.Collectors
abstract class Component<TP : JavaPlugin> { abstract class Component<TP : JavaPlugin> {
var isEnabled = false var isEnabled = false
var config: IHaveConfig = IHaveConfig({ logWarn("Attempted to save config with null section!") }, null) val config: IHaveConfig = IHaveConfig({ logWarn("Attempted to save config with null section!") }, null)
private set
lateinit var plugin: TP lateinit var plugin: TP
private set private set

View file

@ -17,12 +17,11 @@ import java.util.function.Supplier
@ChromaGamerEnforcer @ChromaGamerEnforcer
abstract class ChromaGamerBase : Command2Sender { abstract class ChromaGamerBase : Command2Sender {
lateinit var config: IHaveConfig val config: IHaveConfig = IHaveConfig({ save() }, null)
protected set
protected lateinit var commonUserData: CommonUserData<out ChromaGamerBase> protected lateinit var commonUserData: CommonUserData<out ChromaGamerBase>
protected open fun initConfig() { protected open fun initConfig() {
config = IHaveConfig({ save() }, commonUserData.playerData) config.reload(commonUserData.playerData)
} }
/** /**

View file

@ -2,7 +2,6 @@ package buttondevteam.lib.player
import buttondevteam.core.MainPlugin import buttondevteam.core.MainPlugin
import buttondevteam.core.component.channel.Channel import buttondevteam.core.component.channel.Channel
import buttondevteam.lib.architecture.IHaveConfig
import org.bukkit.Bukkit import org.bukkit.Bukkit
import org.bukkit.entity.Player import org.bukkit.entity.Player
import java.util.* import java.util.*
@ -17,10 +16,9 @@ abstract class TBMCPlayerBase : ChromaGamerBase() {
/** /**
* If the player is the console * If the player is the console
*/ */
val isConsole = uniqueId == UUID(0, 0) val isConsole by lazy { uniqueId == UUID(0, 0) }
@JvmField var playerName by super.config.getData("PlayerName", "")
val playerName = super.config.getData("PlayerName", "")
public override fun initConfig() { public override fun initConfig() {
super.initConfig() super.initConfig()
val pluginName = if (javaClass.isAnnotationPresent(PlayerClass::class.java)) val pluginName = if (javaClass.isAnnotationPresent(PlayerClass::class.java))
@ -29,7 +27,7 @@ abstract class TBMCPlayerBase : ChromaGamerBase() {
throw RuntimeException("Class not defined as player class! Use @PlayerClass") throw RuntimeException("Class not defined as player class! Use @PlayerClass")
val playerData = commonUserData.playerData val playerData = commonUserData.playerData
val section = playerData.getConfigurationSection(pluginName) ?: playerData.createSection(pluginName) val section = playerData.getConfigurationSection(pluginName) ?: playerData.createSection(pluginName)
config = IHaveConfig({ save() }, section) config.reload(section)
} }
/** /**
@ -55,7 +53,7 @@ abstract class TBMCPlayerBase : ChromaGamerBase() {
} }
override fun getName(): String { override fun getName(): String {
return player?.displayName ?: playerName.get() return player?.displayName ?: playerName
} }
override fun checkChannelInGroup(group: String?): Channel.RecipientTestResult { override fun checkChannelInGroup(group: String?): Channel.RecipientTestResult {

View file

@ -1,5 +1,6 @@
package buttondevteam.lib.player; package buttondevteam.lib.player;
import buttondevteam.lib.ChromaUtils;
import buttondevteam.lib.player.ChromaGamerBase.InfoTarget; import buttondevteam.lib.player.ChromaGamerBase.InfoTarget;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
@ -24,7 +25,7 @@ public class TBMCPlayerGetInfoEvent extends Event {
private final InfoTarget target; private final InfoTarget target;
TBMCPlayerGetInfoEvent(ChromaGamerBase player, InfoTarget target) { TBMCPlayerGetInfoEvent(ChromaGamerBase player, InfoTarget target) {
super(true); super(!ChromaUtils.isTest());
this.player = player; this.player = player;
infolines = new ArrayList<>(); infolines = new ArrayList<>();
this.target = target; this.target = target;