/*
 * Copyright (c) 2016 MCPhoton <http://mcphoton.org> and contributors.
 *
 * This file is part of the Photon Server Implementation <https://github.com/mcphoton/Photon-Server>.
 *
 * The Photon Server Implementation is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * The Photon Server Implementation is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
package org.mcphoton.impl.world;

import com.electronwill.utils.SimpleBag;
import java.io.File;
import java.util.Collection;
import org.mcphoton.Photon;
import org.mcphoton.entity.living.Player;
import org.mcphoton.world.Location;
import org.mcphoton.world.World;
import org.mcphoton.world.WorldType;
import org.mcphoton.world.protection.WorldAccessManager;

/**
 *
 * @author TheElectronWill
 */
public class PhotonWorld implements World {

	protected volatile String name;
	protected volatile File directory = new File(Photon.WORLDS_DIR, name);
	protected volatile double spawnX = 0, spawnY = 0, spawnZ = 0;
	protected final WorldType type;
	protected final Collection<Player> players = new SimpleBag<>();

	public PhotonWorld(String name, WorldType type) {
		this.name = name;
		this.type = type;
	}

	@Override
	public String getName() {
		return name;
	}

	@Override
	public synchronized void renameTo(String name) {
		boolean renameSuccess = directory.renameTo(new File(Photon.WORLDS_DIR, name));
		if (renameSuccess) {
			this.name = name;
		}
	}

	@Override
	public File getDirectory() {
		return directory;
	}

	@Override
	public WorldType getType() {
		return type;
	}

	@Override
	public Location getSpawn() {
		return new Location(spawnX, spawnY, spawnZ, this);
	}

	@Override
	public synchronized void setSpawn(int x, int y, int z) {
		this.spawnX = x;
		this.spawnY = y;
		this.spawnZ = z;
	}

	@Override
	public synchronized void setSpawn(Location spawn) {
		this.spawnX = spawn.getX();
		this.spawnY = spawn.getY();
		this.spawnZ = spawn.getZ();
	}

	@Override
	public Collection<Player> getPlayers() {
		return players;
	}

	@Override
	public void save() {
		; //TODO
	}

	@Override
	public void delete() {
		directory.delete();
	}

	@Override
	public WorldAccessManager getAccessManager() {
		return null;//TODO
	}

	@Override
	public void setAccessManager(WorldAccessManager manager) {
		; //TODO
	}

}

@@ -1061,26 +1061,341 @@
 ton.
-entity.living.Play
+command.WorldCommandRegistry;%0Aimport org.mcphoton.entity.living.Player;%0Aimport org.mcphoton.event.WorldEventsManager;%0Aimport org.mcphoton.impl.command.WorldCommandRegistryImpl;%0Aimport org.mcphoton.impl.event.WorldEventsManagerImpl;%0Aimport org.mcphoton.impl.plugin.WorldPluginsManagerImpl;%0Aimport org.mcphoton.plugin.WorldPluginsManag
 er;%0A
@@ -1562,16 +1562,50 @@
 r;%0A%0A/**%0A
+ * Basic implementation of World.%0A
  *%0A * @a
@@ -1843,16 +1843,17 @@
 nZ = 0;%0A
+%0A
 %09protect
@@ -1943,16 +1943,276 @@
 g%3C%3E();%0A%0A
+%09protected final WorldPluginsManager pluginsManager = new WorldPluginsManagerImpl(this);%0A%09protected final WorldEventsManager eventsManager = new WorldEventsManagerImpl();%0A%09protected final WorldCommandRegistry commandRegistry = new WorldCommandRegistryImpl();%0A%0A
 %09public 
@@ -3395,24 +3395,24 @@
  manager) %7B%0A
-
 %09%09; //TODO%0A%09
@@ -3414,10 +3414,280 @@
 ODO%0A%09%7D%0A%0A
+%09@Override%0A%09public WorldCommandRegistry getCommandRegistry() %7B%0A%09%09return commandRegistry;%0A%09%7D%0A%0A%09@Override%0A%09public WorldEventsManager getEventsManager() %7B%0A%09%09return eventsManager;%0A%09%7D%0A%0A%09@Override%0A%09public WorldPluginsManager getPluginsManager() %7B%0A%09%09return pluginsManager;%0A%09%7D%0A%0A
 %7D%0A

Update world implementation