• Es freut uns dass du in unser Minecraft Forum gefunden hast. Hier kannst du mit über 130.000 Minecraft Fans über Minecraft diskutieren, Fragen stellen und anderen helfen. In diesem Minecraft Forum kannst du auch nach Teammitgliedern, Administratoren, Moderatoren , Supporter oder Sponsoren suchen. Gerne kannst du im Offtopic Bereich unseres Minecraft Forums auch über nicht Minecraft spezifische Themen reden. Wir hoffen dir gefällt es in unserem Minecraft Forum!

Random Teleportation

HeadiPlays

Redstoneengineer
Registriert
8 Februar 2014
Beiträge
45
Diamanten
0
Minecraft
HeadShotNoob
Hallöchen Zusammen ;) ,

ich bin gerade dabei ein kleines MiniGame zu programmieren, jedoch bin ich schon bei meinem ersten Problem,

ich habe in eine Config (locations.yml) die ganzen Coordinaten für Lobby und Spawns gesetzt,
jetzt möchte ich, dass die spieler (gesamt 12) an einen von diesen Orten teleportiert wird, wenn mein sheduler abgelaufen ist!

Danke :D
 

Paulomart

Schafhirte
Registriert
3 November 2013
Beiträge
147
Diamanten
0
Minecraft
Paulomart
Code:
	public static void teleport(Player player, List<Location> locations){
		Random random = new Random();
		player.teleport(locations.get(random.nextInt(locations.size())));
	}
	
	public static void teleport(List<Player> players, List<Location> locations){
		int locI = 0;
		for (Player player : players){
			if (locI >= locations.size()){
				locI = 0;
			}
			player.teleport(locations.get(locI));
			locI++;
		}
	}

Du musst einfach nur teleport(players, locations); benutzen
 

HeadiPlays

Redstoneengineer
Registriert
8 Februar 2014
Beiträge
45
Diamanten
0
Minecraft
HeadShotNoob
lobby:
world: world
x: 0.40489244218415604
y: 66.0
z: 0.514784466429347
yaw: -270.15405
pitch: 72.74983
spawn:
players:
'1':
world: world
x: -2.3906191584904084
y: 66.0
z: 0.5182044720109216
yaw: -270.15405
pitch: 72.74983
'2':
world: world
x: -2.3906191584904084
y: 66.0
z: 0.5182044720109216
yaw: -270.15405
pitch: 72.74983
'3':
world: world
x: -2.3906191584904084
y: 66.0
z: 0.5182044720109216
yaw: -270.15405
pitch: 72.74983
'4':
world: world
x: -2.3906191584904084
y: 66.0
z: 0.5182044720109216
yaw: -270.15405
pitch: 72.74983
'5':
world: world
x: -2.3906191584904084
y: 66.0
z: 0.5182044720109216
yaw: -270.15405
pitch: 72.74983
'6':
world: world
x: -2.3906191584904084
y: 66.0
z: 0.5182044720109216
yaw: -270.15405
pitch: 72.74983
'7':
world: world
x: -2.3906191584904084
y: 66.0
z: 0.5182044720109216
yaw: -270.15405
pitch: 72.74983
'8':
world: world
x: -2.3906191584904084
y: 66.0
z: 0.5182044720109216
yaw: -270.15405
pitch: 72.74983
'9':
world: world
x: -2.3906191584904084
y: 66.0
z: 0.5182044720109216
yaw: -270.15405
pitch: 72.74983
'10':
world: world
x: -2.3906191584904084
y: 66.0
z: 0.5182044720109216
yaw: -270.15405
pitch: 72.74983
'11':
world: world
x: -2.3906191584904084
y: 66.0
z: 0.5182044720109216
yaw: -270.15405
pitch: 72.74983
'12':
world: world
x: -2.3906191584904084
y: 66.0
z: 0.5182044720109216
yaw: -270.15405
pitch: 72.74983
 

Paulomart

Schafhirte
Registriert
3 November 2013
Beiträge
147
Diamanten
0
Minecraft
Paulomart
Code:
	public List<Location> loadLocations(String path){
		List<Location> locations = new ArrayList<Location>();
		for (String key : config.getConfigurationSection(path).getKeys(false)){
			locations.add(loadLocation(path+"."+key));
		}
		return locations;
	}
	/**
	 * Loads a location out of the Config
	 * @param path Path in the Configfile
	 * @return Location
	 */
	public Location loadLocation(String path){
		double x = config.getDouble(path + ".x");
		double y = config.getDouble(path + ".y");
		double z = config.getDouble(path + ".z");
		float yaw	= (float) config.getDouble(path + ".jaw");
		float pitch = (float) config.getDouble(path + ".pitch");
                World world = Bukkit.getServer().getWorld(path+".world");

		Location loc = new Location(world, x, y, z);
		loc.setPitch(pitch);
		loc.setYaw(yaw);
		
		return loc;
	}

damit sollte das gehen:

Code:
List<Locations> locations = loadLocations("spawn.players");
...
teleport(players, locations);

Du solltest aber locations irgentwo speichern, damit man nicht immer auf die Config zugreifen muss..
 
Zuletzt bearbeitet:
Oben