From 1cf83aaca623f4050ce7e557ba5421c04ad7227a Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Sat, 25 Apr 2020 00:33:42 +0200 Subject: [PATCH] Add new EditPlayer events --- .../api/event/player/EditPlayerEditEvent.java | 66 ++++++++++++++ .../api/event/player/EditPlayerEvent.java | 39 +++++++++ .../event/player/EditPlayerLeaveEvent.java | 86 +++++++++++++++++++ .../instance/edit/DEditPlayerEscapeEvent.java | 54 ------------ .../instance/edit/DEditPlayerEvent.java | 40 --------- 5 files changed, 191 insertions(+), 94 deletions(-) create mode 100644 api/src/main/java/de/erethon/dungeonsxl/api/event/player/EditPlayerEditEvent.java create mode 100644 api/src/main/java/de/erethon/dungeonsxl/api/event/player/EditPlayerEvent.java create mode 100644 api/src/main/java/de/erethon/dungeonsxl/api/event/player/EditPlayerLeaveEvent.java delete mode 100644 core/src/main/java/de/erethon/dungeonsxl/event/dplayer/instance/edit/DEditPlayerEscapeEvent.java delete mode 100644 core/src/main/java/de/erethon/dungeonsxl/event/dplayer/instance/edit/DEditPlayerEvent.java diff --git a/api/src/main/java/de/erethon/dungeonsxl/api/event/player/EditPlayerEditEvent.java b/api/src/main/java/de/erethon/dungeonsxl/api/event/player/EditPlayerEditEvent.java new file mode 100644 index 00000000..5382151c --- /dev/null +++ b/api/src/main/java/de/erethon/dungeonsxl/api/event/player/EditPlayerEditEvent.java @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2014-2020 Daniel Saukel + * + * This library is free software: you can redistribute it and/or modify it under the + * terms of the GNU Lesser 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 GNULesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with + * this program. If not, see . + */ +package de.erethon.dungeonsxl.api.event.player; + +import de.erethon.dungeonsxl.api.player.EditPlayer; +import org.bukkit.event.Cancellable; +import org.bukkit.event.HandlerList; + +/** + * Fired when a player starts editing a dungeon map. + * + * @author Daniel Saukel + */ +public class EditPlayerEditEvent extends EditPlayerEvent implements Cancellable { + + private static final HandlerList handlers = new HandlerList(); + private boolean cancelled; + + private boolean newlyLoaded; + + public EditPlayerEditEvent(EditPlayer editPlayer, boolean newlyLoaded) { + super(editPlayer); + this.newlyLoaded = newlyLoaded; + } + + /** + * Returns true if the edit world was not instantiated before the player edited it and false if it was. + * + * @return true if the edit world was not instantiated before the player edited it and false if it was + */ + public boolean isNewlyLoaded() { + return newlyLoaded; + } + + @Override + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean cancelled) { + this.cancelled = cancelled; + } + +} diff --git a/api/src/main/java/de/erethon/dungeonsxl/api/event/player/EditPlayerEvent.java b/api/src/main/java/de/erethon/dungeonsxl/api/event/player/EditPlayerEvent.java new file mode 100644 index 00000000..e6f9c12e --- /dev/null +++ b/api/src/main/java/de/erethon/dungeonsxl/api/event/player/EditPlayerEvent.java @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2014-2020 Daniel Saukel + * + * This library is free software: you can redistribute it and/or modify it under the + * terms of the GNU Lesser 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 GNULesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with + * this program. If not, see . + */ +package de.erethon.dungeonsxl.api.event.player; + +import de.erethon.dungeonsxl.api.player.EditPlayer; + +/** + * Superclass for events involving {@link EditPlayer}s. + * + * @author Daniel Saukel + */ +public abstract class EditPlayerEvent extends GlobalPlayerEvent { + + protected EditPlayerEvent(EditPlayer editPlayer) { + super(editPlayer); + } + + /** + * Returns the EditPlayer involved in this event + * + * @return the EditPlayer involved in this event + */ + public EditPlayer getEditPlayer() { + return (EditPlayer) globalPlayer; + } + +} diff --git a/api/src/main/java/de/erethon/dungeonsxl/api/event/player/EditPlayerLeaveEvent.java b/api/src/main/java/de/erethon/dungeonsxl/api/event/player/EditPlayerLeaveEvent.java new file mode 100644 index 00000000..9c2b0a8d --- /dev/null +++ b/api/src/main/java/de/erethon/dungeonsxl/api/event/player/EditPlayerLeaveEvent.java @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2014-2020 Daniel Saukel + * + * This library is free software: you can redistribute it and/or modify it under the + * terms of the GNU Lesser 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 GNULesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with + * this program. If not, see . + */ +package de.erethon.dungeonsxl.api.event.player; + +import de.erethon.dungeonsxl.api.player.EditPlayer; +import org.bukkit.event.Cancellable; +import org.bukkit.event.HandlerList; + +/** + * Fired when a player stops editing a dungeon map. + * + * @author Daniel Saukel + */ +public class EditPlayerLeaveEvent extends EditPlayerEvent implements Cancellable { + + private static final HandlerList handlers = new HandlerList(); + private boolean cancelled; + + private boolean escape; + private boolean unloadIfEmpty; + + public EditPlayerLeaveEvent(EditPlayer editPlayer, boolean escape, boolean unloadIfEmpty) { + super(editPlayer); + this.escape = escape; + this.unloadIfEmpty = unloadIfEmpty; + } + + /** + * Returns false if the edit world is saved, true if not. + * + * @return false if the edit world is saved, true if not + */ + public boolean isEscape() { + return escape; + } + + /** + * Returns if the instance shall be unloaded when it is empty after the player left. + * + * @return if the instance shall be unloaded when it is empty after the player left + */ + public boolean getUnloadIfEmpty() { + return unloadIfEmpty; + } + + /** + * Sets if the instance shall be unloaded when it is empty after the player left. + * + * @param unloadIfEmpty if the instance shall be unloaded when it is empty after the player left + */ + public void setUnloadIfEmpty(boolean unloadIfEmpty) { + this.unloadIfEmpty = unloadIfEmpty; + } + + @Override + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean cancelled) { + this.cancelled = cancelled; + } + +} diff --git a/core/src/main/java/de/erethon/dungeonsxl/event/dplayer/instance/edit/DEditPlayerEscapeEvent.java b/core/src/main/java/de/erethon/dungeonsxl/event/dplayer/instance/edit/DEditPlayerEscapeEvent.java deleted file mode 100644 index 12b992e2..00000000 --- a/core/src/main/java/de/erethon/dungeonsxl/event/dplayer/instance/edit/DEditPlayerEscapeEvent.java +++ /dev/null @@ -1,54 +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 . - */ -package de.erethon.dungeonsxl.event.dplayer.instance.edit; - -import de.erethon.dungeonsxl.player.DEditPlayer; -import org.bukkit.event.Cancellable; -import org.bukkit.event.HandlerList; - -/** - * @author Daniel Saukel - */ -public class DEditPlayerEscapeEvent extends DEditPlayerEvent implements Cancellable { - - private static final HandlerList handlers = new HandlerList(); - private boolean cancelled; - - public DEditPlayerEscapeEvent(DEditPlayer dPlayer) { - super(dPlayer); - } - - @Override - public HandlerList getHandlers() { - return handlers; - } - - public static HandlerList getHandlerList() { - return handlers; - } - - @Override - public boolean isCancelled() { - return cancelled; - } - - @Override - public void setCancelled(boolean cancelled) { - this.cancelled = cancelled; - } - -} diff --git a/core/src/main/java/de/erethon/dungeonsxl/event/dplayer/instance/edit/DEditPlayerEvent.java b/core/src/main/java/de/erethon/dungeonsxl/event/dplayer/instance/edit/DEditPlayerEvent.java deleted file mode 100644 index a2b5794a..00000000 --- a/core/src/main/java/de/erethon/dungeonsxl/event/dplayer/instance/edit/DEditPlayerEvent.java +++ /dev/null @@ -1,40 +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 . - */ -package de.erethon.dungeonsxl.event.dplayer.instance.edit; - -import de.erethon.dungeonsxl.event.dplayer.DPlayerEvent; -import de.erethon.dungeonsxl.player.DEditPlayer; - -/** - * @author Daniel Saukel - */ -public abstract class DEditPlayerEvent extends DPlayerEvent { - - public DEditPlayerEvent(DEditPlayer dPlayer) { - super(dPlayer); - } - - @Override - public DEditPlayer getDPlayer() { - return (DEditPlayer) dPlayer; - } - - public void setDPlayer(DEditPlayer dPlayer) { - this.dPlayer = dPlayer; - } - -}