From 45ad34f4c8d316c0a467d7e30869037c95636fec Mon Sep 17 00:00:00 2001 From: dmccoystephenson Date: Wed, 1 Mar 2023 18:59:18 -0700 Subject: [PATCH 01/19] Started working on create & list commands. --- .../kotlin/com/dansplugins/fiefs/Fiefs.kt | 5 ++ .../fiefs/command/fiefs/FiefsCommand.kt | 14 +++++- .../fiefs/create/FiefsCreateCommand.kt | 22 +++++++++ .../command/fiefs/help/FiefsHelpCommand.kt | 2 + .../command/fiefs/list/FiefsListCommand.kt | 27 +++++++++++ .../kotlin/com/dansplugins/fiefs/fief/Fief.kt | 31 ++++++++++++ .../com/dansplugins/fiefs/fief/FiefFactory.kt | 14 ++++++ .../dansplugins/fiefs/fief/FiefRepository.kt | 48 +++++++++++++++++++ src/main/resources/plugin.yml | 9 +++- 9 files changed, 169 insertions(+), 3 deletions(-) create mode 100644 src/main/kotlin/com/dansplugins/fiefs/command/fiefs/create/FiefsCreateCommand.kt create mode 100644 src/main/kotlin/com/dansplugins/fiefs/command/fiefs/list/FiefsListCommand.kt create mode 100644 src/main/kotlin/com/dansplugins/fiefs/fief/Fief.kt create mode 100644 src/main/kotlin/com/dansplugins/fiefs/fief/FiefFactory.kt create mode 100644 src/main/kotlin/com/dansplugins/fiefs/fief/FiefRepository.kt diff --git a/src/main/kotlin/com/dansplugins/fiefs/Fiefs.kt b/src/main/kotlin/com/dansplugins/fiefs/Fiefs.kt index 35883ce..600709a 100644 --- a/src/main/kotlin/com/dansplugins/fiefs/Fiefs.kt +++ b/src/main/kotlin/com/dansplugins/fiefs/Fiefs.kt @@ -2,12 +2,17 @@ package com.dansplugins.fiefs import com.dansplugins.factionsystem.MedievalFactions import com.dansplugins.fiefs.command.fiefs.FiefsCommand +import com.dansplugins.fiefs.fief.FiefFactory +import com.dansplugins.fiefs.fief.FiefRepository import org.bstats.bukkit.Metrics import org.bukkit.plugin.java.JavaPlugin class Fiefs : JavaPlugin() { lateinit var medievalFactions: MedievalFactions + val fiefRepository = FiefRepository(this) + val fiefFactory = FiefFactory(this) + override fun onEnable() { saveDefaultConfig() config.options().copyDefaults(true) diff --git a/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/FiefsCommand.kt b/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/FiefsCommand.kt index d22a047..02a7434 100644 --- a/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/FiefsCommand.kt +++ b/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/FiefsCommand.kt @@ -1,7 +1,9 @@ package com.dansplugins.fiefs.command.fiefs import com.dansplugins.fiefs.Fiefs +import com.dansplugins.fiefs.command.fiefs.create.FiefsCreateCommand import com.dansplugins.fiefs.command.fiefs.help.FiefsHelpCommand +import com.dansplugins.fiefs.command.fiefs.list.FiefsListCommand import org.bukkit.ChatColor.AQUA import org.bukkit.ChatColor.GREEN import org.bukkit.command.Command @@ -11,14 +13,20 @@ import org.bukkit.command.TabCompleter class FiefsCommand(private val plugin: Fiefs) : CommandExecutor, TabCompleter { private val helpCommand = FiefsHelpCommand(plugin) + private val createCommand = FiefsCreateCommand(plugin) + private val listCommand = FiefsListCommand(plugin) private val subcommands = listOf( - "help" + "help", + "create", + "list" ) override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array): Boolean { return when (args.firstOrNull()?.lowercase()) { "help" -> helpCommand.onCommand(sender, command, label, args.drop(1).toTypedArray()) + "create" -> createCommand.onCommand(sender, command, label, args.drop(1).toTypedArray()) + "list" -> listCommand.onCommand(sender, command, label, args.drop(1).toTypedArray()) else -> { // send plugin information sender.sendMessage("$AQUA" + "Fiefs v${plugin.description.version}") @@ -37,11 +45,13 @@ class FiefsCommand(private val plugin: Fiefs) : CommandExecutor, TabCompleter { command: Command, alias: String, args: Array - ): List { + ): List? { return when (args.size) { 1 -> subcommands.filter { it.startsWith(args[0]) }.toMutableList() else -> when(args.first().lowercase()) { "help" -> helpCommand.onTabComplete(sender, command, alias, args.drop(1).toTypedArray()) + "create" -> createCommand.onTabComplete(sender, command, alias, args.drop(1).toTypedArray()) + "list" -> listCommand.onTabComplete(sender, command, alias, args.drop(1).toTypedArray()) else -> emptyList() } } diff --git a/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/create/FiefsCreateCommand.kt b/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/create/FiefsCreateCommand.kt new file mode 100644 index 0000000..b687f7e --- /dev/null +++ b/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/create/FiefsCreateCommand.kt @@ -0,0 +1,22 @@ +package com.dansplugins.fiefs.command.fiefs.create + +import com.dansplugins.fiefs.Fiefs +import org.bukkit.command.Command +import org.bukkit.command.CommandExecutor +import org.bukkit.command.CommandSender +import org.bukkit.command.TabCompleter + +class FiefsCreateCommand(private val plugin: Fiefs) : CommandExecutor, TabCompleter { + override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array): Boolean { + TODO("Not yet implemented") + } + + override fun onTabComplete( + sender: CommandSender, + command: Command, + alias: String, + args: Array + ): MutableList? { + TODO("Not yet implemented") + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/help/FiefsHelpCommand.kt b/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/help/FiefsHelpCommand.kt index 3fcad97..56f026d 100644 --- a/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/help/FiefsHelpCommand.kt +++ b/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/help/FiefsHelpCommand.kt @@ -12,6 +12,8 @@ class FiefsHelpCommand(private val plugin: Fiefs) : CommandExecutor, TabComplete // send list of commands sender.sendMessage("${AQUA}=== Fiefs Commands ===") sender.sendMessage("${AQUA}/fiefs help - Displays a list of useful commands.") + sender.sendMessage("${AQUA}/fiefs create - Creates a fief.") + sender.sendMessage("${AQUA}/fiefs list - Lists all fiefs.") return true } diff --git a/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/list/FiefsListCommand.kt b/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/list/FiefsListCommand.kt new file mode 100644 index 0000000..e9a0d5b --- /dev/null +++ b/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/list/FiefsListCommand.kt @@ -0,0 +1,27 @@ +package com.dansplugins.fiefs.command.fiefs.list + +import com.dansplugins.fiefs.Fiefs +import org.bukkit.command.Command +import org.bukkit.command.CommandExecutor +import org.bukkit.command.CommandSender +import org.bukkit.command.TabCompleter + +class FiefsListCommand(private val plugin: Fiefs) : CommandExecutor, TabCompleter { + override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array): Boolean { + sender.sendMessage("=== Fiefs ===") + for (fief in plugin.fiefRepository.getFiefs()) { + sender.sendMessage(fief.getName()) + } + return true + } + + override fun onTabComplete( + sender: CommandSender, + command: Command, + alias: String, + args: Array + ): MutableList? { + TODO("Not yet implemented") + } + +} \ No newline at end of file diff --git a/src/main/kotlin/com/dansplugins/fiefs/fief/Fief.kt b/src/main/kotlin/com/dansplugins/fiefs/fief/Fief.kt new file mode 100644 index 0000000..aa193e9 --- /dev/null +++ b/src/main/kotlin/com/dansplugins/fiefs/fief/Fief.kt @@ -0,0 +1,31 @@ +package com.dansplugins.fiefs.fief + +import java.util.UUID + +class Fief(private val name: String, private val ownerUUID: UUID) { + private var members: MutableList = mutableListOf() + + fun addMember(uuid: UUID) { + members.add(uuid) + } + + fun removeMember(uuid: UUID) { + members.remove(uuid) + } + + fun isMember(uuid: UUID): Boolean { + return members.contains(uuid) + } + + fun getMembers(): List { + return members + } + + fun getOwnerUUID(): UUID { + return ownerUUID + } + + fun getName(): String { + return name + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/dansplugins/fiefs/fief/FiefFactory.kt b/src/main/kotlin/com/dansplugins/fiefs/fief/FiefFactory.kt new file mode 100644 index 0000000..6a8860f --- /dev/null +++ b/src/main/kotlin/com/dansplugins/fiefs/fief/FiefFactory.kt @@ -0,0 +1,14 @@ +package com.dansplugins.fiefs.fief + +import com.dansplugins.fiefs.Fiefs +import com.dansplugins.fiefs.fief.Fief +import java.util.UUID + +/** + * Creates instances of the Fief class. + */ +class FiefFactory(private val plugin: Fiefs) { + fun createFief(name: String, ownerUUID: UUID): Fief { + return Fief(name, ownerUUID) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/dansplugins/fiefs/fief/FiefRepository.kt b/src/main/kotlin/com/dansplugins/fiefs/fief/FiefRepository.kt new file mode 100644 index 0000000..9df1b36 --- /dev/null +++ b/src/main/kotlin/com/dansplugins/fiefs/fief/FiefRepository.kt @@ -0,0 +1,48 @@ +package com.dansplugins.fiefs.fief + +import com.dansplugins.fiefs.Fiefs + +/** + * Stores all Fiefs in a list and provides methods for accessing and modifying the list. + */ +class FiefRepository(private val plugin: Fiefs) { + private val fiefs = mutableListOf() + + /** + * Adds a Fief to the list. + * @param fief The Fief to add. + */ + fun addFief(fief: Fief) { + fiefs.add(fief) + } + + /** + * Removes a Fief from the list. + * @param fief The Fief to remove. + */ + fun removeFief(fief: Fief) { + fiefs.remove(fief) + } + + /** + * Gets a Fief from the list. + * @param name The name of the Fief to get. + * @return The Fief with the given name. + */ + fun getFief(name: String): Fief? { + for (fief in fiefs) { + if (fief.getName() == name) { + return fief + } + } + return null + } + + /** + * Gets a list of all Fiefs. + * @return A list of all Fiefs. + */ + fun getFiefs(): List { + return fiefs + } +} \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index b771ac9..6a1caaf 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -14,4 +14,11 @@ commands: permissions: fiefs.help: - default: true \ No newline at end of file + default: true + description: Allows the player to view the help menu. + fiefs.create: + default: true + description: Allows the player to create a fief. + fiefs.list: + default: true + description: Allows the player to view a list of all fiefs. \ No newline at end of file From e78612319ab3f07fb20e4f8ec73171b48fff8161 Mon Sep 17 00:00:00 2001 From: dmccoystephenson Date: Wed, 1 Mar 2023 19:23:42 -0700 Subject: [PATCH 02/19] Added unit tests for 'fief' package. --- .../kotlin/com/dansplugins/fiefs/fief/Fief.kt | 5 ++ .../dansplugins/fiefs/fief/FiefRepository.kt | 15 +++++ .../com/dansplugins/fiefs/fief/TestFief.kt | 46 +++++++++++++++ .../dansplugins/fiefs/fief/TestFiefFactory.kt | 24 ++++++++ .../fiefs/fief/TestFiefRepository.kt | 56 +++++++++++++++++++ 5 files changed, 146 insertions(+) create mode 100644 src/test/kotlin/com/dansplugins/fiefs/fief/TestFief.kt create mode 100644 src/test/kotlin/com/dansplugins/fiefs/fief/TestFiefFactory.kt create mode 100644 src/test/kotlin/com/dansplugins/fiefs/fief/TestFiefRepository.kt diff --git a/src/main/kotlin/com/dansplugins/fiefs/fief/Fief.kt b/src/main/kotlin/com/dansplugins/fiefs/fief/Fief.kt index aa193e9..7ce9ebc 100644 --- a/src/main/kotlin/com/dansplugins/fiefs/fief/Fief.kt +++ b/src/main/kotlin/com/dansplugins/fiefs/fief/Fief.kt @@ -3,8 +3,13 @@ package com.dansplugins.fiefs.fief import java.util.UUID class Fief(private val name: String, private val ownerUUID: UUID) { + private var uuid = UUID.randomUUID() private var members: MutableList = mutableListOf() + fun getId(): UUID { + return uuid + } + fun addMember(uuid: UUID) { members.add(uuid) } diff --git a/src/main/kotlin/com/dansplugins/fiefs/fief/FiefRepository.kt b/src/main/kotlin/com/dansplugins/fiefs/fief/FiefRepository.kt index 9df1b36..539377f 100644 --- a/src/main/kotlin/com/dansplugins/fiefs/fief/FiefRepository.kt +++ b/src/main/kotlin/com/dansplugins/fiefs/fief/FiefRepository.kt @@ -1,6 +1,7 @@ package com.dansplugins.fiefs.fief import com.dansplugins.fiefs.Fiefs +import java.util.* /** * Stores all Fiefs in a list and provides methods for accessing and modifying the list. @@ -38,6 +39,20 @@ class FiefRepository(private val plugin: Fiefs) { return null } + /** + * Gets a Fief from the list. + * @param uuid The UUID of the Fief to get. + * @return The Fief with the given UUID. + */ + fun getFief(uuid: UUID): Fief? { + for (fief in fiefs) { + if (fief.getId() == uuid) { + return fief + } + } + return null + } + /** * Gets a list of all Fiefs. * @return A list of all Fiefs. diff --git a/src/test/kotlin/com/dansplugins/fiefs/fief/TestFief.kt b/src/test/kotlin/com/dansplugins/fiefs/fief/TestFief.kt new file mode 100644 index 0000000..326143e --- /dev/null +++ b/src/test/kotlin/com/dansplugins/fiefs/fief/TestFief.kt @@ -0,0 +1,46 @@ +package com.dansplugins.fiefs.fief + +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test +import java.util.* + +class TestFief { + + @Test + fun testInitialization() { + val uuid = UUID.randomUUID() + val fief = Fief("testFief", uuid) + assertEquals("testFief", fief.getName()) + assertEquals(uuid, fief.getOwnerUUID()) + assertEquals(0, fief.getMembers().size) + } + + @Test + fun testAddMember() { + val uuid = UUID.randomUUID() + val fief = Fief("testFief", uuid) + val memberUUID = UUID.randomUUID() + fief.addMember(memberUUID) + assertEquals(1, fief.getMembers().size) + assertEquals(memberUUID, fief.getMembers()[0]) + } + + @Test + fun testRemoveMember() { + val uuid = UUID.randomUUID() + val fief = Fief("testFief", uuid) + val memberUUID = UUID.randomUUID() + fief.addMember(memberUUID) + fief.removeMember(memberUUID) + assertEquals(0, fief.getMembers().size) + } + + @Test + fun testIsMember() { + val uuid = UUID.randomUUID() + val fief = Fief("testFief", uuid) + val memberUUID = UUID.randomUUID() + fief.addMember(memberUUID) + assertEquals(true, fief.isMember(memberUUID)) + } +} \ No newline at end of file diff --git a/src/test/kotlin/com/dansplugins/fiefs/fief/TestFiefFactory.kt b/src/test/kotlin/com/dansplugins/fiefs/fief/TestFiefFactory.kt new file mode 100644 index 0000000..97898ad --- /dev/null +++ b/src/test/kotlin/com/dansplugins/fiefs/fief/TestFiefFactory.kt @@ -0,0 +1,24 @@ +package com.dansplugins.fiefs.fief + +import com.dansplugins.fiefs.Fiefs +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test + +// import mockk +import io.mockk.every +import io.mockk.mockk +import java.util.* + +class TestFiefFactory { + + @Test + fun testCreateFief() { + val plugin = mockk() + val fiefFactory = FiefFactory(plugin) + val uuid = UUID.randomUUID() + val fief = fiefFactory.createFief("testFief", uuid) + assertEquals("testFief", fief.getName()) + assertEquals(uuid, fief.getOwnerUUID()) + assertEquals(0, fief.getMembers().size) + } +} \ No newline at end of file diff --git a/src/test/kotlin/com/dansplugins/fiefs/fief/TestFiefRepository.kt b/src/test/kotlin/com/dansplugins/fiefs/fief/TestFiefRepository.kt new file mode 100644 index 0000000..354dc9b --- /dev/null +++ b/src/test/kotlin/com/dansplugins/fiefs/fief/TestFiefRepository.kt @@ -0,0 +1,56 @@ +package com.dansplugins.fiefs.fief + +import com.dansplugins.fiefs.Fiefs +import io.mockk.mockk +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test +import java.util.* + +class TestFiefRepository { + + @Test + fun testInitialization() { + val mockPlugin = mockk() + val fiefRepository = FiefRepository(mockPlugin) + assertEquals(0, fiefRepository.getFiefs().size) + } + + @Test + fun testAddFief() { + val mockPlugin = mockk() + val fiefRepository = FiefRepository(mockPlugin) + val fief = Fief("testFief", UUID.randomUUID()) + fiefRepository.addFief(fief) + assertEquals(1, fiefRepository.getFiefs().size) + assertEquals(fief, fiefRepository.getFiefs()[0]) + } + + @Test + fun testRemoveFief() { + val mockPlugin = mockk() + val fiefRepository = FiefRepository(mockPlugin) + val fief = Fief("testFief", UUID.randomUUID()) + fiefRepository.addFief(fief) + fiefRepository.removeFief(fief) + assertEquals(0, fiefRepository.getFiefs().size) + } + + @Test + fun testGetFiefByName() { + val mockPlugin = mockk() + val fiefRepository = FiefRepository(mockPlugin) + val fief = Fief("testFief", UUID.randomUUID()) + fiefRepository.addFief(fief) + assertEquals(fief, fiefRepository.getFief("testFief")) + } + + @Test + fun testGetFiefByUUID() { + val mockPlugin = mockk() + val fiefRepository = FiefRepository(mockPlugin) + val uuid = UUID.randomUUID() + val fief = Fief("testFief", uuid) + fiefRepository.addFief(fief) + assertEquals(fief, fiefRepository.getFief(uuid)) + } +} \ No newline at end of file From 9014360259c004102db0ea82e636bfda576b2c37 Mon Sep 17 00:00:00 2001 From: dmccoystephenson Date: Wed, 1 Mar 2023 19:51:55 -0700 Subject: [PATCH 03/19] Added tests for FiefsCommand class. --- .../fiefs/command/TestFiefsCommand.kt | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/test/kotlin/com/dansplugins/fiefs/command/TestFiefsCommand.kt diff --git a/src/test/kotlin/com/dansplugins/fiefs/command/TestFiefsCommand.kt b/src/test/kotlin/com/dansplugins/fiefs/command/TestFiefsCommand.kt new file mode 100644 index 0000000..ae3ae9f --- /dev/null +++ b/src/test/kotlin/com/dansplugins/fiefs/command/TestFiefsCommand.kt @@ -0,0 +1,60 @@ +package com.dansplugins.fiefs.command + +import com.dansplugins.fiefs.Fiefs +import com.dansplugins.fiefs.command.fiefs.FiefsCommand +import io.mockk.every +import io.mockk.mockk +import io.mockk.verify +import org.bukkit.command.Command +import org.bukkit.command.CommandSender +import org.junit.jupiter.api.Test + +class TestFiefsCommand { + + private fun createMockPlugin(): Fiefs { + val mockPlugin = mockk() { + every { description.version } returns "1.0.0" + every { description.authors } returns listOf("Dan") + every { description.description } returns "A plugin about fiefs." + } + return mockPlugin + } + + @Test + fun testFiefsCommandNoArguments() { + // prepare + val mockPlugin = createMockPlugin() + val mockSender = mockk() { + every { sendMessage(any()) } returns Unit + } + val mockCommand = mockk() + val args = emptyArray() + val label = "fiefs" + val fiefsCommand = FiefsCommand(mockPlugin) + + // execute + fiefsCommand.onCommand(mockSender, mockCommand, label, args) + + // verify + verify { mockSender.sendMessage(any()); } + } + + @Test + fun testFiefsCommandHelpArgument() { + // prepare + val mockPlugin = createMockPlugin() + val mockSender = mockk() { + every { sendMessage(any()) } returns Unit + } + val mockCommand = mockk() + val args = arrayOf("help") + val label = "fiefs" + val fiefsCommand = FiefsCommand(mockPlugin) + + // execute + fiefsCommand.onCommand(mockSender, mockCommand, label, args) + + // verify + verify { mockSender.sendMessage(any()); } + } +} \ No newline at end of file From 74bebc999593f2f51da12e1b0c6796f2f6f463d9 Mon Sep 17 00:00:00 2001 From: dmccoystephenson Date: Wed, 1 Mar 2023 20:02:47 -0700 Subject: [PATCH 04/19] Implemented the create & list commands. --- .../fiefs/create/FiefsCreateCommand.kt | 21 +++++++++++++++++-- .../command/fiefs/list/FiefsListCommand.kt | 2 +- .../fiefs/fief/TestFiefRepository.kt | 3 ++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/create/FiefsCreateCommand.kt b/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/create/FiefsCreateCommand.kt index b687f7e..dba22de 100644 --- a/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/create/FiefsCreateCommand.kt +++ b/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/create/FiefsCreateCommand.kt @@ -5,10 +5,27 @@ import org.bukkit.command.Command import org.bukkit.command.CommandExecutor import org.bukkit.command.CommandSender import org.bukkit.command.TabCompleter +import org.bukkit.entity.Player class FiefsCreateCommand(private val plugin: Fiefs) : CommandExecutor, TabCompleter { override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array): Boolean { - TODO("Not yet implemented") + if (sender !is Player) { + sender.sendMessage("This command can only be run by a player.") + return false + } + val name = args.firstOrNull() + if (name == null) { + sender.sendMessage("Please specify a name for the fief.") + return false + } + if (plugin.fiefRepository.getFief(name) != null) { + sender.sendMessage("A fief with that name already exists.") + return false + } + val fief = plugin.fiefFactory.createFief(name, sender.uniqueId) + plugin.fiefRepository.addFief(fief) + sender.sendMessage("Fief created.") + return true } override fun onTabComplete( @@ -17,6 +34,6 @@ class FiefsCreateCommand(private val plugin: Fiefs) : CommandExecutor, TabComple alias: String, args: Array ): MutableList? { - TODO("Not yet implemented") + return null } } \ No newline at end of file diff --git a/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/list/FiefsListCommand.kt b/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/list/FiefsListCommand.kt index e9a0d5b..7e85d5c 100644 --- a/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/list/FiefsListCommand.kt +++ b/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/list/FiefsListCommand.kt @@ -21,7 +21,7 @@ class FiefsListCommand(private val plugin: Fiefs) : CommandExecutor, TabComplete alias: String, args: Array ): MutableList? { - TODO("Not yet implemented") + return null } } \ No newline at end of file diff --git a/src/test/kotlin/com/dansplugins/fiefs/fief/TestFiefRepository.kt b/src/test/kotlin/com/dansplugins/fiefs/fief/TestFiefRepository.kt index 354dc9b..fe60334 100644 --- a/src/test/kotlin/com/dansplugins/fiefs/fief/TestFiefRepository.kt +++ b/src/test/kotlin/com/dansplugins/fiefs/fief/TestFiefRepository.kt @@ -50,7 +50,8 @@ class TestFiefRepository { val fiefRepository = FiefRepository(mockPlugin) val uuid = UUID.randomUUID() val fief = Fief("testFief", uuid) + val fiefId = fief.getId() fiefRepository.addFief(fief) - assertEquals(fief, fiefRepository.getFief(uuid)) + assertEquals(fief, fiefRepository.getFief(fiefId)) } } \ No newline at end of file From 9adfe1ab1d81caae56b15f876cc41844fc67a5ba Mon Sep 17 00:00:00 2001 From: dmccoystephenson Date: Wed, 1 Mar 2023 21:42:23 -0700 Subject: [PATCH 05/19] Modified message colors for create & list commands. --- .../fiefs/command/fiefs/create/FiefsCreateCommand.kt | 7 ++++--- .../fiefs/command/fiefs/list/FiefsListCommand.kt | 9 +++++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/create/FiefsCreateCommand.kt b/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/create/FiefsCreateCommand.kt index dba22de..7a63a59 100644 --- a/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/create/FiefsCreateCommand.kt +++ b/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/create/FiefsCreateCommand.kt @@ -1,6 +1,7 @@ package com.dansplugins.fiefs.command.fiefs.create import com.dansplugins.fiefs.Fiefs +import org.bukkit.ChatColor import org.bukkit.command.Command import org.bukkit.command.CommandExecutor import org.bukkit.command.CommandSender @@ -15,16 +16,16 @@ class FiefsCreateCommand(private val plugin: Fiefs) : CommandExecutor, TabComple } val name = args.firstOrNull() if (name == null) { - sender.sendMessage("Please specify a name for the fief.") + sender.sendMessage("${ChatColor.RED}" + "Please specify a name for the fief.") return false } if (plugin.fiefRepository.getFief(name) != null) { - sender.sendMessage("A fief with that name already exists.") + sender.sendMessage("${ChatColor.RED}" + "A fief with that name already exists.") return false } val fief = plugin.fiefFactory.createFief(name, sender.uniqueId) plugin.fiefRepository.addFief(fief) - sender.sendMessage("Fief created.") + sender.sendMessage("${ChatColor.RED}" + "Fief created.") return true } diff --git a/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/list/FiefsListCommand.kt b/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/list/FiefsListCommand.kt index 7e85d5c..5e53872 100644 --- a/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/list/FiefsListCommand.kt +++ b/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/list/FiefsListCommand.kt @@ -1,6 +1,7 @@ package com.dansplugins.fiefs.command.fiefs.list import com.dansplugins.fiefs.Fiefs +import org.bukkit.ChatColor import org.bukkit.command.Command import org.bukkit.command.CommandExecutor import org.bukkit.command.CommandSender @@ -8,9 +9,13 @@ import org.bukkit.command.TabCompleter class FiefsListCommand(private val plugin: Fiefs) : CommandExecutor, TabCompleter { override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array): Boolean { - sender.sendMessage("=== Fiefs ===") + if (plugin.fiefRepository.getFiefs().isEmpty()) { + sender.sendMessage("${ChatColor.RED}" + "There are no fiefs.") + return false + } + sender.sendMessage("${ChatColor.AQUA}" + "=== Fiefs ===") for (fief in plugin.fiefRepository.getFiefs()) { - sender.sendMessage(fief.getName()) + sender.sendMessage("${ChatColor.AQUA}" + fief.getName()) } return true } From dc7ceace7cbfb32db84e9808356e2ae985282a6d Mon Sep 17 00:00:00 2001 From: dmccoystephenson Date: Wed, 1 Mar 2023 22:08:48 -0700 Subject: [PATCH 06/19] Required players to be in a faction and not already be in a fief in order to create a fief. --- .../fiefs/create/FiefsCreateCommand.kt | 22 ++++++++++++++++--- .../kotlin/com/dansplugins/fiefs/fief/Fief.kt | 2 +- .../dansplugins/fiefs/fief/FiefRepository.kt | 15 +++++++++++++ src/main/resources/plugin.yml | 1 - .../com/dansplugins/fiefs/fief/TestFief.kt | 1 + .../fiefs/fief/TestFiefRepository.kt | 11 ++++++++++ 6 files changed, 47 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/create/FiefsCreateCommand.kt b/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/create/FiefsCreateCommand.kt index 7a63a59..5b4874d 100644 --- a/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/create/FiefsCreateCommand.kt +++ b/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/create/FiefsCreateCommand.kt @@ -23,9 +23,25 @@ class FiefsCreateCommand(private val plugin: Fiefs) : CommandExecutor, TabComple sender.sendMessage("${ChatColor.RED}" + "A fief with that name already exists.") return false } - val fief = plugin.fiefFactory.createFief(name, sender.uniqueId) - plugin.fiefRepository.addFief(fief) - sender.sendMessage("${ChatColor.RED}" + "Fief created.") + + // player must be in a faction + val mfPlayer = plugin.medievalFactions.services.playerService.getPlayer(sender) + val faction = plugin.medievalFactions.services.factionService.getFaction(mfPlayer?.id ?: return false) + if (faction == null) { + sender.sendMessage("${ChatColor.RED}" + "You must be in a faction to create a fief.") + return false + } + + // player must not be in a fief already + val playersFief = plugin.fiefRepository.getPlayersFief(sender.uniqueId) + if (playersFief != null) { + sender.sendMessage("${ChatColor.RED}" + "You're already in a fief. You must leave it first.") + return false + } + + val newFief = plugin.fiefFactory.createFief(name, sender.uniqueId) + plugin.fiefRepository.addFief(newFief) + sender.sendMessage("${ChatColor.GREEN}" + "Fief created.") return true } diff --git a/src/main/kotlin/com/dansplugins/fiefs/fief/Fief.kt b/src/main/kotlin/com/dansplugins/fiefs/fief/Fief.kt index 7ce9ebc..d55017a 100644 --- a/src/main/kotlin/com/dansplugins/fiefs/fief/Fief.kt +++ b/src/main/kotlin/com/dansplugins/fiefs/fief/Fief.kt @@ -19,7 +19,7 @@ class Fief(private val name: String, private val ownerUUID: UUID) { } fun isMember(uuid: UUID): Boolean { - return members.contains(uuid) + return members.contains(uuid) || ownerUUID == uuid } fun getMembers(): List { diff --git a/src/main/kotlin/com/dansplugins/fiefs/fief/FiefRepository.kt b/src/main/kotlin/com/dansplugins/fiefs/fief/FiefRepository.kt index 539377f..dff4ec2 100644 --- a/src/main/kotlin/com/dansplugins/fiefs/fief/FiefRepository.kt +++ b/src/main/kotlin/com/dansplugins/fiefs/fief/FiefRepository.kt @@ -53,6 +53,21 @@ class FiefRepository(private val plugin: Fiefs) { return null } + /** + * Gets a player's fief from the list. + * @param playerUUID The UUID of the player whose fief to get. + * @return The Fief which the player is a member of. + * @return null if the player is not a member of any fief. + */ + fun getPlayersFief(playerUUID: UUID): Fief? { + for (fief in fiefs) { + if (fief.isMember(playerUUID)) { + return fief + } + } + return null + } + /** * Gets a list of all Fiefs. * @return A list of all Fiefs. diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 6a1caaf..f38a74c 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -9,7 +9,6 @@ description: An expansion for Medieval Factions that allows faction members to c commands: fiefs: description: The main command for Fiefs. - usage: /fiefs aliases: [fi] permissions: diff --git a/src/test/kotlin/com/dansplugins/fiefs/fief/TestFief.kt b/src/test/kotlin/com/dansplugins/fiefs/fief/TestFief.kt index 326143e..d2e1d1e 100644 --- a/src/test/kotlin/com/dansplugins/fiefs/fief/TestFief.kt +++ b/src/test/kotlin/com/dansplugins/fiefs/fief/TestFief.kt @@ -13,6 +13,7 @@ class TestFief { assertEquals("testFief", fief.getName()) assertEquals(uuid, fief.getOwnerUUID()) assertEquals(0, fief.getMembers().size) + assertEquals(fief.isMember(uuid), true) } @Test diff --git a/src/test/kotlin/com/dansplugins/fiefs/fief/TestFiefRepository.kt b/src/test/kotlin/com/dansplugins/fiefs/fief/TestFiefRepository.kt index fe60334..5cb8f36 100644 --- a/src/test/kotlin/com/dansplugins/fiefs/fief/TestFiefRepository.kt +++ b/src/test/kotlin/com/dansplugins/fiefs/fief/TestFiefRepository.kt @@ -54,4 +54,15 @@ class TestFiefRepository { fiefRepository.addFief(fief) assertEquals(fief, fiefRepository.getFief(fiefId)) } + + @Test + fun testGetFiefByPlayerUUID() { + val mockPlugin = mockk() + val fiefRepository = FiefRepository(mockPlugin) + val fief = Fief("testFief", UUID.randomUUID()) + val playerUUID = UUID.randomUUID() + fief.addMember(playerUUID) + fiefRepository.addFief(fief) + assertEquals(fief, fiefRepository.getPlayersFief(playerUUID)) + } } \ No newline at end of file From 72e1aabfa40b5fa95ee234f288c168a4e0e207cb Mon Sep 17 00:00:00 2001 From: dmccoystephenson Date: Sun, 5 Mar 2023 00:59:01 -0700 Subject: [PATCH 07/19] Made a message red. --- .../fiefs/command/fiefs/create/FiefsCreateCommand.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/create/FiefsCreateCommand.kt b/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/create/FiefsCreateCommand.kt index 5b4874d..41178ff 100644 --- a/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/create/FiefsCreateCommand.kt +++ b/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/create/FiefsCreateCommand.kt @@ -11,7 +11,7 @@ import org.bukkit.entity.Player class FiefsCreateCommand(private val plugin: Fiefs) : CommandExecutor, TabCompleter { override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array): Boolean { if (sender !is Player) { - sender.sendMessage("This command can only be run by a player.") + sender.sendMessage("${ChatColor.RED}" + "This command can only be run by a player.") return false } val name = args.firstOrNull() From bca28b9388799d87000ecca5c22b76a01654dfad Mon Sep 17 00:00:00 2001 From: dmccoystephenson Date: Sun, 5 Mar 2023 01:03:53 -0700 Subject: [PATCH 08/19] Modified chatcolor formatting for messages. --- .../dansplugins/fiefs/command/fiefs/FiefsCommand.kt | 11 +++++------ .../fiefs/command/fiefs/create/FiefsCreateCommand.kt | 12 ++++++------ .../fiefs/command/fiefs/help/FiefsHelpCommand.kt | 10 +++++----- .../fiefs/command/fiefs/list/FiefsListCommand.kt | 4 ++-- 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/FiefsCommand.kt b/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/FiefsCommand.kt index 02a7434..4415805 100644 --- a/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/FiefsCommand.kt +++ b/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/FiefsCommand.kt @@ -4,8 +4,7 @@ import com.dansplugins.fiefs.Fiefs import com.dansplugins.fiefs.command.fiefs.create.FiefsCreateCommand import com.dansplugins.fiefs.command.fiefs.help.FiefsHelpCommand import com.dansplugins.fiefs.command.fiefs.list.FiefsListCommand -import org.bukkit.ChatColor.AQUA -import org.bukkit.ChatColor.GREEN +import org.bukkit.ChatColor import org.bukkit.command.Command import org.bukkit.command.CommandExecutor import org.bukkit.command.CommandSender @@ -29,12 +28,12 @@ class FiefsCommand(private val plugin: Fiefs) : CommandExecutor, TabCompleter { "list" -> listCommand.onCommand(sender, command, label, args.drop(1).toTypedArray()) else -> { // send plugin information - sender.sendMessage("$AQUA" + "Fiefs v${plugin.description.version}") - sender.sendMessage("$AQUA" + "Author: ${plugin.description.authors}") - sender.sendMessage("$AQUA" + "Description: ${plugin.description.description}") + sender.sendMessage("${ChatColor.AQUA}Fiefs v${plugin.description.version}") + sender.sendMessage("${ChatColor.AQUA}Author: ${plugin.description.authors}") + sender.sendMessage("${ChatColor.AQUA}Description: ${plugin.description.description}") // send help message - sender.sendMessage("$GREEN" + "Type /fiefs help for a list of commands.") + sender.sendMessage("${ChatColor.GREEN}Type /fiefs help for a list of commands.") return true } } diff --git a/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/create/FiefsCreateCommand.kt b/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/create/FiefsCreateCommand.kt index 41178ff..3b1580b 100644 --- a/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/create/FiefsCreateCommand.kt +++ b/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/create/FiefsCreateCommand.kt @@ -11,16 +11,16 @@ import org.bukkit.entity.Player class FiefsCreateCommand(private val plugin: Fiefs) : CommandExecutor, TabCompleter { override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array): Boolean { if (sender !is Player) { - sender.sendMessage("${ChatColor.RED}" + "This command can only be run by a player.") + sender.sendMessage("${ChatColor.RED}This command can only be run by a player.") return false } val name = args.firstOrNull() if (name == null) { - sender.sendMessage("${ChatColor.RED}" + "Please specify a name for the fief.") + sender.sendMessage("${ChatColor.RED}Please specify a name for the fief.") return false } if (plugin.fiefRepository.getFief(name) != null) { - sender.sendMessage("${ChatColor.RED}" + "A fief with that name already exists.") + sender.sendMessage("${ChatColor.RED}A fief with that name already exists.") return false } @@ -28,20 +28,20 @@ class FiefsCreateCommand(private val plugin: Fiefs) : CommandExecutor, TabComple val mfPlayer = plugin.medievalFactions.services.playerService.getPlayer(sender) val faction = plugin.medievalFactions.services.factionService.getFaction(mfPlayer?.id ?: return false) if (faction == null) { - sender.sendMessage("${ChatColor.RED}" + "You must be in a faction to create a fief.") + sender.sendMessage("${ChatColor.RED}You must be in a faction to create a fief.") return false } // player must not be in a fief already val playersFief = plugin.fiefRepository.getPlayersFief(sender.uniqueId) if (playersFief != null) { - sender.sendMessage("${ChatColor.RED}" + "You're already in a fief. You must leave it first.") + sender.sendMessage("${ChatColor.RED}You're already in a fief. You must leave it first.") return false } val newFief = plugin.fiefFactory.createFief(name, sender.uniqueId) plugin.fiefRepository.addFief(newFief) - sender.sendMessage("${ChatColor.GREEN}" + "Fief created.") + sender.sendMessage("${ChatColor.GREEN}Fief created.") return true } diff --git a/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/help/FiefsHelpCommand.kt b/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/help/FiefsHelpCommand.kt index 56f026d..816d6cb 100644 --- a/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/help/FiefsHelpCommand.kt +++ b/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/help/FiefsHelpCommand.kt @@ -1,7 +1,7 @@ package com.dansplugins.fiefs.command.fiefs.help import com.dansplugins.fiefs.Fiefs -import org.bukkit.ChatColor.AQUA +import org.bukkit.ChatColor import org.bukkit.command.Command import org.bukkit.command.CommandExecutor import org.bukkit.command.CommandSender @@ -10,10 +10,10 @@ import org.bukkit.command.TabCompleter class FiefsHelpCommand(private val plugin: Fiefs) : CommandExecutor, TabCompleter { override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array): Boolean { // send list of commands - sender.sendMessage("${AQUA}=== Fiefs Commands ===") - sender.sendMessage("${AQUA}/fiefs help - Displays a list of useful commands.") - sender.sendMessage("${AQUA}/fiefs create - Creates a fief.") - sender.sendMessage("${AQUA}/fiefs list - Lists all fiefs.") + sender.sendMessage("${ChatColor.AQUA}=== Fiefs Commands ===") + sender.sendMessage("${ChatColor.AQUA}/fiefs help - Displays a list of useful commands.") + sender.sendMessage("${ChatColor.AQUA}/fiefs create - Creates a fief.") + sender.sendMessage("${ChatColor.AQUA}/fiefs list - Lists all fiefs.") return true } diff --git a/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/list/FiefsListCommand.kt b/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/list/FiefsListCommand.kt index 5e53872..acc0afb 100644 --- a/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/list/FiefsListCommand.kt +++ b/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/list/FiefsListCommand.kt @@ -10,10 +10,10 @@ import org.bukkit.command.TabCompleter class FiefsListCommand(private val plugin: Fiefs) : CommandExecutor, TabCompleter { override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array): Boolean { if (plugin.fiefRepository.getFiefs().isEmpty()) { - sender.sendMessage("${ChatColor.RED}" + "There are no fiefs.") + sender.sendMessage("${ChatColor.RED}There are no fiefs.") return false } - sender.sendMessage("${ChatColor.AQUA}" + "=== Fiefs ===") + sender.sendMessage("${ChatColor.AQUA}=== Fiefs ===") for (fief in plugin.fiefRepository.getFiefs()) { sender.sendMessage("${ChatColor.AQUA}" + fief.getName()) } From b2f3e2cf55c78dca2ecc6a7885192036012189b0 Mon Sep 17 00:00:00 2001 From: dmccoystephenson Date: Thu, 9 Mar 2023 21:10:49 -0700 Subject: [PATCH 09/19] Extended base command description in plugin.yml --- src/main/resources/plugin.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index f38a74c..bf943f4 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -8,7 +8,7 @@ description: An expansion for Medieval Factions that allows faction members to c commands: fiefs: - description: The main command for Fiefs. + description: The main command for Fiefs. Subcommands include:: help, create, list aliases: [fi] permissions: From ecc19741e6fe47fb090eec575ea8557e780079ca Mon Sep 17 00:00:00 2001 From: dmccoystephenson Date: Thu, 9 Mar 2023 21:12:58 -0700 Subject: [PATCH 10/19] Made mock plugin a class field in TestFiefsCommand.kt --- .../dansplugins/fiefs/command/TestFiefsCommand.kt | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/test/kotlin/com/dansplugins/fiefs/command/TestFiefsCommand.kt b/src/test/kotlin/com/dansplugins/fiefs/command/TestFiefsCommand.kt index ae3ae9f..5f90141 100644 --- a/src/test/kotlin/com/dansplugins/fiefs/command/TestFiefsCommand.kt +++ b/src/test/kotlin/com/dansplugins/fiefs/command/TestFiefsCommand.kt @@ -11,19 +11,15 @@ import org.junit.jupiter.api.Test class TestFiefsCommand { - private fun createMockPlugin(): Fiefs { - val mockPlugin = mockk() { - every { description.version } returns "1.0.0" - every { description.authors } returns listOf("Dan") - every { description.description } returns "A plugin about fiefs." - } - return mockPlugin + private val mockPlugin = mockk() { + every { description.version } returns "1.0.0" + every { description.authors } returns listOf("Dan") + every { description.description } returns "A plugin about fiefs." } @Test fun testFiefsCommandNoArguments() { // prepare - val mockPlugin = createMockPlugin() val mockSender = mockk() { every { sendMessage(any()) } returns Unit } @@ -42,7 +38,6 @@ class TestFiefsCommand { @Test fun testFiefsCommandHelpArgument() { // prepare - val mockPlugin = createMockPlugin() val mockSender = mockk() { every { sendMessage(any()) } returns Unit } From bc56e81f49ff614499d12e28c1a786bc88837aa1 Mon Sep 17 00:00:00 2001 From: dmccoystephenson Date: Thu, 9 Mar 2023 21:15:15 -0700 Subject: [PATCH 11/19] Switched order of some arguments to assertEquals() in TestFief.kt --- src/test/kotlin/com/dansplugins/fiefs/fief/TestFief.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/kotlin/com/dansplugins/fiefs/fief/TestFief.kt b/src/test/kotlin/com/dansplugins/fiefs/fief/TestFief.kt index d2e1d1e..434ba28 100644 --- a/src/test/kotlin/com/dansplugins/fiefs/fief/TestFief.kt +++ b/src/test/kotlin/com/dansplugins/fiefs/fief/TestFief.kt @@ -13,7 +13,7 @@ class TestFief { assertEquals("testFief", fief.getName()) assertEquals(uuid, fief.getOwnerUUID()) assertEquals(0, fief.getMembers().size) - assertEquals(fief.isMember(uuid), true) + assertEquals(true, fief.isMember(uuid)) } @Test @@ -22,7 +22,7 @@ class TestFief { val fief = Fief("testFief", uuid) val memberUUID = UUID.randomUUID() fief.addMember(memberUUID) - assertEquals(1, fief.getMembers().size) + assertEquals(fief.getMembers().size, 1) assertEquals(memberUUID, fief.getMembers()[0]) } From 534e22c6b035b71ccfc8ad66c0c4f3e71b007b7a Mon Sep 17 00:00:00 2001 From: dmccoystephenson Date: Thu, 9 Mar 2023 21:17:11 -0700 Subject: [PATCH 12/19] Cast return value of onTabComplete() method in FiefCommand.kt to List --- .../com/dansplugins/fiefs/command/fiefs/FiefsCommand.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/FiefsCommand.kt b/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/FiefsCommand.kt index 4415805..8d7a1b3 100644 --- a/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/FiefsCommand.kt +++ b/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/FiefsCommand.kt @@ -44,7 +44,7 @@ class FiefsCommand(private val plugin: Fiefs) : CommandExecutor, TabCompleter { command: Command, alias: String, args: Array - ): List? { + ): List { return when (args.size) { 1 -> subcommands.filter { it.startsWith(args[0]) }.toMutableList() else -> when(args.first().lowercase()) { @@ -52,7 +52,7 @@ class FiefsCommand(private val plugin: Fiefs) : CommandExecutor, TabCompleter { "create" -> createCommand.onTabComplete(sender, command, alias, args.drop(1).toTypedArray()) "list" -> listCommand.onTabComplete(sender, command, alias, args.drop(1).toTypedArray()) else -> emptyList() - } + } as List } } From b560da2e2daeee32464bc191e4f2c7c9ce9fd1e8 Mon Sep 17 00:00:00 2001 From: dmccoystephenson Date: Sat, 11 Mar 2023 22:29:23 -0700 Subject: [PATCH 13/19] Removed FiefFactory.kt --- .../kotlin/com/dansplugins/fiefs/Fiefs.kt | 2 -- .../fiefs/create/FiefsCreateCommand.kt | 3 ++- .../kotlin/com/dansplugins/fiefs/fief/Fief.kt | 2 +- .../com/dansplugins/fiefs/fief/FiefFactory.kt | 14 ----------- .../dansplugins/fiefs/fief/TestFiefFactory.kt | 24 ------------------- 5 files changed, 3 insertions(+), 42 deletions(-) delete mode 100644 src/main/kotlin/com/dansplugins/fiefs/fief/FiefFactory.kt delete mode 100644 src/test/kotlin/com/dansplugins/fiefs/fief/TestFiefFactory.kt diff --git a/src/main/kotlin/com/dansplugins/fiefs/Fiefs.kt b/src/main/kotlin/com/dansplugins/fiefs/Fiefs.kt index 600709a..6e2312f 100644 --- a/src/main/kotlin/com/dansplugins/fiefs/Fiefs.kt +++ b/src/main/kotlin/com/dansplugins/fiefs/Fiefs.kt @@ -2,7 +2,6 @@ package com.dansplugins.fiefs import com.dansplugins.factionsystem.MedievalFactions import com.dansplugins.fiefs.command.fiefs.FiefsCommand -import com.dansplugins.fiefs.fief.FiefFactory import com.dansplugins.fiefs.fief.FiefRepository import org.bstats.bukkit.Metrics import org.bukkit.plugin.java.JavaPlugin @@ -11,7 +10,6 @@ class Fiefs : JavaPlugin() { lateinit var medievalFactions: MedievalFactions val fiefRepository = FiefRepository(this) - val fiefFactory = FiefFactory(this) override fun onEnable() { saveDefaultConfig() diff --git a/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/create/FiefsCreateCommand.kt b/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/create/FiefsCreateCommand.kt index 3b1580b..cb2f275 100644 --- a/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/create/FiefsCreateCommand.kt +++ b/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/create/FiefsCreateCommand.kt @@ -1,6 +1,7 @@ package com.dansplugins.fiefs.command.fiefs.create import com.dansplugins.fiefs.Fiefs +import com.dansplugins.fiefs.fief.Fief import org.bukkit.ChatColor import org.bukkit.command.Command import org.bukkit.command.CommandExecutor @@ -39,7 +40,7 @@ class FiefsCreateCommand(private val plugin: Fiefs) : CommandExecutor, TabComple return false } - val newFief = plugin.fiefFactory.createFief(name, sender.uniqueId) + val newFief = Fief(name, sender.uniqueId) plugin.fiefRepository.addFief(newFief) sender.sendMessage("${ChatColor.GREEN}Fief created.") return true diff --git a/src/main/kotlin/com/dansplugins/fiefs/fief/Fief.kt b/src/main/kotlin/com/dansplugins/fiefs/fief/Fief.kt index d55017a..0be60f4 100644 --- a/src/main/kotlin/com/dansplugins/fiefs/fief/Fief.kt +++ b/src/main/kotlin/com/dansplugins/fiefs/fief/Fief.kt @@ -2,7 +2,7 @@ package com.dansplugins.fiefs.fief import java.util.UUID -class Fief(private val name: String, private val ownerUUID: UUID) { +data class Fief(private val name: String, private val ownerUUID: UUID) { private var uuid = UUID.randomUUID() private var members: MutableList = mutableListOf() diff --git a/src/main/kotlin/com/dansplugins/fiefs/fief/FiefFactory.kt b/src/main/kotlin/com/dansplugins/fiefs/fief/FiefFactory.kt deleted file mode 100644 index 6a8860f..0000000 --- a/src/main/kotlin/com/dansplugins/fiefs/fief/FiefFactory.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.dansplugins.fiefs.fief - -import com.dansplugins.fiefs.Fiefs -import com.dansplugins.fiefs.fief.Fief -import java.util.UUID - -/** - * Creates instances of the Fief class. - */ -class FiefFactory(private val plugin: Fiefs) { - fun createFief(name: String, ownerUUID: UUID): Fief { - return Fief(name, ownerUUID) - } -} \ No newline at end of file diff --git a/src/test/kotlin/com/dansplugins/fiefs/fief/TestFiefFactory.kt b/src/test/kotlin/com/dansplugins/fiefs/fief/TestFiefFactory.kt deleted file mode 100644 index 97898ad..0000000 --- a/src/test/kotlin/com/dansplugins/fiefs/fief/TestFiefFactory.kt +++ /dev/null @@ -1,24 +0,0 @@ -package com.dansplugins.fiefs.fief - -import com.dansplugins.fiefs.Fiefs -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Test - -// import mockk -import io.mockk.every -import io.mockk.mockk -import java.util.* - -class TestFiefFactory { - - @Test - fun testCreateFief() { - val plugin = mockk() - val fiefFactory = FiefFactory(plugin) - val uuid = UUID.randomUUID() - val fief = fiefFactory.createFief("testFief", uuid) - assertEquals("testFief", fief.getName()) - assertEquals(uuid, fief.getOwnerUUID()) - assertEquals(0, fief.getMembers().size) - } -} \ No newline at end of file From c9b4c9a8195f953d39a8ab4be251ff44b8dc7d69 Mon Sep 17 00:00:00 2001 From: dmccoystephenson Date: Sat, 11 Mar 2023 22:33:44 -0700 Subject: [PATCH 14/19] Fixed onTabComplete methods. --- .../fiefs/command/fiefs/create/FiefsCreateCommand.kt | 4 ++-- .../dansplugins/fiefs/command/fiefs/list/FiefsListCommand.kt | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/create/FiefsCreateCommand.kt b/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/create/FiefsCreateCommand.kt index cb2f275..412181b 100644 --- a/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/create/FiefsCreateCommand.kt +++ b/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/create/FiefsCreateCommand.kt @@ -51,7 +51,7 @@ class FiefsCreateCommand(private val plugin: Fiefs) : CommandExecutor, TabComple command: Command, alias: String, args: Array - ): MutableList? { - return null + ): List { + return emptyList() } } \ No newline at end of file diff --git a/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/list/FiefsListCommand.kt b/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/list/FiefsListCommand.kt index acc0afb..2e6549f 100644 --- a/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/list/FiefsListCommand.kt +++ b/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/list/FiefsListCommand.kt @@ -25,8 +25,7 @@ class FiefsListCommand(private val plugin: Fiefs) : CommandExecutor, TabComplete command: Command, alias: String, args: Array - ): MutableList? { - return null + ): List { + return emptyList() } - } \ No newline at end of file From a235cd1dd5a7eb1f2abca22d8ac2476bc5edd23e Mon Sep 17 00:00:00 2001 From: dmccoystephenson Date: Sat, 11 Mar 2023 22:35:56 -0700 Subject: [PATCH 15/19] Removed useless cast. --- .../kotlin/com/dansplugins/fiefs/command/fiefs/FiefsCommand.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/FiefsCommand.kt b/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/FiefsCommand.kt index 8d7a1b3..8cc8ff1 100644 --- a/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/FiefsCommand.kt +++ b/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/FiefsCommand.kt @@ -52,7 +52,7 @@ class FiefsCommand(private val plugin: Fiefs) : CommandExecutor, TabCompleter { "create" -> createCommand.onTabComplete(sender, command, alias, args.drop(1).toTypedArray()) "list" -> listCommand.onTabComplete(sender, command, alias, args.drop(1).toTypedArray()) else -> emptyList() - } as List + } } } From 141bbd3d2be7588a7148927521d565df5f973631 Mon Sep 17 00:00:00 2001 From: dmccoystephenson Date: Sat, 11 Mar 2023 22:55:58 -0700 Subject: [PATCH 16/19] Switched over to using MfFactionId instead of UUID to track faction membership. --- .../fiefs/create/FiefsCreateCommand.kt | 4 +-- .../kotlin/com/dansplugins/fiefs/fief/Fief.kt | 23 +++++++------ .../dansplugins/fiefs/fief/FiefRepository.kt | 5 +-- .../com/dansplugins/fiefs/fief/TestFief.kt | 34 +++++++++---------- .../fiefs/fief/TestFiefRepository.kt | 17 +++++----- 5 files changed, 43 insertions(+), 40 deletions(-) diff --git a/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/create/FiefsCreateCommand.kt b/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/create/FiefsCreateCommand.kt index 412181b..0509526 100644 --- a/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/create/FiefsCreateCommand.kt +++ b/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/create/FiefsCreateCommand.kt @@ -34,13 +34,13 @@ class FiefsCreateCommand(private val plugin: Fiefs) : CommandExecutor, TabComple } // player must not be in a fief already - val playersFief = plugin.fiefRepository.getPlayersFief(sender.uniqueId) + val playersFief = plugin.fiefRepository.getPlayersFief(mfPlayer.id) if (playersFief != null) { sender.sendMessage("${ChatColor.RED}You're already in a fief. You must leave it first.") return false } - val newFief = Fief(name, sender.uniqueId) + val newFief = Fief(name, mfPlayer.id) plugin.fiefRepository.addFief(newFief) sender.sendMessage("${ChatColor.GREEN}Fief created.") return true diff --git a/src/main/kotlin/com/dansplugins/fiefs/fief/Fief.kt b/src/main/kotlin/com/dansplugins/fiefs/fief/Fief.kt index 0be60f4..e093897 100644 --- a/src/main/kotlin/com/dansplugins/fiefs/fief/Fief.kt +++ b/src/main/kotlin/com/dansplugins/fiefs/fief/Fief.kt @@ -1,33 +1,34 @@ package com.dansplugins.fiefs.fief +import com.dansplugins.factionsystem.player.MfPlayerId import java.util.UUID -data class Fief(private val name: String, private val ownerUUID: UUID) { +data class Fief(private val name: String, private val ownerMfPlayerId: MfPlayerId) { private var uuid = UUID.randomUUID() - private var members: MutableList = mutableListOf() + private var members: MutableList = mutableListOf() fun getId(): UUID { return uuid } - fun addMember(uuid: UUID) { - members.add(uuid) + fun addMember(mfPlayerId: MfPlayerId) { + members.add(mfPlayerId) } - fun removeMember(uuid: UUID) { - members.remove(uuid) + fun removeMember(mfPlayerId: MfPlayerId) { + members.remove(mfPlayerId) } - fun isMember(uuid: UUID): Boolean { - return members.contains(uuid) || ownerUUID == uuid + fun isMember(mfPlayerId: MfPlayerId): Boolean { + return members.contains(mfPlayerId) || ownerMfPlayerId == mfPlayerId } - fun getMembers(): List { + fun getMembers(): List { return members } - fun getOwnerUUID(): UUID { - return ownerUUID + fun getOwnerId(): MfPlayerId { + return ownerMfPlayerId } fun getName(): String { diff --git a/src/main/kotlin/com/dansplugins/fiefs/fief/FiefRepository.kt b/src/main/kotlin/com/dansplugins/fiefs/fief/FiefRepository.kt index dff4ec2..05f4329 100644 --- a/src/main/kotlin/com/dansplugins/fiefs/fief/FiefRepository.kt +++ b/src/main/kotlin/com/dansplugins/fiefs/fief/FiefRepository.kt @@ -1,5 +1,6 @@ package com.dansplugins.fiefs.fief +import com.dansplugins.factionsystem.player.MfPlayerId import com.dansplugins.fiefs.Fiefs import java.util.* @@ -59,9 +60,9 @@ class FiefRepository(private val plugin: Fiefs) { * @return The Fief which the player is a member of. * @return null if the player is not a member of any fief. */ - fun getPlayersFief(playerUUID: UUID): Fief? { + fun getPlayersFief(mfPlayerId: MfPlayerId): Fief? { for (fief in fiefs) { - if (fief.isMember(playerUUID)) { + if (fief.isMember(mfPlayerId)) { return fief } } diff --git a/src/test/kotlin/com/dansplugins/fiefs/fief/TestFief.kt b/src/test/kotlin/com/dansplugins/fiefs/fief/TestFief.kt index 434ba28..5636465 100644 --- a/src/test/kotlin/com/dansplugins/fiefs/fief/TestFief.kt +++ b/src/test/kotlin/com/dansplugins/fiefs/fief/TestFief.kt @@ -1,5 +1,6 @@ package com.dansplugins.fiefs.fief +import com.dansplugins.factionsystem.player.MfPlayerId import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test import java.util.* @@ -8,40 +9,39 @@ class TestFief { @Test fun testInitialization() { - val uuid = UUID.randomUUID() - val fief = Fief("testFief", uuid) + val mfPlayerId = MfPlayerId("test") + val fief = Fief("testFief", mfPlayerId) assertEquals("testFief", fief.getName()) - assertEquals(uuid, fief.getOwnerUUID()) + assertEquals(mfPlayerId, fief.getOwnerId()) assertEquals(0, fief.getMembers().size) - assertEquals(true, fief.isMember(uuid)) + assertEquals(true, fief.isMember(mfPlayerId)) } @Test fun testAddMember() { - val uuid = UUID.randomUUID() - val fief = Fief("testFief", uuid) - val memberUUID = UUID.randomUUID() - fief.addMember(memberUUID) + val mfPlayerId = MfPlayerId("test") + val fief = Fief("testFief", mfPlayerId) + fief.addMember(mfPlayerId) assertEquals(fief.getMembers().size, 1) - assertEquals(memberUUID, fief.getMembers()[0]) + assertEquals(mfPlayerId, fief.getMembers()[0]) } @Test fun testRemoveMember() { - val uuid = UUID.randomUUID() - val fief = Fief("testFief", uuid) + val mfPlayerId = MfPlayerId("test") + val fief = Fief("testFief", mfPlayerId) val memberUUID = UUID.randomUUID() - fief.addMember(memberUUID) - fief.removeMember(memberUUID) + fief.addMember(mfPlayerId) + fief.removeMember(mfPlayerId) assertEquals(0, fief.getMembers().size) } @Test fun testIsMember() { - val uuid = UUID.randomUUID() - val fief = Fief("testFief", uuid) + val mfPlayerId = MfPlayerId("test") + val fief = Fief("testFief", mfPlayerId) val memberUUID = UUID.randomUUID() - fief.addMember(memberUUID) - assertEquals(true, fief.isMember(memberUUID)) + fief.addMember(mfPlayerId) + assertEquals(true, fief.isMember(mfPlayerId)) } } \ No newline at end of file diff --git a/src/test/kotlin/com/dansplugins/fiefs/fief/TestFiefRepository.kt b/src/test/kotlin/com/dansplugins/fiefs/fief/TestFiefRepository.kt index 5cb8f36..bec5825 100644 --- a/src/test/kotlin/com/dansplugins/fiefs/fief/TestFiefRepository.kt +++ b/src/test/kotlin/com/dansplugins/fiefs/fief/TestFiefRepository.kt @@ -1,5 +1,6 @@ package com.dansplugins.fiefs.fief +import com.dansplugins.factionsystem.player.MfPlayerId import com.dansplugins.fiefs.Fiefs import io.mockk.mockk import org.junit.jupiter.api.Assertions.assertEquals @@ -19,7 +20,7 @@ class TestFiefRepository { fun testAddFief() { val mockPlugin = mockk() val fiefRepository = FiefRepository(mockPlugin) - val fief = Fief("testFief", UUID.randomUUID()) + val fief = Fief("testFief", MfPlayerId("test")) fiefRepository.addFief(fief) assertEquals(1, fiefRepository.getFiefs().size) assertEquals(fief, fiefRepository.getFiefs()[0]) @@ -29,7 +30,7 @@ class TestFiefRepository { fun testRemoveFief() { val mockPlugin = mockk() val fiefRepository = FiefRepository(mockPlugin) - val fief = Fief("testFief", UUID.randomUUID()) + val fief = Fief("testFief", MfPlayerId("test")) fiefRepository.addFief(fief) fiefRepository.removeFief(fief) assertEquals(0, fiefRepository.getFiefs().size) @@ -39,7 +40,7 @@ class TestFiefRepository { fun testGetFiefByName() { val mockPlugin = mockk() val fiefRepository = FiefRepository(mockPlugin) - val fief = Fief("testFief", UUID.randomUUID()) + val fief = Fief("testFief", MfPlayerId("test")) fiefRepository.addFief(fief) assertEquals(fief, fiefRepository.getFief("testFief")) } @@ -49,7 +50,7 @@ class TestFiefRepository { val mockPlugin = mockk() val fiefRepository = FiefRepository(mockPlugin) val uuid = UUID.randomUUID() - val fief = Fief("testFief", uuid) + val fief = Fief("testFief", MfPlayerId("test")) val fiefId = fief.getId() fiefRepository.addFief(fief) assertEquals(fief, fiefRepository.getFief(fiefId)) @@ -59,10 +60,10 @@ class TestFiefRepository { fun testGetFiefByPlayerUUID() { val mockPlugin = mockk() val fiefRepository = FiefRepository(mockPlugin) - val fief = Fief("testFief", UUID.randomUUID()) - val playerUUID = UUID.randomUUID() - fief.addMember(playerUUID) + val fief = Fief("testFief", MfPlayerId("test")) + val playerId = MfPlayerId("test") + fief.addMember(playerId) fiefRepository.addFief(fief) - assertEquals(fief, fiefRepository.getPlayersFief(playerUUID)) + assertEquals(fief, fiefRepository.getPlayersFief(playerId)) } } \ No newline at end of file From 37ba2fe697934e18b1902ed709655ea954a24181 Mon Sep 17 00:00:00 2001 From: dmccoystephenson Date: Sat, 11 Mar 2023 23:09:21 -0700 Subject: [PATCH 17/19] Modified message verification in TestFiefsCommand.kt --- .../fiefs/command/TestFiefsCommand.kt | 26 +++++-------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/src/test/kotlin/com/dansplugins/fiefs/command/TestFiefsCommand.kt b/src/test/kotlin/com/dansplugins/fiefs/command/TestFiefsCommand.kt index 5f90141..db0e430 100644 --- a/src/test/kotlin/com/dansplugins/fiefs/command/TestFiefsCommand.kt +++ b/src/test/kotlin/com/dansplugins/fiefs/command/TestFiefsCommand.kt @@ -5,6 +5,7 @@ import com.dansplugins.fiefs.command.fiefs.FiefsCommand import io.mockk.every import io.mockk.mockk import io.mockk.verify +import org.bukkit.ChatColor import org.bukkit.command.Command import org.bukkit.command.CommandSender import org.junit.jupiter.api.Test @@ -32,24 +33,11 @@ class TestFiefsCommand { fiefsCommand.onCommand(mockSender, mockCommand, label, args) // verify - verify { mockSender.sendMessage(any()); } - } - - @Test - fun testFiefsCommandHelpArgument() { - // prepare - val mockSender = mockk() { - every { sendMessage(any()) } returns Unit - } - val mockCommand = mockk() - val args = arrayOf("help") - val label = "fiefs" - val fiefsCommand = FiefsCommand(mockPlugin) - - // execute - fiefsCommand.onCommand(mockSender, mockCommand, label, args) - - // verify - verify { mockSender.sendMessage(any()); } + val expectedAuthors = mockPlugin.description.authors + val expectedDescription = mockPlugin.description.description + verify(exactly = 1) { mockSender.sendMessage("${ChatColor.AQUA}Fiefs v1.0.0") } + verify(exactly = 1) { mockSender.sendMessage("${ChatColor.AQUA}Author: $expectedAuthors") } + verify(exactly = 1) { mockSender.sendMessage("${ChatColor.AQUA}Description: $expectedDescription") } + verify(exactly = 1) { mockSender.sendMessage("${ChatColor.GREEN}Type /fiefs help for a list of commands.") } } } \ No newline at end of file From 911b7892fe5681657b9ccf0fc5e9435a8cc1a8c4 Mon Sep 17 00:00:00 2001 From: dmccoystephenson Date: Sat, 11 Mar 2023 23:16:42 -0700 Subject: [PATCH 18/19] Added mfFactionId field in Fief.kt --- .../command/fiefs/create/FiefsCreateCommand.kt | 2 +- .../kotlin/com/dansplugins/fiefs/fief/Fief.kt | 3 ++- .../kotlin/com/dansplugins/fiefs/fief/TestFief.kt | 15 +++++++++------ .../dansplugins/fiefs/fief/TestFiefRepository.kt | 12 ++++++------ 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/create/FiefsCreateCommand.kt b/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/create/FiefsCreateCommand.kt index 0509526..8f71f90 100644 --- a/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/create/FiefsCreateCommand.kt +++ b/src/main/kotlin/com/dansplugins/fiefs/command/fiefs/create/FiefsCreateCommand.kt @@ -40,7 +40,7 @@ class FiefsCreateCommand(private val plugin: Fiefs) : CommandExecutor, TabComple return false } - val newFief = Fief(name, mfPlayer.id) + val newFief = Fief(name, mfPlayer.id, faction.id) plugin.fiefRepository.addFief(newFief) sender.sendMessage("${ChatColor.GREEN}Fief created.") return true diff --git a/src/main/kotlin/com/dansplugins/fiefs/fief/Fief.kt b/src/main/kotlin/com/dansplugins/fiefs/fief/Fief.kt index e093897..2c5c184 100644 --- a/src/main/kotlin/com/dansplugins/fiefs/fief/Fief.kt +++ b/src/main/kotlin/com/dansplugins/fiefs/fief/Fief.kt @@ -1,9 +1,10 @@ package com.dansplugins.fiefs.fief +import com.dansplugins.factionsystem.faction.MfFactionId import com.dansplugins.factionsystem.player.MfPlayerId import java.util.UUID -data class Fief(private val name: String, private val ownerMfPlayerId: MfPlayerId) { +data class Fief(private val name: String, private val ownerMfPlayerId: MfPlayerId, private val mfFactionid: MfFactionId) { private var uuid = UUID.randomUUID() private var members: MutableList = mutableListOf() diff --git a/src/test/kotlin/com/dansplugins/fiefs/fief/TestFief.kt b/src/test/kotlin/com/dansplugins/fiefs/fief/TestFief.kt index 5636465..4d90e85 100644 --- a/src/test/kotlin/com/dansplugins/fiefs/fief/TestFief.kt +++ b/src/test/kotlin/com/dansplugins/fiefs/fief/TestFief.kt @@ -1,5 +1,6 @@ package com.dansplugins.fiefs.fief +import com.dansplugins.factionsystem.faction.MfFactionId import com.dansplugins.factionsystem.player.MfPlayerId import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test @@ -10,7 +11,8 @@ class TestFief { @Test fun testInitialization() { val mfPlayerId = MfPlayerId("test") - val fief = Fief("testFief", mfPlayerId) + val mfFactionId = MfFactionId("test") + val fief = Fief("testFief", mfPlayerId, mfFactionId) assertEquals("testFief", fief.getName()) assertEquals(mfPlayerId, fief.getOwnerId()) assertEquals(0, fief.getMembers().size) @@ -20,7 +22,8 @@ class TestFief { @Test fun testAddMember() { val mfPlayerId = MfPlayerId("test") - val fief = Fief("testFief", mfPlayerId) + val mfFactionId = MfFactionId("test") + val fief = Fief("testFief", mfPlayerId, mfFactionId) fief.addMember(mfPlayerId) assertEquals(fief.getMembers().size, 1) assertEquals(mfPlayerId, fief.getMembers()[0]) @@ -29,8 +32,8 @@ class TestFief { @Test fun testRemoveMember() { val mfPlayerId = MfPlayerId("test") - val fief = Fief("testFief", mfPlayerId) - val memberUUID = UUID.randomUUID() + val mfFactionId = MfFactionId("test") + val fief = Fief("testFief", mfPlayerId, mfFactionId) fief.addMember(mfPlayerId) fief.removeMember(mfPlayerId) assertEquals(0, fief.getMembers().size) @@ -39,8 +42,8 @@ class TestFief { @Test fun testIsMember() { val mfPlayerId = MfPlayerId("test") - val fief = Fief("testFief", mfPlayerId) - val memberUUID = UUID.randomUUID() + val mfFactionId = MfFactionId("test") + val fief = Fief("testFief", mfPlayerId, mfFactionId) fief.addMember(mfPlayerId) assertEquals(true, fief.isMember(mfPlayerId)) } diff --git a/src/test/kotlin/com/dansplugins/fiefs/fief/TestFiefRepository.kt b/src/test/kotlin/com/dansplugins/fiefs/fief/TestFiefRepository.kt index bec5825..605627f 100644 --- a/src/test/kotlin/com/dansplugins/fiefs/fief/TestFiefRepository.kt +++ b/src/test/kotlin/com/dansplugins/fiefs/fief/TestFiefRepository.kt @@ -1,5 +1,6 @@ package com.dansplugins.fiefs.fief +import com.dansplugins.factionsystem.faction.MfFactionId import com.dansplugins.factionsystem.player.MfPlayerId import com.dansplugins.fiefs.Fiefs import io.mockk.mockk @@ -20,7 +21,7 @@ class TestFiefRepository { fun testAddFief() { val mockPlugin = mockk() val fiefRepository = FiefRepository(mockPlugin) - val fief = Fief("testFief", MfPlayerId("test")) + val fief = Fief("testFief", MfPlayerId("test"), MfFactionId("test")) fiefRepository.addFief(fief) assertEquals(1, fiefRepository.getFiefs().size) assertEquals(fief, fiefRepository.getFiefs()[0]) @@ -30,7 +31,7 @@ class TestFiefRepository { fun testRemoveFief() { val mockPlugin = mockk() val fiefRepository = FiefRepository(mockPlugin) - val fief = Fief("testFief", MfPlayerId("test")) + val fief = Fief("testFief", MfPlayerId("test"), MfFactionId("test")) fiefRepository.addFief(fief) fiefRepository.removeFief(fief) assertEquals(0, fiefRepository.getFiefs().size) @@ -40,7 +41,7 @@ class TestFiefRepository { fun testGetFiefByName() { val mockPlugin = mockk() val fiefRepository = FiefRepository(mockPlugin) - val fief = Fief("testFief", MfPlayerId("test")) + val fief = Fief("testFief", MfPlayerId("test"), MfFactionId("test")) fiefRepository.addFief(fief) assertEquals(fief, fiefRepository.getFief("testFief")) } @@ -49,8 +50,7 @@ class TestFiefRepository { fun testGetFiefByUUID() { val mockPlugin = mockk() val fiefRepository = FiefRepository(mockPlugin) - val uuid = UUID.randomUUID() - val fief = Fief("testFief", MfPlayerId("test")) + val fief = Fief("testFief", MfPlayerId("test"), MfFactionId("test")) val fiefId = fief.getId() fiefRepository.addFief(fief) assertEquals(fief, fiefRepository.getFief(fiefId)) @@ -60,7 +60,7 @@ class TestFiefRepository { fun testGetFiefByPlayerUUID() { val mockPlugin = mockk() val fiefRepository = FiefRepository(mockPlugin) - val fief = Fief("testFief", MfPlayerId("test")) + val fief = Fief("testFief", MfPlayerId("test"), MfFactionId("test")) val playerId = MfPlayerId("test") fief.addMember(playerId) fiefRepository.addFief(fief) From fdbf00470d583bdc252fc2f8f1cb6fb41b999aa5 Mon Sep 17 00:00:00 2001 From: dmccoystephenson Date: Sat, 11 Mar 2023 23:25:20 -0700 Subject: [PATCH 19/19] Created the MfFiefId value class. --- src/main/kotlin/com/dansplugins/fiefs/fief/Fief.kt | 6 +++--- .../com/dansplugins/fiefs/fief/FiefRepository.kt | 8 ++++---- src/main/kotlin/com/dansplugins/fiefs/fief/MfFiefId.kt | 10 ++++++++++ 3 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 src/main/kotlin/com/dansplugins/fiefs/fief/MfFiefId.kt diff --git a/src/main/kotlin/com/dansplugins/fiefs/fief/Fief.kt b/src/main/kotlin/com/dansplugins/fiefs/fief/Fief.kt index 2c5c184..9df8b7b 100644 --- a/src/main/kotlin/com/dansplugins/fiefs/fief/Fief.kt +++ b/src/main/kotlin/com/dansplugins/fiefs/fief/Fief.kt @@ -5,11 +5,11 @@ import com.dansplugins.factionsystem.player.MfPlayerId import java.util.UUID data class Fief(private val name: String, private val ownerMfPlayerId: MfPlayerId, private val mfFactionid: MfFactionId) { - private var uuid = UUID.randomUUID() + private var id = MfFiefId.generate() private var members: MutableList = mutableListOf() - fun getId(): UUID { - return uuid + fun getId(): MfFiefId { + return id } fun addMember(mfPlayerId: MfPlayerId) { diff --git a/src/main/kotlin/com/dansplugins/fiefs/fief/FiefRepository.kt b/src/main/kotlin/com/dansplugins/fiefs/fief/FiefRepository.kt index 05f4329..d75d433 100644 --- a/src/main/kotlin/com/dansplugins/fiefs/fief/FiefRepository.kt +++ b/src/main/kotlin/com/dansplugins/fiefs/fief/FiefRepository.kt @@ -42,12 +42,12 @@ class FiefRepository(private val plugin: Fiefs) { /** * Gets a Fief from the list. - * @param uuid The UUID of the Fief to get. + * @param mfFiefId The ID of the Fief to get. * @return The Fief with the given UUID. */ - fun getFief(uuid: UUID): Fief? { + fun getFief(mfFiefId: MfFiefId): Fief? { for (fief in fiefs) { - if (fief.getId() == uuid) { + if (fief.getId() == mfFiefId) { return fief } } @@ -56,7 +56,7 @@ class FiefRepository(private val plugin: Fiefs) { /** * Gets a player's fief from the list. - * @param playerUUID The UUID of the player whose fief to get. + * @param mfPlayerId The ID of the player whose fief to get. * @return The Fief which the player is a member of. * @return null if the player is not a member of any fief. */ diff --git a/src/main/kotlin/com/dansplugins/fiefs/fief/MfFiefId.kt b/src/main/kotlin/com/dansplugins/fiefs/fief/MfFiefId.kt new file mode 100644 index 0000000..e6631af --- /dev/null +++ b/src/main/kotlin/com/dansplugins/fiefs/fief/MfFiefId.kt @@ -0,0 +1,10 @@ +package com.dansplugins.fiefs.fief + +import java.util.* + +@JvmInline +value class MfFiefId(val value: String) { + companion object { + fun generate() = MfFiefId(UUID.randomUUID().toString()) + } +} \ No newline at end of file