resourceworld.sk

Created by Sombrerian

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.

options:
	#
	# What should the name of your resource world be?
	world: resource_world
	#
	# VERY IMPORTANT!
	# Skript file name (resourceworld.sk)
	# Every time a new resource world is created, we reload this file,
	# so newly created world can be recognized by Skript. If you rename
	# "resourceworld.sk" to something else, you must do that here as well!
	filename: resourceworld.sk
	#
	# Minimum X & Z coordinates.
	minimumxz: -1000
	#
	# Maximum X & Z coordinates.
	maximumxz: 1000
	#
	# Reset timer (in seconds)
	# How ofter should we reset the resource world?
	# 24 hours: 86400 seconds,
	# 3 days: 259200 seconds,
	# 1 week: 604800 seconds etc...
	resettimer: 86400
	#
	# Specify blocks to avoid from being dropped on. It is highly recommended to not
	# remove default values, unless you want players drowning in lava.
	# Valid blocks that can be blacklisted: https://github.com/SkriptLang/skript-aliases/blob/master/building.sk
	blockblacklist: lava or water or cactus or bamboo or stone or any leaves
	#
	# How many times should we attempt to randomly teleport a player before giving up?
	# This depends on blacklisted blocks. For example, if first location attempt
	# is lava (assuming lava is under "blockblacklist"), then we increase attempt amount by 1 and try
	# to find a new location for the player. Recommended and probably the most appropriate value is 20.
	maxattempts: 20
	#
	# How long should the delay (in ticks) between teleportation attempts be?
	# Lower value means faster teleportation attempts, but possible lag.
	# It is recommended to keep this set to 5 (meaning max 4 attempts per second)
	# 20 ticks = 1 second
	attemptdelay: 5
	#
	# Warmup message
	# Let players know that they are getting teleported to resource world.
	# -
	# Set to "none" to disable this feature.
	warmupmessage: "&aHang tight... Looking for a safe spot!"
	#
	# Drop-off message
	# Let players know that they were successfully teleported to resource world.
	# -
	# Set to "none" to disable this feature.
	dropoffmessage: "&aYou have been dropped off at %location at player%"
	#
	# Resource world reset message
	# Should we announce that resource world is about to reset?
	# -
	# Set to "none" to disable this feature.
	announceresetmessage: "&aIts time for a new resource world, resetting now!"
	#
	# Console Post-reset command
	# This is completely optional, but pretty useful in some cases.
	# Post command is executed 1 second after resource world is reset.
	# Set this to "none" if you don't wish to use post a command.
	# -
	# Useful examples?
	# postresetcommand: "/eco give * 100"
	# postresetcommand: "/heal *"
	# postresetcommand: "/effect give @a minecraft:glowing 10"
	# postresetcommand: "/tell * Hello World"
	# postresetcommand: "/broadcast Everyone sees this!"
	postresetcommand: "none"
	#
	# Console Post-TP command
	# Same as Post-reset command... but executed every time a player teleports to resource world.
	# Use %player% if you want to run a command specifically with that player's name. For example,
	# if a player by the name of "Bob" teleports to resource world while Post-TP command is set to
	# "/kick %player%", then Bob gets kicked.
	posttpcommand: "none"
	#
	# Dedicated command
	# Just in case you don't want players constantly typing /rw tp.
	# This can be set to any non-existent command.
	dedicatedcommand: /rworld
	#
	# Command cooldown (in seconds)
	# Set this to 0 for no cooldown.
	rwcooldown: 120
	#
	# Decreased command cooldown (in seconds)
	# Possible donator perk? Players with permission "resourceworld.decreasedcooldown" will be
	# cooled down for amount of seconds specified here, instead of regular "rwcooldown".
	# Set this to 0 for no cooldown.
	rwdecreasedcooldown: 20
	#
	# Cooldown message
	# Players will be presented with this message when they try to randomly teleport while on cooldown.
	# Only works if cooldowns are enabled.
	# %{rwcooldown.%player%}% is the placeholder to show remaining seconds.
	cooldownmessage: "&cYou are on cooldown, %{rwcooldown.%player%}%&c seconds remain!"
	#
	# Particle mode
	# Particles are summoned at player's location once successfully teleported to resource world.
	# Valid switches: none, ball, splash
	# -
	# none: Disable particles
	# ball: Particles summoned in a 'ball'-a-like shape
	# splash: Particles summoned beneath the player
	particlesmode: "ball"
	#
	# Particle effect radius
	# Only applies if you have particles set to "ball" or "splash".
	particleradius: 2
	#
	# Particle type
	# List of valid particles: https://www.digminecraft.com/lists/particle_list_pc.php
	# -
	# Make sure to exclude underscores! For example, if you are setting your particle to
	# enchanted_hit, remove _, having the final value set as: enchanted hit
	particlestype: happy villager
	#
	# Sound effect
	# List of valid sounds: https://www.digminecraft.com/lists/sound_list_pc.php
	# Set this to "none" if you don't wish to use sound effects.
	# -
	# Make sure to reaplce all dots with underscores! For example, if you are setting your sound effect
	# to "BLOCK.BEEHIVE.SHEAR", replace all . with _, having the final value set as: "BLOCK_BEEHIVE_SHEAR"
	soundeffect: "ENTITY_ENDER_DRAGON_SHOOT"
	#
	# Smart location search
	# When teleporting to resource world, the location which you are dropped off at is truly random...
	# ...however servers tend to become laggy when chunks attempt to load out of the blue, especially
	# on higher player counts.
	# -
	# Enabling smartsearch fixes this issue by storing exactly 32 safe locations and picking one
	# where we then drop off the player. This will 100% fix chunk lag in case you are experiencing
	# it when teleporting to the resource world.
	# -
	# Chunk lag is greatly decreased when players walk/fly into an unloaded chunk rather than getting
	# teleported directly into it.
	smartsearch: false
	#
	# Permission to use /resourceworld (and alias) administrative commands.
	# Keep in mind that "resourceworld.use" is still needed no matter if
	# player already has superuser "resourceworld.superuser" permission.
	# Administrative commands: /rw reset, /rw setspawn
	superuserpermission: resourceworld.superuser
	#
	# Permission to use /resourceworld (and alias) commands.
	cmdpermission: resourceworld.use
	#
	# Should we enable debug mode?
	# This will play unnecessary, but useful chat messages to the player.
	# Valid switches: true/false
	debug: false
	#
	#-------------------------------
	# Resource world options bellow
	#-------------------------------
	# World difficulty
	# Valid switches: peaceful, easy, normal, hard
	rwdifficulty: hard
	#
	# Daylight cycle
	# Valid switches: true/false
	rwdaylightcyctle: true
	#
	# Weather cycle
	# Valid switches: true/false
	rwweathercyctle: true
	#
	# Mob spawning
	# Valid switches: true/false
	rwmobs: true
	#
	# PVP state
	# Valid switches: true/false
	rwpvp: true
	#
	# Keep inventory
	# Valid switches: true/false
	rwkeepinventory: false

