-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ feat: Add subcommands
ender
and inv
to preview player data
- Loading branch information
Showing
7 changed files
with
230 additions
and
2 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
17 changes: 17 additions & 0 deletions
17
bukkit/src/main/kotlin/com/aiyostudio/esync/internal/util/TextUtil.kt
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,17 @@ | ||
package com.aiyostudio.esync.internal.util | ||
|
||
import org.bukkit.ChatColor | ||
import org.bukkit.configuration.ConfigurationSection | ||
|
||
object TextUtil { | ||
|
||
fun String.colorify(): String { | ||
return ChatColor.translateAlternateColorCodes('&', this) | ||
} | ||
|
||
fun ConfigurationSection.getColorifyStringList(key: String): MutableList<String> { | ||
return this.getStringList(key).apply { | ||
this.replaceAll { ChatColor.translateAlternateColorCodes('&', it) } | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
bukkit/src/main/kotlin/com/aiyostudio/esync/internal/view/EnderChestView.kt
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,44 @@ | ||
package com.aiyostudio.esync.internal.view | ||
|
||
import com.aiyostudio.esync.internal.module.entity.EnderChestEntity | ||
import com.aiyostudio.esync.internal.plugin.EfficientSyncBukkit | ||
import com.aiyostudio.esync.internal.util.TextUtil.colorify | ||
import com.aiyostudio.esync.internal.util.TextUtil.getColorifyStringList | ||
import com.aystudio.core.bukkit.util.common.CommonUtil | ||
import com.aystudio.core.bukkit.util.inventory.GuiModel | ||
import org.bukkit.Material | ||
import org.bukkit.configuration.file.YamlConfiguration | ||
import org.bukkit.entity.Player | ||
import org.bukkit.inventory.ItemStack | ||
|
||
class EnderChestView( | ||
val player: Player, | ||
val entity: EnderChestEntity | ||
) { | ||
private lateinit var gui: GuiModel | ||
|
||
init { | ||
EfficientSyncBukkit.instance.saveResource("view/enderChest.yml", "view/enderChest.yml", false) { | ||
val data = YamlConfiguration.loadConfiguration(it) | ||
this.gui = GuiModel(data.getString("title"), data.getInt("size")) | ||
this.gui.registerListener(EfficientSyncBukkit.instance) | ||
data.getConfigurationSection("items")?.getKeys(false)?.forEach { key -> | ||
val section = data.getConfigurationSection("items.$key") | ||
val item = ItemStack( | ||
Material.valueOf(section.getString("type").uppercase()), | ||
section.getInt("amount"), | ||
section.getInt("data").toShort() | ||
) | ||
val meta = item.itemMeta | ||
meta.displayName = section.getString("name").colorify() | ||
meta.lore = section.getColorifyStringList("lore") | ||
item.setItemMeta(meta) | ||
CommonUtil.formatSlots(section.getString("slot")).forEach { slot -> this.gui.setItem(slot, item) } | ||
} | ||
val contentSlots = CommonUtil.formatSlots(data.getString("contents")) | ||
contentSlots.forEach { slot -> slot.takeIf { it < 27 }?.let { this.gui.setItem(it, entity.items.get(it)) } } | ||
this.gui.execute { it.isCancelled = true } | ||
this.gui.openInventory(player) | ||
} | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
bukkit/src/main/kotlin/com/aiyostudio/esync/internal/view/InventoryView.kt
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,55 @@ | ||
package com.aiyostudio.esync.internal.view | ||
|
||
import com.aiyostudio.esync.internal.module.entity.PlayerInventoryEntity | ||
import com.aiyostudio.esync.internal.plugin.EfficientSyncBukkit | ||
import com.aiyostudio.esync.internal.util.TextUtil.colorify | ||
import com.aiyostudio.esync.internal.util.TextUtil.getColorifyStringList | ||
import com.aystudio.core.bukkit.util.common.CommonUtil | ||
import com.aystudio.core.bukkit.util.inventory.GuiModel | ||
import org.bukkit.Material | ||
import org.bukkit.configuration.file.YamlConfiguration | ||
import org.bukkit.entity.Player | ||
import org.bukkit.inventory.ItemStack | ||
|
||
class InventoryView( | ||
val player: Player, | ||
val entity: PlayerInventoryEntity | ||
) { | ||
private lateinit var gui: GuiModel | ||
|
||
init { | ||
EfficientSyncBukkit.instance.saveResource("view/inventory.yml", "view/inventory.yml", false) { | ||
val data = YamlConfiguration.loadConfiguration(it) | ||
this.gui = GuiModel(data.getString("title"), data.getInt("size")) | ||
this.gui.registerListener(EfficientSyncBukkit.instance) | ||
data.getConfigurationSection("items")?.getKeys(false)?.forEach { key -> | ||
val section = data.getConfigurationSection("items.$key") | ||
val item = ItemStack( | ||
Material.valueOf(section.getString("type").uppercase()), | ||
section.getInt("amount"), | ||
section.getInt("data").toShort() | ||
) | ||
val meta = item.itemMeta | ||
meta.displayName = section.getString("name").colorify() | ||
meta.lore = section.getColorifyStringList("lore") | ||
item.setItemMeta(meta) | ||
CommonUtil.formatSlots(section.getString("slot")).forEach { slot -> this.gui.setItem(slot, item) } | ||
} | ||
val contentSlots = CommonUtil.formatSlots(data.getString("contents")) | ||
(0 until 36).forEach { slot -> | ||
if (slot < contentSlots.size && entity.inventory.containsKey(slot)) { | ||
this.gui.setItem(contentSlots[slot], entity.inventory.get(slot)) | ||
} | ||
} | ||
val armorSlots = CommonUtil.formatSlots(data.getString("armor")) | ||
(36 until 41).forEach { slot -> | ||
val finalIndex = slot - 36 | ||
if (finalIndex < armorSlots.size && entity.inventory.containsKey(slot)) { | ||
this.gui.setItem(armorSlots[finalIndex], entity.inventory.get(slot)) | ||
} | ||
} | ||
this.gui.execute { it.isCancelled = true } | ||
this.gui.openInventory(player) | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,9 +1,24 @@ | ||
prefix: "&beSync&f " | ||
|
||
commands: | ||
- "&6eSync" | ||
- "&e/%c kickAll &f踢出全部玩家(触发保存)" | ||
- "&e/%c inv <UUID> &f查看玩家背包数据" | ||
- "&e/%c ender <UUID> &f查看玩家末影箱" | ||
- "&e/%c reload &f重载插件配置" | ||
|
||
params: | ||
enter-uuid: "请输入玩家UUID." | ||
uuid-failure: "请输入正确的UUID." | ||
|
||
sync: | ||
success: "数据同步完成." | ||
failed: "数据同步失败." | ||
kick-all: | ||
reason: "&e服务器维护." | ||
message: "已将全部玩家踢出服务器." | ||
reload: "插件配置重载完成." | ||
reload: "插件配置重载完成." | ||
|
||
repo-failure: "没有找到可用的数据同步源." | ||
module-failure: "没有找到可用的数据模块." | ||
empty-data: "没有找到玩家数据." |
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,11 @@ | ||
title: "&8玩家末影箱预览" | ||
size: 27 | ||
contents: 0-26 | ||
items: | ||
panel: | ||
type: STAINED_GLASS_PANE | ||
amount: 1 | ||
data: 15 | ||
name: "&f" | ||
lore: [ ] | ||
slot: 0,1,6,8-17 |
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,12 @@ | ||
title: "&8玩家背包预览" | ||
size: 54 | ||
contents: 18-53 | ||
armor: 2,3,4,5,7 | ||
items: | ||
panel: | ||
type: STAINED_GLASS_PANE | ||
amount: 1 | ||
data: 15 | ||
name: "&f" | ||
lore: [ ] | ||
slot: 0,1,6,8-17 |