useu
대표칭호 없음
장르 | 그 외에 장르 |
---|---|
게임버전 | 모든버전 |
API | 스피곳, 페이퍼 |
원산지 | 국산 |
개발자 | 본인(useu) |
저작권 | 스크립트 파일 내 제작자 표시만 남기고 자유롭게 이용 |
자료 출처 | https://본인 |
# 제작자: useu / 디스코드: o1_o2
# Tested in
# Skript: 2.8.5
# Minecraft: 1.20.4
options:
PERM_OPEN_CHEST: uchest.open
PERM_MANAGE_CHEST: uchest.manage
import:
org.bukkit.Bukkit
org.bukkit.Material
org.bukkit.inventory.ItemStack
org.bukkit.configuration.file.YamlConfiguration
java.io.File
java.util.UUID
java.lang.Runnable
ch.njol.skript.Skript
on unload:
set {-chest.unloadBySystem} to true
loop {-chest::*}:
unloadChestFromUUID(loop-index)
delete {-chest::*}
delete {-chest.unloadBySystem}
on load:
loop all players:
loadChestFromPlayer(loop-value)
function onAsyncChestLoaded(uuid: string):
delete {-chest.running::%{_uuid}%}
set {_p} to Bukkit.getOfflinePlayer(UUID.fromString({_uuid}))
send "[창고] 로딩 완료" to {_p}
if {_p} is not online:
runAsnycUnloadChestFromUUID({_uuid})
function onAsyncChestUnloaded(uuid: string):
delete {-chest.running::%{_uuid}%}
if Bukkit.getOfflinePlayer(UUID.fromString({_uuid})) is online:
runAsnycLoadChestFromUUID({_uuid})
function loadChestFromPlayer(p: player):
loadChestFromUUID(uuid of {_p})
function loadChestFromUUID(uuid: string):
set {_file} to loadPlayerChestDataFile({_uuid})
set {_config} to YamlConfiguration.loadConfiguration({_file})
set {_inv} to chest inventory with 6 rows named "창고"
loop integers between 0 and 53:
continue if {_config}.isSet("%loop-number%") is false
set slot loop-number of {_inv} to {_config}.getItemStack("%loop-number%", new ItemStack(Material.AIR))
set {-chest::%{_uuid}%} to {_inv}
function unloadChestFromPlayer(p: player):
unloadChestFromUUID(uuid of {_p})
function unloadChestFromUUID(uuid: string):
saveChestFromUUID({_uuid})
delete {-chest::%{_uuid}%}
function saveChestFromPlayer(p: player):
saveChestFromUUID(uuid of {_p})
function saveChestFromUUID(uuid: string):
if {-chest::%{_uuid}%} is not set:
exit
set {_file} to loadPlayerChestDataFile({_uuid})
set {_config} to new YamlConfiguration()
loop integers between 0 and 53:
continue if slot loop-number of {-chest::%{_uuid}%} is air
set {_item} to slot loop-number of {-chest::%{_uuid}%}
{_config}.set("%loop-number%", {_item})
{_config}.save({_file})
function loadPlayerChestDataFile(uuid: string) :: object:
set {_scriptsPath} to Skript.getInstance().getScriptsFolder().getAbsolutePath()
set {_folder} to new File("%{_scriptsPath}%\UChest")
{_folder}.mkdirs()
set {_file} to new File({_folder}, "%{_uuid}%.yaml")
if {_file}.exists() is false:
try {_file}.createNewFile()
if last java exception is set:
Skript.error("[ERROR] 0001 (in %script name%)")
(last java exception).printStackTrace()
stop
return {_file}
function runAsnycLoadChestFromUUID(uuid: string):
create new section stored in {_function::run}:
loadChestFromUUID({_uuid})
create section stored in {_function::run}:
onAsyncChestLoaded({_uuid})
set {_proxy} to new proxy instance of Runnable using {_function::*}
Bukkit.getScheduler().runTask(Skript.getInstance(), {_proxy})
set {_proxy} to new proxy instance of Runnable using {_function::*}
set {-chest.running::%{_uuid}%} to Bukkit.getScheduler().runTaskAsynchronously(Skript.getInstance(), {_proxy})
function runAsnycUnloadChestFromUUID(uuid: string):
create new section stored in {_function::run}:
unloadChestFromUUID({_uuid})
create section stored in {_function::run}:
onAsyncChestUnloaded({_uuid})
set {_proxy} to new proxy instance of Runnable using {_function::*}
Bukkit.getScheduler().runTask(Skript.getInstance(), {_proxy})
set {_proxy} to new proxy instance of Runnable using {_function::*}
set {-chest.running::%{_uuid}%} to Bukkit.getScheduler().runTaskAsynchronously(Skript.getInstance(), {_proxy})
function checkChestTaskRunning(uuid: string) :: boolean:
if {-chest.running::%{_uuid}%} is not set:
return false
if Bukkit.getScheduler().isCurrentlyRunning({-chest.running::%{_uuid}%}.getTaskId()) is false:
return false
return true
command /창고:
permission: {@PERM_OPEN_CHEST}
aliases: ckdrh, chest, 상자, tkdwk
executable by: players
trigger:
if {-chest::%uuid of player%} is not set:
send "[창고] 창고가 아직 로딩되지 않았습니다."
exit
if {-chest.running::%uuid of player%} is set:
send "[창고] 창고가 아직 로딩되지 않았습니다."
exit
open {-chest::%uuid of player%} to player
command /창고관리 :
permission: {@PERM_MANAGE_CHEST}
executable by: players
trigger:
if {-chest::%uuid of arg 1%} is not set:
send "[창고] 창고가 아직 로딩되지 않았습니다."
exit
if {-chest.running::%uuid of arg 1%} is set:
send "[창고] 창고가 아직 로딩되지 않았습니다."
exit
open {-chest::%uuid of arg 1%} to player
on join:
stop if checkChestTaskRunning(uuid of player) is true
send "[창고] 로딩 시작"
runAsnycLoadChestFromUUID(uuid of player)
on quit:
stop if checkChestTaskRunning(uuid of player) is true
runAsnycUnloadChestFromUUID(uuid of player)
창고 스크립트를 비동기, 파일 저장 방식으로 만들어봤습니다.
[비동기] 유저 접속시 해당 유저의 창고 정보 파일을 읽어 인벤토리 생성 및 변수에 저장합니다.
[비동기] 유저 퇴장시 현재 변수에 저장된 인벤토리의 내용물을 파일에 저장합니다. / 인벤토리 변수를 삭제합니다.
해당 스크립트는 유저 접속시 아이템이 담긴 인벤토리 객체를 변수에 저장하는 방식으로 구현했습니다.
그냥 개인적인 궁금증으로 만들어본거라 이 방식이 문제가 있을지 확인해보진 않았습니다.
댓글이 없습니다.
새로운 댓글을 등록해 주세요!