-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add GUIHeadItem for better typing (#20)
Breaking change
- Loading branch information
1 parent
334963d
commit c50302d
Showing
5 changed files
with
83 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package me.tech.mcchestui.item | ||
|
||
import com.destroystokyo.paper.profile.PlayerProfile | ||
import me.tech.mcchestui.GUI | ||
import org.bukkit.Material | ||
import org.bukkit.OfflinePlayer | ||
import org.bukkit.inventory.ItemStack | ||
import org.bukkit.inventory.meta.SkullMeta | ||
|
||
/** | ||
* Construct a [ItemStack] to be placed in a [GUI.Slot]. | ||
* Automatically uses [Material.PLAYER_HEAD]. | ||
* @param builder [GUIHeadItem] builder. | ||
*/ | ||
fun GUI.Slot.headItem( | ||
builder: GUIHeadItem.() -> Unit = {} | ||
): GUIHeadItem { | ||
return guiHeadItem(builder) | ||
} | ||
|
||
/** | ||
* Construct a [ItemStack] to be placed in a [GUI.Slot]. | ||
* Automatically uses [Material.PLAYER_HEAD]. | ||
* @param builder [GUIHeadItem] builder. | ||
*/ | ||
fun guiHeadItem( | ||
builder: GUIHeadItem.() -> Unit = {} | ||
): GUIHeadItem { | ||
return GUIHeadItem().apply(builder) | ||
} | ||
|
||
class GUIHeadItem : GUIItem(Material.PLAYER_HEAD) { | ||
override val itemMeta: SkullMeta | ||
get() = stack.itemMeta as SkullMeta | ||
|
||
/** | ||
* Current [OfflinePlayer] that owns the player head. | ||
* | ||
* @warning Will only apply on items that inherit [SkullMeta]. | ||
*/ | ||
var skullOwner: OfflinePlayer? | ||
get() = itemMeta.owningPlayer | ||
set(value) { | ||
stack.editMeta(SkullMeta::class.java) { | ||
it.owningPlayer = value | ||
} | ||
} | ||
|
||
/** | ||
* Current [PlayerProfile] that owns the player head. | ||
* | ||
* @warning Will only apply on items that inherit [SkullMeta]. | ||
*/ | ||
var playerProfile: PlayerProfile? | ||
get() = itemMeta.playerProfile | ||
set(value) { | ||
stack.editMeta(SkullMeta::class.java) { | ||
it.playerProfile = value | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters