Hey,
I want to create a mysql home Plugin. I found out, that there are functions like the teleporthelper, but I cant use them in combination with a command source.
Please can you show me how it would look, if I want to get the coordinates from a command sorce and save x,y,z in 3 variables ?
Greets
you would need 4 variables actuallyâŚ1 for the world, 3 for the coordinates, to do it that wayâŚ
thats great by the way - can you say me how i perform this ? ^^
Presumedly the only command-souce making a âhomeâ would be a player⌠youâre not worrying about the console - no physical presence - or a command-block issuing the command. Or another pluginâŚ
so:
if (src instanceof Player){
Player player = (Player) src;
Location pLoc = player.getLocation();
World world = (World) pLoc.getExtent();
String worldname = world.getName();
int x=pLoc.getBlockX();
âŚetc for y, z coords
Though really, if you are just using a key/value system : âHomeXâ for âPlayerXâ = âLocationXâ⌠you dont need to break the location down into all of its individual smallest compoents for storing and then build it back up again, unless you will have reasons for wanting x, y , z as separate fields in the database for a reason, or worlds to be separate.
You can store the location object as a string, or serialize it. Or you can pull the world part out from a location, and the coordinate-vector part out of a location, and store world as one field, and the position vector as another, which is less messy strings than a location object stringâŚ
thanks the idea is, that i want (as u said) to store homes in my mysql db ^^
when its possible, i will store the location as it is in my db
I have another question ^^
When i stored it, and the player runs something like /home, how can i teleport the player to the saved location ?
Another question:
When I create the new Location with the 4 vars â location = new Location(var,var, var, var) , right ?
Greets
I believe thatâs correct. You then change the location of the player with
player.setLocation(Location location)
And donât forget to offer() it back to the server once itâs changed! I believe this will result in this code snippet:
offer(player.setLocation(Location location))
ok, so after i changed the location of a player, i just hafe to run this:
offer(player.setLocation(Location location)) ? ^^ (with my variables)
why i have to do this ?
Think of it as forcing a refresh to assert that it is not an illegal movement at mach 7
1 Like
Youâll notice that the contents of the offer() is the location setting in the first snippet, so you donât need both lines
Iâm not entirely sure why you have to do this, but perhaps the player object you manipulate is a snapshot of the dynamic one used by the game itself, to ensure your variables donât dynamically change while youâre working on them? I didnât make it, and I donât know Java, but Iâve been on these forums for long enough to pick up some howâs. The whyâs I leave to the Sponge team
I think this is a part of the Data API, so perhaps @gabizou would be able to enlighten us?
yeah, i know, that i donât have to use the code again, but I hope too, that someone can explain offer()
wait what? You arenât offering anything back⌠player.setLocation(Location)
works just fine. The only things you offer
are DataManipulator
s (and soon Value
s).
1 Like
In that case, I stand corrected. Offer() isnât necessary.