26.03.2016, 17:10
Hi again, seems the gamemode reloader isn't working anymore, it doesn't reload the gamemode once I updated it, I must close it and then start it again with startup.bat (On Windwos, I haven't tested it on Linux)
Another thing is the mapandreas class. I tried using mapandreas using the following class:
And this is my code:
But it teleports me most of the time 100 meters above or 1 meter below the map.
PHP код:
# Additional plugins
plugins:
- net.gtaun:shoebill-gamemode-reloader:1.0-SNAPSHOT
# Your gamemode
gamemode:dev.acesamp:Gamemode:1.0-SNAPSHOT
PHP код:
/*
* MapAndreas mapAndreas = new MapAndreas(new File(getDataDir(), "SAfull.hmap"));
* float z = mapAndreas.findZ(player.getLocation().x, player.getLocation().y);
* mapAndreas.close();
*
* */
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
public class MapAndreas
{
private MappedByteBuffer mappedByteBuffer;
public MapAndreas(File mapAndreadData) throws IOException
{
FileInputStream in = new FileInputStream(mapAndreadData);
FileChannel fileChannel = in.getChannel();
mappedByteBuffer = fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, fileChannel.size());
fileChannel.close();
in.close();
}
public void close()
{
if (mappedByteBuffer == null) return;
synchronized (mappedByteBuffer)
{
mappedByteBuffer = null;
}
}
public float findZ(float x, float y)
{
if (mappedByteBuffer == null) return 0.0f;
if (x < -3000.0f || x > 3000.0f || y > 3000.0f || y < -3000.0f) return 0.0f;
synchronized (mappedByteBuffer)
{
int gridX = ((int) x) + 3000;
int gridY = (((int) y) - 3000) * -1;
int dataPos = (gridY * 6000) + gridX;
mappedByteBuffer.position(dataPos);
int ch1 = Byte.toUnsignedInt(mappedByteBuffer.get()), ch2 = Byte.toUnsignedInt(mappedByteBuffer.get());
return ((float) ((ch2 << 8) + (ch1))) / 100.0f;
}
}
}
PHP код:
try {
mapObject = new MapAndreas(new File(Gamemode.getInstance().getDataDir(), "SAfull.hmap"));
} catch (IOException e) {
e.printStackTrace();
}
PHP код:
public void onPlayerClickMap(Player player, Vector3D pos){
float z = Server.getMapAndreas().findZ(pos.getX(), pos.getY());
player.setLocation(pos.getX(), pos.getY(), z);
}
}