Java HashMap - String to bukkit Vector? How? -


i didn't see answered question , i'm stuck. gist of i'm storing vector inside hashmap string, so:

notes.put(notes.size()+1), player.getlocation().getdirection().tostring());

notes hashmap name. since hashmaps seemingly store strings, need way convert vector.

later in code, implement vector later this:

`player.getlocation().setdirection(vector);` 

when couldn't think of way around conversion, tried mathematical way of calculating direction facing so:

`double pit = ((parsed[4]+ 90) * math.pi) / 180; double ya = ((parsed[3]+ 90) * math.pi) / 180; double newx = math.sin(pit) * math.cos(ya); double newy = math.sin(pit) * math.sin(ya); double newz = math.cos(pit); vector vector = new vector(newx, newz, newy);` 

pit being pitch , ya being yaw. parsed[3] , parsed[4] original pitch , yaw of player. again didn't work , sent error server console. [error]: null. in short, want way convert string vector. i'd prefer not math way if don't have choice, it. , constructive criticism appreciated; in advance!

as side note: i'm new java have experience in c , javascript, lot of things familiar me.

hashmaps aren't limited storing strings. can store object, including vectors

map<integer, vector> mymap = new hashmap<integer, vector>(); 

so, instead of worrying converting string vector, store vectors in hashmap

map<integer, vector> notes = new hashmap<integer, vector>();  //add vector map notes.put(notes.size() + 1, player.getlocation().getdirection());  //get vector out of map vector playervector = notes.get(notes.size()); 

also, way you're writing it, use arraylist

list<vector> notes = new arraylist<vector>();  //add vector array notes.add(player.getlocation().getdirection());  //get vector out of map vector playervector = notes.get(notes.size()); 

if change string vector reason, use

//get x, y, , z values of vector array string[] components = vectorstring.split(",");  //components[0] x value, [1] y, , [2] z. double x = double.valueof(components[0]); double y = double.valueof(components[1]); double z = double.valueof(components[2]);  //construct vector using components vector myvector = new vector(x, y, z); 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -