Backpacks v3.3.sk

Created by using

Just so you know, we don't know the file format for every file. If it's just a bunch of random characters, it's probably a .zip or .jar.

#
# ____             _                     _               ____  
# |  _ \           | |                   | |             |___ \ 
# | |_) | __ _  ___| | ___ __   __ _  ___| | _____  __   ____) |
# |  _ < / _` |/ __| |/ / '_ \ / _` |/ __| |/ / __| \ \ / /__ < 
# | |_) | (_| | (__|   <| |_) | (_| | (__|   <\__ \  \ V /___) |
# |____/ \__,_|\___|_|\_\ .__/ \__,_|\___|_|\_\___/   \_/|____/ 
#                        | |                                     
#                        |_|       
#
# Backpacks v3.3
# Now stored totally in NBT! No variables!
#
# And once again, a recode.
# The v2 was never posted, but it exists.
#
# What's new?
# - You can define the number of rows.
# - Only the ID appears in the lore (as it can be useful).
# - Backpacks can be renamed.
# - Pure NBT, no more databases.
# - More optimised?
#
# Needed addons:
# - skStuff.
# - skQuery.
#

#
# Configuration
# It is recommended to customize only here.
# No support will be given with edited code.
#
options:

	# The DEFAULT name of the backpack item.
	# It can be change if you shift + rightclick the backpack.
	backpack.name : &dBackpack
	
	# Lore of the backpack item. New lines can be specified by using '||'.
	backpack.lore : &7Use an anvil to customize||&7your amazing backpack!
	
	# Item to be used as backpack.
	# You can use anything, blocks won't be placed.
	backpack.item : chest
	
	# Name of inventory that opens when you open a backpack, to detect if it's a backpack and save it.
	# More than 30 characters in the name of the inventory will cause a crash.
	backpack.inventoryname : Backpack
	
	# The sound when the backpack opens & closes.
	# Under the sound is the pitch, that sets how 'acute' is the sound (bigger numbers means more acute sounds).
	# The list of sounds can be found here: http://www.theredengineer.com/1.9-playsound-list.html
	backpack.sound.open : entity horse armor
	backpack.sound.open.pitch : 1
	
	backpack.sound.close : entity horse armor
	backpack.sound.close.pitch : 2
	
	# These are the backpack prices.
	# Set a different price for each size.
	# Use the following example:
	# 500-1500-3000-4000-7000-10000 | Meaning $500 for 1 row, $1500 for 2 rows, $3000 for 3 rows... up to six.
	#
	# Remember that you will need VAULT installed.
	# You can still sell the backpacks using plugins like ChestShop, and craftings with https://www.spigotmc.org/resources/custom-recipes.11440/.
	backpack.buy.eachsize : 500-1500-3000-4000-7000-10000
	
#
# Messages
# If you want to add a default translation, please PM me on skUnity! (user: EWS)
#
	
	# This message shows up when you use "/backpack (buy|pucharse) [rows number | 1-6]" wrongly.
	# Default: "&7Usage: /backpack (buy|pucharse) [rows number | 1-6]."
	backpack.msgs.buy.wrongly: "&7Usage: /backpack (buy|pucharse) [rows number | 1-6]."
	
	# This message shows up when you misconfigurate the prices in the script and tries do buy something.
	# Default: "&7An error occured, please contact an admin and tell him that the 'backpacks' plugin is misconfigurated."
	backpack.msgs.buy.misconfig: "&7An error occured, please contact an admin and tell him that the 'backpacks' plugin is misconfigurated."
	
	# This message is the separator (lines added before and after a message).
	# Default: "&m-|--&3&m------&f&m--------------------------------&3&m------&f&m--|-"
	backpack.msgs.separator: "&m-|--&3&m------&f&m--------------------------------&3&m------&f&m--|-"
	
	# These messages below show up when you don't have enough money to buy a backpack.
	# The third message has only colors separated by commas, because it'll tell you all the prices in 6 lines (one for each price).
	# Default line 01: "&3You don't have enough money to buy this backpack."
	# Default line 02: "&3Take a look at the sizes and prices below:"
	# Default line 03: "3,f,7"
	backpack.msgs.buy.nomoney.1: "&3You don't have enough money to buy this backpack."
	backpack.msgs.buy.nomoney.2: "&3Take a look at the sizes and prices below:"
	backpack.msgs.buy.nomoney.colors: "3,f,7"
	
	# This message shows up when you successfuly buy or get (admin) a backpack.
	# Default: "&7You bought a backpack with &3%arg 2% rows&7!"
	backpacks.msgs.buy.success: "&7You bought a backpack with &3%arg 2% rows&7!"
	
	# This message shows up when you use "/backpack get [rows number | 1-6]" wrongly.
	# Default: "&7Usage: /backpack get [rows number | 1-6]."
	backpacks.msgs.get.wrongly: "&7Usage: /backpack get [rows number | 1-6]."
	
	# This message shows up when you don't have permission to use the command.
	# Default: "&7You are &4not &3cool enough &7to use this."
	backpacks.msgs.noperm: "&7You are &4not &3cool enough &7to use this."
	
	# This message shows up when you stack 2 or more backpacks and the script blocks it.
	# Default: "&7How did you manage to stack &32 backpacks&7?"
	backpack.msgs.abuse.stack: "&7How did you manage to stack &32 backpacks&7?"
	