command /resourceworld [<text>]:
	permission: {@cmdpermission}
	permission message: &cNo permission!
	aliases: /rw, /resw
	trigger:
		if arg-1 is set:
			if arg-1 is "setspawn":
				if executor has permission "{@superuserpermission}":
					set {rw.setspawn} to location at player
					send "&aPlayers that are in resource world at time of reset will now be teleported to X: %player's x coordinate%&a, Y: %player's y coordinate%&a, Z: %player's z coordinate%&a in world %player's world%&a!" to player
			if arg-1 is "reset" or "create":
				if executor has permission "{@superuserpermission}":
					if {@announceresetmessage} is not "none":
						broadcast {@announceresetmessage}
					send "&a&l[Resource World] &aCleaning up..."
					set {maxlocations} to 32
					delete {possiblexz::*}
					set {rw.timer} to {@resettimer}
					loop all players:
						if loop-player's world is "{@world}":
							teleport loop-player to {rw.setspawn}
					wait 5 ticks
					send "&a&l[Resource World] &aDeleting current resource world..."
					execute console command "/mv delete {@world}"
					wait 10 ticks
					execute console command "/mv confirm"
					wait 10 ticks
					send "&a&l[Resource World] &aCreating a new resource world..."
					execute console command "/mv create {@world} normal"
					wait 2 seconds
					send "&aDone!"
					send "&r"
					send "&eThe following settings were applied:"
					execute console command "/mvm set diff {@rwdifficulty} {@world}"
					send "&8- &fDifficulty: &a{@rwdifficulty}"
					wait 1 tick
					if {@rwdaylightcyctle} is false:
						execute console command "/mvrule doDaylightCycle false {@world}"
						send "&8- &fDaylight cycle: &cdisabled"
					else:
						send "&8- &fDaylight cycle: &aenabled"
					wait 1 tick
					if {@rwweathercyctle} is false:
						execute console command "/mvrule doWeatherCycle false {@world}"
						send "&8- &fWeather cycle: &cdisabled"
					else:
						send "&8- &fWeather cycle: &aenabled"
					wait 1 tick
					if {@rwmobs} is false:
						send "&8- &fMob spawning: &cdisabled"
					else:
						send "&8- &fMob spawning: &aenabled"
					wait 1 tick
					if {@rwpvp} is false:
						send "&8- &fPVP: &cdisabled"
					else:
						send "&8- &fPVP: &aenabled"
					wait 1 tick
					if {@rwkeepinventory} is false:
						send "&8- &fKeep inventory: &cdisabled"
					else:
						send "&8- &fKeep inventory: &aenabled"
					wait 1 tick
					execute console command "/sk reload {@filename}"
					if {@postresetcommand} is not "none":
						wait 1 second
						execute console command {@postresetcommand}
			if arg-1 is "tp" or "teleport":
				if {rwcooldown.%player%} exists:
					send {@cooldownmessage} to player
					stop
				if {@warmupmessage} is not "none":
					send {@warmupmessage} to player
				if {@debug} is true:
					send "&7&oMaximum location search attempts: {@maxattempts}" to player
				loop {@maxattempts} times:
					if {@debug} is true:
						send "&7&oDelaying location search attempt for: {@attemptdelay}&7&o ticks..." to player
					wait {@attemptdelay} ticks
					set {_x} to random integer from {@minimumxz} to {@maximumxz}
					set {_y} to 50 # Just to avoid most caves
					set {_z} to random integer from {@minimumxz} to {@maximumxz}
					if {@smartsearch} is true:
						if {maxlocations} = 0:
							loop {possiblexz::*}:
								add 1 to {_total}
							if {@debug} is true:
								send "&7&oThere are a total of %{_total}%&7&o stored (smart) locations, picking one&7&o..." to player
							set {_cords} to random integer from 1 to {_total}
							loop {possiblexz::*}:
								add 1 to {_count}
								if {_count} = {_cords}:
									set {_smartlocation} to loop-value-2
									if {@debug} is true:
										send "&7&oPicked a smart location (%{_cords}%&7&o) %{_smartlocation}%&7&o..." to player
					if {_smartlocation} does not exist:
						set {_location} to location at ({_x}, {_y}, {_z}) in world "{@world}"
						set {_block} to block at {_location}
					else:
						set {_location} to location at {_smartlocation}
						set {_block} to block at {_location}
					loop all blocks above {_block}:
						if loop-block is air:
							if block under loop-block is {@blockblacklist}:
								if {@debug} is true:
									send "&7&oFailed resource world teleport attempt (blacklisted block: %block under loop-block%&7&o). Retrying..." to player
								exit loop
							add 1 to {_i}
							if {_i} >= 2:
								teleport player above loop-block
								if {maxlocations} >= 1:
									remove 1 from {maxlocations}
									add {_location} to {possiblexz::*}
									if {@debug} is true:
										send "&7&oSafe location %{_location}%&7&o added to the list of safe locations..." to player
								if player has permission "resourceworld.decreasedcooldown":
									add {@rwdecreasedcooldown} to {rwcooldown.%player%}
								else:
									add {@rwcooldown} to {rwcooldown.%player%}
								if {@dropoffmessage} is not "none":
									send {@dropoffmessage} to player
								if {rw.setspawn} is not set:
									send "&cMissing resource world setup! Tell an Administrator to set resource world reset spawnpoint using /rw setspawn" to player
								if {@soundeffect} is not "none":
									play sound {@soundeffect} with volume 100 and pitch 1 at player for player
								if {@particlesmode} is not "none":
									wait 10 ticks
									if {@particlesmode} is "ball":
										loop all blocks in radius {@particleradius} around player:
											play 1 ({@particlestype} with speed 0) at block at loop-block-2
									else if {@particlesmode} is "splash":
										set {_y} to loop-block's y coordinate
										remove 1 from {_y}
										loop all blocks in radius {@particleradius} around player:
											if loop-block-2's y coordinate is {_y}:
												play 1 ({@particlestype} with speed 0) at block at loop-block-2
								if {@posttpcommand} is not "none":
									wait 1 second
									execute console command {@posttpcommand}
								stop
		else:
			set {_timer} to "%{rw.timer}% seconds" parsed as timespan
			send "&aResource world will be reset in %{_timer}%&a (or in exactly %{rw.timer}%&a seconds)" to player
			
