0% found this document useful (0 votes)
18 views

Config Bestpractise

The document discusses storing arena data from different game types in a consistent way. It proposes: 1) Creating an Arena class with common properties like a unique ID, name, spawn location, and cuboid area. Game-specific classes like RaceArena and SpleefArena would extend this class and add additional properties. 2) Storing each arena's data in a configuration file using the unique ID as the key and the arena's properties as values. This allows flexible storage of nested data like checkpoints for a race arena. 3) An alternative of storing all an arena's data in a Map object when saving, but this is less flexible for nested types like checkpoints.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Config Bestpractise

The document discusses storing arena data from different game types in a consistent way. It proposes: 1) Creating an Arena class with common properties like a unique ID, name, spawn location, and cuboid area. Game-specific classes like RaceArena and SpleefArena would extend this class and add additional properties. 2) Storing each arena's data in a configuration file using the unique ID as the key and the arena's properties as values. This allows flexible storage of nested data like checkpoints for a race arena. 3) An alternative of storing all an arena's data in a Map object when saving, but this is less flexible for nested types like checkpoints.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Alright lets say we have a bunch of data from classes.

As example Ill use an Arena with data like a cuboid, spawn point, name etc

The example
So we have a class like

public
class

Arena

protected

UUID

uid;

protected

String name;

protected

Cuboid cuboid;

protected

Location spawn;

protected

List<

UUID
>
players
=
new

ArrayList<

UUID
>
();

public

Arena

(UUID
uid
, String
name
) {

this

.
uid
=
uid;

this

.
name
=
name;
}

//Etc etc...

Now we would want to store each arena by its UID and store the name, cuboid and spawn.
We would have other classes extend from this Arena class with extra data.
For example if we were to make a race game we would create RaceArena and it would have extra data like a
cuboid for the finish and a map with checkpoints like <Integer(index), CheckPoint>
Checkpoint would then consist of a location where the player would respawn and a cuboid that will trigger
the checkpoint.
Then to make the example more clear we add another game like Spleef and we create a SpleefArena.
This would have a cuboid for the floor to protect it and reset it etc.
So the ideal config would be similar to this.
{uid}
:
#Race arena.
name
:
{name}
spawn
:
{location}

cuboid
:
{cuboid}
checkpoints
:
'1'
:
location
:
{location}
cuboid
:
{cuboid}
'2'
:
etc
:
...
finish
:
{cuboid}

{uid}
:
#Spleef arena.
name
:
{name}
spawn
:
{spawn}
cuboid
:
{cuboid}
floor
:
{cuboid}

Options
Config per arena
A configuration file per arena.
The arena class would have a YamlConfiguration and it would use the values directly from the config
instead of storing them internally in the arena class.

public
class

Arena

{
protected

YamlConfiguration cfg;

public

void

setName

(String
name
) {

cfg
.
set(
"name"
, name);

public

String
getName
() {

return

cfg
.
getString(
"name"
);

Or alternatively store the data in the class too and when setting set it both in the class and config.
Havent really looked into configs so not sure if its an expensive call to do cfg.get

Convert data to map on save.


When the arena gets saved then go through all the data and put it into a map.
public
Map<String,Object>getData(){
Map<String,Object>data=
new
HashMap<String,Object>()
data.put(
"name"
,
name
)
data.put(
"spawn"
,
spawn
)

return
data
}

Something like that and then it would save the map.


But the biggest downside of this is that it would not support nested data.
For example the checkpoints it would not be doable doing it this way.

You might also like