#
# There is the script code.
# Do not change it if you don't know what you're doing.
#

command /backpack [<string>] [<string>]:
	aliases: backpacks, bp
	permission: backpack.command
	permission message: You do not have the required permission.
	trigger:
		if arg 1 is "buy" or "pucharse":
			if "%arg 2%" is not "1", "2", "3", "4", "5" or "6":
				send {@backpack.msgs.buy.wrongly}
				stop
			set {_sizeprice} to "{@backpack.buy.eachsize}"
			set {_sizeeach::*} to {_sizeprice} split at "-"
			if {_sizeeach::6} is not set:
				send {@backpack.msgs.buy.misconfig}
				stop
			if player's balance is smaller than {_sizeeach::%arg 2%} parsed as number:
				set {_colors::*} to split uncolored {@backpack.msgs.buy.nomoney.colors} at ","
				send {@backpack.msgs.separator}
				send {@backpack.msgs.buy.nomoney.1}
				send {@backpack.msgs.buy.nomoney.2}
				loop {_sizeeach::*}:
					set {_msg} to "&%{_colors::1}%%loop-index%. &%{_colors::2}%Size %loop-index%: &%{_colors::3}%$%loop-value%"
					send "%colored {_msg}%"
				send {@backpack.msgs.separator}
			else:
				give a {@backpack.item} with nbt "{backpack.rows:""%arg 2 parsed as integer%"",backpack.id:""%a random integer between 1000000000 and 9999999999%""}" named "{@backpack.name}" with lore "{@backpack.lore}" to player
				send {@backpacks.msgs.buy.success}
				remove {_sizeeach::%arg 2%} parsed as number from player's balance
			stop
		if arg 1 is "get" or "give":
			if player doesn't have permission "backpack.admin":
				send {@backpacks.msgs.noperm}
				stop
			if "%arg 2%" is not "1", "2", "3", "4", "5" or "6":
				send {@backpacks.msgs.get.wrongly}
				stop
			give a {@backpack.item} with nbt "{backpack.rows:""%arg 2 parsed as integer%"",backpack.id:""%a random integer between 1000000000 and 9999999999%""}" named "{@backpack.name}" with lore "{@backpack.lore}" to player
			send {@backpacks.msgs.buy.success}
			stop
		# Please, do not remove the credits below. They won't affect ANYTHING in your server.
		# I made this script totally free so people can have a good script to create a really cool server.
		send "&b&m-|--------------------------------------------------|-"
		send "&b&lBackpacks &7| &bAn extra help with your items!"
		send "&fAuthor: &7TrademarkTM"
		send "&fVersion: &7v3.3"
		send " "
		send "&3Buy a backpack by using &b/backpack buy [size]&3."
		send "&7Need support with this script? Bug reports? Contact me!"
		send "&7Call me on Discord: EWS##5810."
		send "&b&m-|--------------------------------------------------|-"
			
