Cześć, chciałem stworzyć start i koniec map parkour vectorami, ale nie dziala.
Config:
Start:
Parkour:
'1':
Loc1:
World: flatworld
X: 111
Y: 6
Z: 13
Loc2:
World: flatworld
X: 111
Y: 6
Z: 14
Loc3:
World: flatworld
X: 110
Y: 6
Z: 14
End:
Parkour:
'1':
Loc1:
World: flatworld
X: 120
Y: 6
Z: 23
Kod obliczania vectora
public Vector matchVectors(int Fx, int Fy, int Fz, int Sx, int Sy, int Sz)
{
Vector from = new Vector(Fx, Fy, Fz);
Vector to = new Vector(Sx, Sy, Sz);
Vector vector = to.subtract(from);
return vector;
}
Pobieranie lokacji z configu:
public void MoveallStartLocations(PlayerMoveEvent e) {
Player p = e.getPlayer();
UserUtil uu = new UserUtil();
String locationToStart = "Start." + "Parkour." + uu.getParkourActive(p) + ".";
Block block = e.getTo().getBlock().getRelative(BlockFace.DOWN);
ConfigurationSection cs = cf.getConfig().getConfigurationSection(locationToStart);
if (cs != null) {
for (String key : cs.getKeys(false)) {
World w = Bukkit.getWorld(cf.getConfig().getString(locationToStart + key + ".World"));
int x = cf.getConfig().getInt(locationToStart + key + ".X");
int y = cf.getConfig().getInt(locationToStart + key + ".Y");
int z = cf.getConfig().getInt(locationToStart + key + ".Z");
Location loc = new Location(w, x, y, z);
locationStart.add(loc);
// This is the key,so loc1, loc2, loc3, etc. You can use this key to fetch individual locations using a simple config.getDouble("locations." + entry.getKey() + ".x") for example.
}
}
for (Location location : locationStart) {
int yFixed = location.getBlockY() -1;
Vector v = matchVectors(location.getBlockX(), location.getBlockY(), location.getBlockZ(), location.getBlockX(), location.getBlockY() + 2, location.getBlockZ());
if (block.getLocation().equals(v)) {
if(uu.getStarted(p) == false && !playertimer.containsKey(p.getName()) && uu.getParkourActive(p) > 0)
{
p.sendMessage(MainUtil.convert("&8> &7You started &6" + pu.getName(uu.getParkourActive(p)) + " &7course!"));
uu.setStarted(true, p, p.getUniqueId().toString());
playertimer.put(p.getName(), new Timer(p));
su.createScoreboard(p, "test", true);
break;
}
}
}
}
public void setStart(int id, Player p, int number) {
String locationToStart = "Start." + "Parkour." + id + ".Loc" + number;
if (!cf.getConfig().contains(locationToStart)) {
cf.getConfig().set(locationToStart + ".World", p.getLocation().getBlock().getWorld().getName());
cf.getConfig().set(locationToStart + ".X", p.getLocation().getBlock().getX());
cf.getConfig().set(locationToStart + ".Y", p.getLocation().getBlock().getY());
cf.getConfig().set(locationToStart + ".Z", p.getLocation().getBlock().getZ());
cf.save();
} else {
p.sendMessage(MainUtil.convert("&8> &7This location number was already created!"));
}
}
a tutaj mam tworzenie takiego startu.
Nie wiem czy czegos nie pomyliłem w vectorze, bo pobierajac normalnie lokacje i sprawdzajac czy gracz nachodzi na daną lokacje działa bez problemu.