Add new GameWorldStartGameEvent

This commit is contained in:
Daniel Saukel 2020-04-25 15:12:42 +02:00
parent fc86c5e999
commit 8f1dea9975
2 changed files with 29 additions and 57 deletions

View File

@ -14,10 +14,11 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package de.erethon.dungeonsxl.event.gameworld; package de.erethon.dungeonsxl.api.event.world;
import de.erethon.dungeonsxl.dungeon.DGame; import de.erethon.dungeonsxl.api.dungeon.Game;
import de.erethon.dungeonsxl.world.DGameWorld; import de.erethon.dungeonsxl.api.world.GameWorld;
import org.bukkit.Location;
import org.bukkit.event.Cancellable; import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
@ -29,25 +30,43 @@ public class GameWorldStartGameEvent extends GameWorldEvent implements Cancellab
private static final HandlerList handlers = new HandlerList(); private static final HandlerList handlers = new HandlerList();
private boolean cancelled; private boolean cancelled;
private DGame game; private Game game;
private Location startLocation;
public GameWorldStartGameEvent(DGameWorld gameWorld, DGame game) { public GameWorldStartGameEvent(GameWorld gameWorld, Game game, Location location) {
super(gameWorld); super(gameWorld, gameWorld.getDungeon());
this.game = game; this.game = game;
} }
/** /**
* Returns the game.
*
* @return the game * @return the game
*/ */
public DGame getGame() { public Game getGame() {
return game; return game;
} }
/** /**
* @param game the game to set * Returns the location where the players are teleported.
*
* @return the location where the players are teleported
*/ */
public void setGame(DGame game) { public Location getStartLocation() {
this.game = game; return startLocation;
}
/**
* Sets the location where the players are teleported.
*
* @param startLocation a location in the game world
* @throws IllegalArgumentException if the given location is not in the game world.
*/
public void setStartLocation(Location startLocation) {
if (startLocation.getWorld() != getGameWorld().getWorld()) {
throw new IllegalArgumentException("Location " + startLocation + " is not in world " + getGameWorld().getWorld());
}
this.startLocation = startLocation;
} }
@Override @Override

View File

@ -1,47 +0,0 @@
/*
* Copyright (C) 2012-2020 Frank Baumann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.erethon.dungeonsxl.event.gameworld;
import de.erethon.dungeonsxl.world.DGameWorld;
import org.bukkit.event.Event;
/**
* @author Daniel Saukel
*/
public abstract class GameWorldEvent extends Event {
protected DGameWorld gameWorld;
public GameWorldEvent(DGameWorld gameWorld) {
this.gameWorld = gameWorld;
}
/**
* @return the gameWorld
*/
public DGameWorld getGameWorld() {
return gameWorld;
}
/**
* @param gameWorld the gameWorld to set
*/
public void setGameWorld(DGameWorld gameWorld) {
this.gameWorld = gameWorld;
}
}