on rightclick holding a {@backpack.item}:
	if tag "backpack.rows" of nbt of player's held item is set:
		cancel event
		if player doesn't have permission "backpack.use":
			send "&7You don't have permission to use backpacks."
		else:
			if "%player's tool%" contains "1", "2", "3", "4", "5", "6", "7", "8", "9" or "0":
				send {@backpack.msgs.abuse.stack}
			else:
				if inventory name of current inventory of player doesn't contain "{@backpack.inventoryname} |":
					open chest with "%tag ""backpack.rows"" of nbt of player's tool%" parsed as number rows named (first 32 characters of "{@backpack.inventoryname} | %name of player's tool%") to player
					if tag "backpack.items" of nbt of player's tool is not "":
						set {_nbt.replace} to "%tag ""backpack.nbt"" of nbt of player's tool%"
						replace all "'" with """" in {_nbt.replace}
						set {_nbt.list::*} to {_nbt.replace} split at ";"
						set {_items.list::*} to ("%tag ""backpack.items"" of nbt of player's tool%") split at ";"
						loop {_items.list::*}:
							set {_item&data::*} to split "%{_items.list::%loop-index parsed as number%}%" at "?"
							set {_i} to {_item&data::1} parsed as item with nbt "%{_nbt.list::%loop-index parsed as number%}%"
							set data value of {_i} to {_item&data::2} parsed as number
							add {_i} to current inventory of player
					play {@backpack.sound.open} at player with pitch {@backpack.sound.open.pitch}

on inventory close:
	if inventory name of current inventory of player contains "{@backpack.inventoryname} |":
		set {_save.items} and {_save.nbt} to ""
		loop all items in current inventory of player:
			set {_save.items} to "%{_save.items}%;%item amount of loop-value% of %id of type of loop-value%?%data value of loop-value%"
			set {_save.nbt} to "%{_save.nbt}%;%nbt of loop-value%"
		set {_save.items} to the last (length of {_save.items} - 1) characters of {_save.items}
		set {_save.nbt} to the last (length of {_save.nbt} - 1) characters of {_save.nbt}
		set {_save.nbt} to the first 65000 characters of {_save.nbt}
		replace all """" with "'" in {_save.nbt}
		replace all """" with "'" in {_save.items}
		add "{backpack.items:""%{_save.items}%""}" to nbt of player's tool
		add "{backpack.nbt:""%{_save.nbt}%""}" to nbt of player's tool
		play {@backpack.sound.close} at player with pitch {@backpack.sound.close.pitch}
		
on inventory click:
	# @Update 3.2.1
	# Fixes the bug that allows you to place a backpack inside a backpack using keyboard numbers.
	# That bug should be definetely fixed now. Thanks to Bensku for creating this 'inventory action' thing. :P
	if inventory name of current inventory of player contains "{@backpack.inventoryname} |":
		if "%inventory action%" is "swap with hotbar" or "hotbar move and readd":
			cancel event
		if tag "backpack.rows" of nbt of event-item is set:
			cancel event

on tool change:
	if inventory name of current inventory of player contains "{@backpack.inventoryname} |":
		cancel event
		 
# This was really useful in the creation of the script.
# In gratitude (to a command), I upgraded it and kept it here.
command /nbt [<string>]:
	permission: backpack.seenbt
	permission message: &7You cannot use this wonderful command.
	trigger:
		send "&f&m-|------------------------------------------------|-"
		set {_tool} to "%player's tool%" in upper case
		send "&6|| &3NBT of %{_tool}% &6||"
		set {_nbt} to uncolored "%nbt of player's tool%"
		replace all "<none>" with "@no nbt" in {_nbt}
		send "&6- &3NBT tags:"
		send "&7%first 2000 characters of {_nbt}%"
		if arg 1 is set:
			set {_tag} to tag "%arg 1%" of nbt of player's tool
			set {_tag} to "%{_tag}%"
			replace all "<none>" with "@no such tag" in {_tag}
			send "&6- &3Tag %arg 1%:"
			send "&7%{_tag}%"
		send "&f&m-|------------------------------------------------|-"