개인 자료란 (JE)

  서버 커뮤니티

Profile useu 대표칭호 없음
Profile

자료 자바 에디션(JE) 플러그인 스크립트

창고 스크립트 [비동기 / 파일저장]

2024.06.04 조회 수 1154 추천 수 0
장르 그 외에 장르 
게임버전 모든버전 
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)


창고 스크립트를 비동기, 파일 저장 방식으로 만들어봤습니다.


[비동기] 유저 접속시 해당 유저의 창고 정보 파일을 읽어 인벤토리 생성 및 변수에 저장합니다.

[비동기] 유저 퇴장시 현재 변수에 저장된 인벤토리의 내용물을 파일에 저장합니다. / 인벤토리 변수를 삭제합니다.


해당 스크립트는 유저 접속시 아이템이 담긴 인벤토리 객체를 변수에 저장하는 방식으로 구현했습니다.

그냥 개인적인 궁금증으로 만들어본거라 이 방식이 문제가 있을지 확인해보진 않았습니다.


UChest.sk

Warning
댓글이 없습니다.

새로운 댓글을 등록해 주세요!

뉴스 및 창작물
/files/thumbnails/163/234/004/262x150.crop.jpg?20260923044846

맵

오직 커맨드로 마인크래프트 안에 마인크래프트를 만들었습니다

Ice28_

2026-09-23

1

/files/thumbnails/345/223/004/262x150.crop.jpg?20260921131805

레드스톤

[영상] 마인크래프트 맵에서 야라라라 노트블럭 커버해보기

노트블럭전문가

2026-09-21

1

사진이 없습니다.

업데이트

마인크래프트 Wilderness Bound 9월 15일 출시 예정, 새 바이옴·버려진 캠프 정리 1

핫브리프

2026-09-15

0

사진이 없습니다.

건축

[영상] 노갑옷으로 깊은 동굴에서 100일 생존하기에 도전해 봤습니다!

FinnMC

2026-09-07

0

/files/thumbnails/217/223/004/262x150.crop.jpg?20260820140938

상품

《마인크래프트 놀라운 건축설계도》 출간!

다코미

2026-08-20

0

/files/thumbnails/429/222/004/262x150.crop.jpg?20260818120811

레드스톤

쿠션 LED 끝판왕 (고퀄리티인가)

지구12345

2026-08-18

0

/files/thumbnails/643/220/004/262x150.crop.jpg?20260812203705

모드

차량들 완료😄 [Minecity]

SHALDOPlus

2026-08-12

0

/files/thumbnails/451/218/004/262x150.crop.jpg?20260806164904

건축

글리코상 만들기 2일차

tytu

2026-08-06

0

/files/thumbnails/304/218/004/262x150.crop.jpg?20260805235245

건축

고퀄리티는 아니지만 글리코상 만들기 1일차

tytu

2026-08-05

0

/files/thumbnails/292/218/004/262x150.crop.jpg?20260805232218

건축

가장현실적인 도시만들기프로젝트 [Minecity]

SHALDOPlus

2026-08-05

0

/files/thumbnails/132/218/004/262x150.crop.jpg?20260805182813

모델링

레이저 터렛

타닥

2026-08-05

1

/files/thumbnails/419/212/004/262x150.crop.jpg?20260723173920

상품

《마인크래프트 아카데미: 좀비 아웃브레이크!》 출간!

다코미

2026-07-23

0