command {@dedicatedcommand}:
	permission: {@cmdpermission}
	permission message: &cNo permission!
	trigger:
		execute player command "/rw tp"
					
every 1 second:
	loop all players:
		if {rwcooldown.%loop-player%} exists:
			if {rwcooldown.%loop-player%} <= 1:
				delete {rwcooldown.%loop-player%}
			else:
				remove 1 from {rwcooldown.%loop-player%}
	if {rw.timer} <= 1:
		set {rw.timer} to {@resettimer}
		execute console command "/rw reset"
	else:
		remove 1 from {rw.timer}
		
# Yes... This is the workaround used to disable mob spawning (since "/mvrule doMobSpawning false" didn't seem to work?)
# This was tested and it doesn't affect performance, so it should be fine as of now.
# I've noticed a lot of Multiverse rules don't work... Please let me know on Discord (Sombrerian#0509) if you find a solution.
# -
# All of Skript you see bellow this line serves as workarounds to Multiverse gamerules.
every 2 ticks:
	if {@rwmobs} is false:
		loop all mobs:
			if loop-mob is in world "{@world}":
				delete loop-mob
				
on damage of player:
	if victim is in world "{@world}":
		cancel event
	if attacker is set:
		if victim is in world "{@world}":
			if {@rwpvp} is false:
				send "&cPVP is disabled here!" to attacker
				cancel event
				
on death of player:
	if player is in world "{@world}":
		if {@rwkeepinventory} is true:
			keep inventory