Question

I started working on my own Minecraft PvP mod and I ran into a wall trying to figure out how to store the players' data. The first version of the mod is "pick-up" style team deathmatch. (Pick-up style is when you and your friends decide the teams and set the win conditions, like a bunch of neighborhood kids creating a football game.)

I thought about using a hashmap to store the player names and their team value while the teams are being set up (I'm shooting for 2 teams at after but would like to have more later). When the game starts I would switch to something else to store player points, assists, deaths, etc. and need to keep a running total of each teams total points. It seems like I should be able to do this with one structure though. I'm not sure it the hashmap would be useful later.

I'm also going to want to be able to sort the players by team and have a scoreboard that ranks the players from high to low. The data needs to be quick to access and sort. Players can only score 1 point per kill so maybe a bubble sort-like method would work.

I think I'm on the right track but I wanted to see if there was a better way. Any suggestions would be much appreciated. If there's another StackExchange for this let me know.

Note: I'm using Bukkit to write the mod because it's server side.

Was it helpful?

Solution

I would recommend creating a Team class, having either a List or Map of teams to hold them. No need to use a different container while creating the teams and during the game itself.

Then you can put in your Team class a List or Map of players, the score of the team, whatever else a team might need to hold and all the methods needed to access that informations.

Keep it simple.

As far as the sorting goes, Collections sorts should work well with that number of players. Unless you think you can implement a faster sort...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top