#KeyBackpack.sk
#Author: Policiu
#Start: 2018/06/09 12:20 AM
#End: 2018/06/09 01:28 PM
#Updated: 2018/06/10 4:04 PM
#Notes:
#Variable domain used {keyBP::*}
# p = player
# k = key
#Settings
options:
#This prefaces most messages
PREFIX: <reset>[Key]<reset>
#This is what players see when looking in there backpack
INVENTORY_NAME: Your keys
#This is what an admin sees when looking at all keys
DEBUG_INVENTORY_NAME: <red>DEBUG<reset>
#Design
INVENTORY_SIZE: 5
INVENTORY_BORDER: black stained glass pane named " "
INVENTORY_BORDER_ID: 0,1,2,3,4,5,6,7,8,9,17,18,26,27,35,36,37,38,39,40,41,42,43, and 44
INVENTORY_BORDER_INNER: purple stained glass pane named " "
INVENTORY_BORDER_INNER_ID: 10,11,12,13,14,15,16,19,20,21,22,23,24,25,28,29,30,31,32,33, and 34
#Next Page Button
INVENTORY_NEXT: green stained glass pane named "<gold>Next Page"
INVENTORY_NEXT_ID: 25
#Previous Page Button
INVENTORY_PREV: red stained glass pane named "<gold>Previous Page"
INVENTORY_PREV_ID: 19
#There is only support for 5 slots
#They are out of order on purpose
INVENTORY_KEY_1_ID: 22
INVENTORY_KEY_2_ID: 20
INVENTORY_KEY_3_ID: 24
INVENTORY_KEY_4_ID: 21
INVENTORY_KEY_5_ID: 23
#If the player does not have any keys
NO_KEYS: dead bush named "<reset>No keys"
#If I were using SKQuery you could have as many lines as possible
#If you have SKQuery, use %nl% for addition lines
NO_KEYS_LORE: <reset>This Is Where I'd Put My Keys
NO_KEYS_LORE_2: <reset><bold>If I Had One
#default key options when a new key is made // use ingame commands to change once created
KEY_ITEM: tripwire hook
KEY_NAME: <NONE>
KEY_LORE: "<NONE>" and "<NONE>"
#Messages that the player sees
MESSAGE_PLAYER_GET_1: You have recieved
MESSAGE_PLAYER_GET_2: keys!
MESSAGE_PLAYER_CLEAR: Your keys have been wiped!
MESSAGE_PLAYER_TAKE: Some our your keys have been taken!
MESSAGE_PLAYER_DO_NOT_HAVE: You do not have any of these keys!
MESSAGE_PLAYER_INVENTORY_FULL: Your Inventory is full!
#Backpack for keys
CHEST_TYPE: ender chest
CHEST_NAME: "<reset>Key Back Pack"
#If you have SKQuery, use %nl% for addition lines
CHEST_LORE_1: <green>Spooky
CHEST_LORE_2: <red>
#Options for backpack
CHEST_CAN_DROP: true
#This is the max amount a player can have of one key
KEY_LIMIT: 1024
#Permission
KEY_GIVE_BACK_PACK: key.bp
KEY_ADMIN: key.admin
#functions
#This function allows the admins to see what keys are on the server
function keyBPAdminList(player: player, startID: number):
open virtual chest inventory with size {@INVENTORY_SIZE} named "{@DEBUG_INVENTORY_NAME} | %{_startID}%" to {_player}
#Color Chest
create gui slot {@INVENTORY_BORDER_ID} of {_player} with {@INVENTORY_BORDER} to do nothing
create gui slot {@INVENTORY_BORDER_INNER_ID} of {_player} with {@INVENTORY_BORDER_INNER} to do nothing
#if number of keys exceed 5 & if already on another page
if (size of {keyBP::k::*} > 4 + {_startID}):
unformat the gui slot {@INVENTORY_NEXT_ID} of {_player}
create gui slot {@INVENTORY_NEXT_ID} of {_player} with {@INVENTORY_NEXT} to run function keyBPAdminList({_player}, {_startID} + 5)
if {_startID} != 1:
unformat the gui slot {@INVENTORY_PREV_ID} of {_player}
create gui slot {@INVENTORY_PREV_ID} of {_player} with {@INVENTORY_PREV} to run function keyBPAdminList({_player}, {_startID} - 5)
#Start displaying hooks
if size of {keyBP::k::*} is 0:
#I can't figure out how to set the lore in one line
set {_item} to {@NO_KEYS}
set line 1 of lore of {_item} to "{@NO_KEYS_LORE}"
set line 2 of lore of {_item} to "{@NO_KEYS_LORE_2}"
set slot {@INVENTORY_KEY_1_ID} of the current inventory of {_player} to {_item}
stop
set {_Place} to 1
#Allows the loop to find where to start. I should have used modulus
set {_check} to 1
loop {keyBP::k::*}:
if {_check} < {_startID}:
add 1 to {_check}
else:
clear {_item}
set {_item} to {keyBP::k::%loop-index%::Item} named {keyBP::k::%loop-index%::Name}
set line 1 of lore of {_item} to "<reset><gold>ID: %loop-index%"
set line 2 of lore of {_item} to "<reset><gold>Command: <reset>%{keyBP::k::%loop-index%::Command}%"
set line 3 of lore of {_item} to "<reset><gold>CommandType: <reset>%{keyBP::k::%loop-index%::CommandType}%"
loop {keyBP::k::%loop-index%::Lore::*}:
set line loop-index-2 parsed as a number + 1 of lore of {_item} to loop-value-2
#Format of key placement
if {_Place} is 1:
unformat the gui slot {@INVENTORY_KEY_1_ID} of {_player}
create gui slot {@INVENTORY_KEY_1_ID} of {_player} with {_item} to do nothing
if {_Place} is 2:
unformat the gui slot {@INVENTORY_KEY_2_ID} of {_player}
create gui slot {@INVENTORY_KEY_2_ID} of {_player} with {_item} to do nothing
if {_Place} is 3:
unformat the gui slot {@INVENTORY_KEY_3_ID} of {_player}
create gui slot {@INVENTORY_KEY_3_ID} of {_player} with {_item} to do nothing
if {_Place} is 4:
unformat the gui slot {@INVENTORY_KEY_4_ID} of {_player}
create gui slot {@INVENTORY_KEY_4_ID} of {_player} with {_item} to do nothing
if {_Place} is 5:
unformat the gui slot {@INVENTORY_KEY_5_ID} of {_player}
create gui slot {@INVENTORY_KEY_5_ID} of {_player} with {_item} to do nothing
stop
add 1 to {_Place}
stop
function keyBPPlayerList(player: player, startID: number):
open virtual chest inventory with size {@INVENTORY_SIZE} named "{@INVENTORY_NAME} | Page %(({_startID} - 1) / 5 )+ 1%" to {_player}
#Color Chest
create gui slot {@INVENTORY_BORDER_ID} of {_player} with {@INVENTORY_BORDER} to do nothing
create gui slot {@INVENTORY_BORDER_INNER_ID} of {_player} with {@INVENTORY_BORDER_INNER} to do nothing
#if number of keys exceed 5 & if already on another page
if (size of {keyBP::p::%{_player}%::Inv::*} > 4 + {_startID}):
unformat the gui slot {@INVENTORY_NEXT_ID} of {_player}
create gui slot {@INVENTORY_NEXT_ID} of {_player} with {@INVENTORY_NEXT} to run function keyBPPlayerList({_player}, {_startID} + 5)
if {_startID} != 1:
unformat the gui slot {@INVENTORY_PREV_ID} of {_player}
create gui slot {@INVENTORY_PREV_ID} of {_player} with {@INVENTORY_PREV} to run function keyBPPlayerList({_player}, {_startID} - 5)
#Start displaying hooks
if size of {keyBP::p::%{_player}%::Inv::*} is 0:
#I can't figure out how to set the lore in one line
set {_item} to {@NO_KEYS}
set line 1 of lore of {_item} to "{@NO_KEYS_LORE}"
set line 2 of lore of {_item} to "{@NO_KEYS_LORE_2}"
set slot {@INVENTORY_KEY_1_ID} of the current inventory of {_player} to {_item}
stop
set {_Place} to 1
set {_check} to 1
loop {keyBP::p::%{_player}%::Inv::*}:
if {_check} < {_startID}:
add 1 to {_check}
else:
clear {_item}
set {_item} to {keyBP::k::%loop-index%::Item} named {keyBP::k::%loop-index%::Name}
set line 1 of lore of {_item} to "<reset><gold>Amount: %{keyBP::p::%{_player}%::Inv::%loop-index%}%"
loop {keyBP::k::%loop-index%::Lore::*}:
set line loop-index-2 parsed as a number + 1 of lore of {_item} to loop-value-2
if {_Place} is 1:
unformat the gui slot {@INVENTORY_KEY_1_ID} of {_player}
create gui slot {@INVENTORY_KEY_1_ID} of {_player} with {_item} to run function keyBPPlayerChestExchange({_player}, {_item}, loop-index parsed as an integer, {_startID})
if {_Place} is 2:
unformat the gui slot {@INVENTORY_KEY_2_ID} of {_player}
create gui slot {@INVENTORY_KEY_2_ID} of {_player} with {_item} to run function keyBPPlayerChestExchange({_player}, {_item}, loop-index parsed as an integer, {_startID})
if {_Place} is 3:
unformat the gui slot {@INVENTORY_KEY_3_ID} of {_player}
create gui slot {@INVENTORY_KEY_3_ID} of {_player} with {_item} to run function keyBPPlayerChestExchange({_player}, {_item}, loop-index parsed as an integer, {_startID})
if {_Place} is 4:
unformat the gui slot {@INVENTORY_KEY_4_ID} of {_player}
create gui slot {@INVENTORY_KEY_4_ID} of {_player} with {_item} to run function keyBPPlayerChestExchange({_player}, {_item}, loop-index parsed as an integer, {_startID})
if {_Place} is 5:
unformat the gui slot {@INVENTORY_KEY_5_ID} of {_player}
create gui slot {@INVENTORY_KEY_5_ID} of {_player} with {_item} to run function keyBPPlayerChestExchange({_player}, {_item}, loop-index parsed as an integer, {_startID})
stop
add 1 to {_Place}
stop
#This function will exhange one key to run the command associated with that key
function keyBPPlayerChestExchange(player: player, item: item, id: number, OG: number):
if {keyBP::p::%{_player}%::Inv::%{_id}%} > 0:
subtract 1 from {keyBP::p::%{_player}%::Inv::%{_id}%}
if {keyBP::p::%{_player}%::Inv::%{_id}%} = 0:
clear {keyBP::p::%{_player}%::Inv::%{_id}%}
if {keyBP::k::%{_ID}%::CommandType} is false: #Bad Programming :(
execute {_player} command "%{keyBP::k::%{_ID}%::Command}%"
else:
execute server command "%{keyBP::k::%{_ID}%::Command}%"
else:
send "{@PREFIX} {@MESSAGE_PLAYER_DO_NOT_HAVE}" to {_player} #Won't happen
keyBPPlayerList({_player}, {_OG})
stop
# Commands
#Gives the player a backpack
command /keyBackPack <player>:
permission: {@KEY_GIVE_BACK_PACK}
aliases: keybp
trigger:
set {_item} to {@CHEST_TYPE} named {@CHEST_NAME}
set line 1 of the lore of {_item} to "{@CHEST_LORE_1}"
set line 2 of the lore of {_item} to "{@CHEST_LORE_2}"
give 1 of {_item} to arg
#Creation and Distribution of keys
command /keyAdmin [<text>] [<text>] [<text>] [<text>] [<text>]:
permission: {@KEY_ADMIN}
aliases: keyA
trigger:
#Since this is for admins, I didn't dress it up
#Global Commands
if arg 1 is "create":
set {_placeholder} to -1
add {_placeholder} to {keyBP::k::*}
loop {keyBP::k::*}:
if loop-value is {_placeholder}:
set {keyBP::k::%loop-index%} to loop-index
set {keyBP::k::%loop-index%::Name} to "{@KEY_NAME}"
set {keyBP::k::%loop-index%::Item} to {@KEY_ITEM}
set {keyBP::k::%loop-index%::Lore} to "lore"
set {keyBP::k::%loop-index%::Lore::*} to {@KEY_LORE}
send "{@PREFIX} New Key added. ID: %loop-index%"
stop
send "{@PREFIX} New key adding failed!"
stop
if arg 1 is "edit":
if arg 2 is not set:
send "{@PREFIX} Please specify an ID"
send "/keyAdmin edit <ID> <OPTION>"
stop
set {_ID} to arg 2 parsed as a number
if {keyBP::k::%{_ID}%} is not set:
send "{@PREFIX} Invalid ID"
stop
if arg 3 is "item":
if arg 5 is set:
set {_item} to "%arg 4% %arg 5%" parsed as an item
else:
set {_item} to arg 4 parsed as an item
if {_item} is not an item:
if arg 5 is set:
send "{@PREFIX} Invalid item: %arg 4% %arg 5%"
else:
send "{@PREFIX} Invalid item: %arg 4%"
stop
set {keyBP::k::%{_ID}%::Item} to {_item}
send "{@PREFIX} Key was set to %{_item}%"
stop
if arg 3 is "name":
if arg 4 is not set:
send "{@PREFIX} Use /keyAdmin edit %{_ID}% name <text>"
stop
if arg 5 is set:
set {keyBP::k::%{_ID}%::Name} to colored "%arg 4% %arg 5%"
else:
set {keyBP::k::%{_ID}%::Name} to colored arg 4
stop
if arg 3 is "lore" :
if arg 4 is not set:
send "{@PREFIX} Use /keyAdmin edit %{_ID}% lore <text>"
stop
#Allow multiple lines!
set {_text::*} to colored arg 4 split at "||"
loop {_text::*}:
add loop-value to {_lore::*}
if arg 5 is set:
#Allow multiple lines!
clear {_text::*}
set {_text::*} to colored arg 5 split at "||"
set {_size} to size of {_lore::*}
set {_lore::%{_size}%} to "%{_lore::%{_size}%}% %{_text::1}%"
clear {_text::1}
loop {_text::*}:
add loop-value to {_lore::*}
#In case previous lore was longer than new lore
clear {keyBP::k::%{_ID}%::Lore::*}
set {keyBP::k::%{_ID}%::Lore::*} to {_lore::*}
send "{@PREFIX} Key's lore was set to %{keyBP::k::%{_ID}%::Lore::*}%"
stop
if arg 3 is "command":
if arg 4 is not set:
send "{@PREFIX} Use /keyAdmin edit %{_ID}% command <text>"
stop
if arg 5 is set:
set {_command} to "%arg 4% %arg 5%"
else:
set {_command} to arg 4
set {_permission} to permission of command arg 4
if player does not have permission {_permission}:
send "{@PREFIX} You do not have permission to add this command!"
if {_permission} is not set:
set {_permission} to "*"
send "{@PREFIX} Requires: %{_permission}%"
stop
set {keyBP::k::%{_ID}%::Command} to {_command}
send "{@PREFIX} Key's command was set to %{keyBP::k::%{_ID}%::Command}%"
stop
if arg 3 is "commandtype":
if arg 4 is not set:
send "{@PREFIX} Use /keyAdmin edit %{_ID}% commandtype console/player"
stop
if arg 4 is "player" or "console":
if arg 4 is "player":
set {keyBP::k::%{_ID}%::CommandType} to false
else:
set {keyBP::k::%{_ID}%::CommandType} to true
else:
send "{@PREFIX} Use /keyAdmin edit %{_ID}% commandtype console/player"
stop
send "{@PREFIX} Key's commandType was set to %{keyBP::k::%{_ID}%::CommandType}%"
stop
#Invalid or no argument given
send ""
send "Valid options"
send "-------------"
send "Item: Change the item the key displays"
send "Name: Change the name of the key"
send "Lore: Change the lore of the key. use '||' for a new line"
send "Command: Changes the command run when a key is used."
send "CommandType: Changes the who runs the command (Server/Player)"
send "Example: /keyAdmin edit Lore Hey world! || How are you??"
stop
if arg 1 is "delete":
if arg 2 is not set:
send "{@PREFIX} Please specify an ID"
send "/keyAdmin delete <ID>"
stop
set {_ID} to arg 2 parsed as a number
if {keyBP::k::%{_ID}%} is not set:
send "{@PREFIX} Invalid ID"
stop
clear {keyBP::k::%{_ID}%::*}
clear {keyBP::k::%{_ID}%}
loop {keyBP::p::*}:
clear {keyBP::p::%loop-index%::Inv::%{_ID}%}
send "{@PREFIX} Key %{_ID}% was removed"
stop
if arg 1 is "list":
keyBPAdminList(player, 1)
stop
if arg 1 is "info":
if arg 2 is not set:
send "{@PREFIX} Please specify an ID"
send "/keyAdmin delete <ID>"
stop
set {_ID} to arg 2 parsed as a number
if {keyBP::k::%{_ID}%} is not set:
send "{@PREFIX} Invalid ID"
stop
send "NAME: %{keyBP::k::%{_ID}%::Name}%"
send "ITEM: %{keyBP::k::%{_ID}%::Item}%"
send "LORE: %{keyBP::k::%{_ID}%::Lore}%"
send "COMMAND: %{keyBP::k::%{_ID}%::Command}%"
send "COMMANDTYPE: %{keyBP::k::%{_ID}%::CommandType}%"
stop
#Player specific commands
if arg 1 is "give":
set {_player} to arg 2 parsed as a player
if {_player} is not set:
send "{@PREFIX} Player not found!"
send "{@PREFIX} /keyAdmin give <player> <Key ID> <Amount>"
stop
if arg 3 is not set:
send "{@PREFIX} Please specify an ID"
send "/keyAdmin /keyAdmin give %arg 3% <Key ID> <Amount>"
stop
set {_ID} to arg 3 parsed as a number
if {keyBP::k::%{_ID}%} is not set:
send "{@PREFIX} Invalid ID"
stop
if arg 4 is not set:
send "{@PREFIX} Please specify an number"
send "/keyAdmin /keyAdmin give %arg 3% %arg 4% <Amount>"
stop
if arg 4 parsed as number is not greater than 0:
send "{@PREFIX} Invalid number: %arg 4% MAX: {@KEY_LIMIT}"
stop
if arg 4 parsed as a number is greater than {@KEY_LIMIT}:
send "{@PREFIX} Invalid number: %arg 4% MAX: {@KEY_LIMIT}"
stop
add arg 4 parsed as a number to {keyBP::p::%{_player}%::Inv::%{_ID}%}
if {keybp::p::%{_player}%::Inv::%{_ID}%} > {@KEY_LIMIT}:
set {keybp::p::%{_player}%::Inv::%{_ID}%} to {@KEY_LIMIT}
send "{@PREFIX} Added %arg 4% Keys (ID: %{_ID}%) to %{_player}%"
send "{@PREFIX} {@MESSAGE_PLAYER_GET_1} %arg 4% {@MESSAGE_PLAYER_GET_2}" to {_player}
stop
if arg 1 is "take":
set {_player} to arg 2 parsed as a player
if {_player} is not set:
send "{@PREFIX} Player not found!"
send "{@PREFIX} /keyAdmin take <player> <Key ID> <Amount>"
stop
if arg 3 is not set:
send "{@PREFIX} Please specify an ID"
send "/keyAdmin /keyAdmin take %arg 3% <Key ID> <Amount>"
stop
set {_ID} to arg 3 parsed as a number
if {keyBP::k::%{_ID}%} is not set:
send "{@PREFIX} Invalid ID"
stop
if arg 4 is not set:
send "{@PREFIX} Please specify an number"
send "/keyAdmin /keyAdmin take %arg 3% %arg 4% <Amount>"
stop
if arg 4 parsed as number is not greater than 0:
send "{@PREFIX} Invalid number: %arg 4% MAX: {@KEY_LIMIT}"
stop
if arg 4 parsed as a number is greater than {@KEY_LIMIT}:
send "{@PREFIX} Invalid number: %arg 4% MAX: {@KEY_LIMIT}"
stop
subtract arg 4 parsed as a number from {keybp::p::%{_player}%::Inv::%{_ID}%}
if {keybp::p::%{_player}%::Inv::%{_ID}%} < 0:
set {keybp::p::%{_player}%::Inv::%{_ID}%} to 0
send "{@PREFIX} Removed (at most) %arg 4% keys from %{_player}%"
send "{@PREFIX} {@MESSAGE_PLAYER_TAKE}" to {_player}
stop
if arg 1 is "clear":
set {_player} to arg 2 parsed as a player
if {_player} is not set:
send "{@PREFIX} Player not found!"
send "{@PREFIX} /keyAdmin clear <player>"
stop
clear {keyBP::p::%{_player}%::Inv::*}
send "{@PREFIX} %{_player}%'s Keys have been cleared"
send "{@PREFIX} {@MESSAGE_PLAYER_CLEAR}" to {_player}
stop
if arg 1 is "peek":
set {_player} to arg 2 parsed as a offline player
if {_player} is not set:
send "{@PREFIX} Player not found!"
send "{@PREFIX} /keyAdmin peek <player>"
stop
send "{@PREFIX} %{_player}x%%'s keys"
loop {keyBP::p::%{_player}%::Inv::*}:
send "ID: %loop-index% | Amount: %loop-value%"
stop
#No argument is given
if arg 1 is not set:
send "-------{@PREFIX}-------"
send "Global Commands"
send "-----------------------"
send "Create: create a new key"
send "Edit: edit an existing key"
send "Delete: delete an existing key"
send "List: list all keys"
send "Info: list the info of 1 key"
send "-----------------------"
send "Player specific commands"
send "-----------------------"
send "Give give a key to a player"
send "Take: remove a key from a player"
send "Clear: clear all keys from a player"
send "Peek: see what keys a player has"
stop
#Invaild Argument
send "{@PREFIX} Invalid Command"
on rightclick:
if held item is a {@CHEST_TYPE}:
if line 2 of the lore of held item is "{@CHEST_LORE_2}":
if line 1 of the lore of held item is "{@CHEST_LORE_1}":
cancel event
keyBPPlayerList(player, 1)
on drop:
if {@CHEST_CAN_DROP} is false:
if line 2 of the lore of held item is "{@CHEST_LORE_2}":
if line 1 of the lore of held item is "{@CHEST_LORE_1}":
cancel event
on join:
set {keyBP::p::%player%} to uuid of player