mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-24 11:37:05 +01:00
Implement remaining events
This commit is contained in:
parent
000250e95b
commit
af5e69100a
@ -15,7 +15,6 @@
|
||||
package de.erethon.dungeonsxl.api.event.player;
|
||||
|
||||
import de.erethon.dungeonsxl.api.player.EditPlayer;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
/**
|
||||
@ -23,10 +22,9 @@ import org.bukkit.event.HandlerList;
|
||||
*
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public class EditPlayerEditEvent extends EditPlayerEvent implements Cancellable {
|
||||
public class EditPlayerEditEvent extends EditPlayerEvent {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private boolean cancelled;
|
||||
|
||||
private boolean newlyLoaded;
|
||||
|
||||
@ -53,14 +51,4 @@ public class EditPlayerEditEvent extends EditPlayerEvent implements Cancellable
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,18 +15,16 @@
|
||||
package de.erethon.dungeonsxl.api.event.world;
|
||||
|
||||
import de.erethon.dungeonsxl.api.world.EditWorld;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
/**
|
||||
* Fired when a dungeon world is generated.
|
||||
* Fired after a dungeon world is generated.
|
||||
*
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public class EditWorldGenerateEvent extends EditWorldEvent implements Cancellable {
|
||||
public class EditWorldGenerateEvent extends EditWorldEvent {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private boolean cancelled;
|
||||
|
||||
public EditWorldGenerateEvent(EditWorld editWorld) {
|
||||
super(editWorld);
|
||||
@ -41,14 +39,4 @@ public class EditWorldGenerateEvent extends EditWorldEvent implements Cancellabl
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -14,7 +14,6 @@
|
||||
*/
|
||||
package de.erethon.dungeonsxl.api.event.world;
|
||||
|
||||
import de.erethon.dungeonsxl.api.dungeon.Dungeon;
|
||||
import de.erethon.dungeonsxl.api.world.ResourceWorld;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
@ -29,20 +28,11 @@ public class ResourceWorldInstantiateEvent extends ResourceWorldEvent implements
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private boolean cancelled;
|
||||
|
||||
private Dungeon dungeon;
|
||||
private String instanceWorldName;
|
||||
|
||||
public ResourceWorldInstantiateEvent(ResourceWorld resource, Dungeon dungeon) {
|
||||
public ResourceWorldInstantiateEvent(ResourceWorld resource, String instanceWorldName) {
|
||||
super(resource);
|
||||
this.dungeon = dungeon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the dungeon as a part of which the instance is loaded.
|
||||
*
|
||||
* @return the dungeon as a part of which the instance is loaded
|
||||
*/
|
||||
public Dungeon getDungeon() {
|
||||
return dungeon;
|
||||
this.instanceWorldName = instanceWorldName;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -51,7 +41,18 @@ public class ResourceWorldInstantiateEvent extends ResourceWorldEvent implements
|
||||
* @return if the loaded instance will be an edit world
|
||||
*/
|
||||
public boolean isEditInstance() {
|
||||
return dungeon == null;
|
||||
return instanceWorldName.startsWith("DXL_Edit_");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name the newly loaded Bukkit world is going to have.
|
||||
* <p>
|
||||
* Note that at this point no Bukkit World object for this world exists.
|
||||
*
|
||||
* @return the name the newly loaded Bukkit world is going to have
|
||||
*/
|
||||
public String getInstanceWorldName() {
|
||||
return instanceWorldName;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -47,6 +47,23 @@ public interface EditPlayer extends InstancePlayer {
|
||||
*/
|
||||
void setCopiedLines(String[] copiedLines);
|
||||
|
||||
/**
|
||||
* Makes the player leave his group and dungeon.
|
||||
* <p>
|
||||
* This unloads the world if there are no editors left after this player leaves.
|
||||
*/
|
||||
@Override
|
||||
default void leave() {
|
||||
leave(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the player leave his group and dungeon.
|
||||
*
|
||||
* @param unloadIfEmpty whether the world is to be unloaded if, after this player leaves, no editors are left
|
||||
*/
|
||||
void leave(boolean unloadIfEmpty);
|
||||
|
||||
/**
|
||||
* Makes the player leave the edit world without saving the progress.
|
||||
*/
|
||||
|
@ -19,6 +19,7 @@ package de.erethon.dungeonsxl.command;
|
||||
import de.erethon.commons.chat.MessageUtil;
|
||||
import de.erethon.commons.config.CommonMessage;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.api.event.player.EditPlayerEditEvent;
|
||||
import de.erethon.dungeonsxl.api.player.GlobalPlayer;
|
||||
import de.erethon.dungeonsxl.api.player.InstancePlayer;
|
||||
import de.erethon.dungeonsxl.api.player.PlayerGroup;
|
||||
@ -27,6 +28,7 @@ import de.erethon.dungeonsxl.api.world.ResourceWorld;
|
||||
import de.erethon.dungeonsxl.config.DMessage;
|
||||
import de.erethon.dungeonsxl.player.DEditPlayer;
|
||||
import de.erethon.dungeonsxl.player.DPermission;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -59,6 +61,7 @@ public class EditCommand extends DCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean newlyLoaded = resource.getEditWorld() == null;
|
||||
EditWorld editWorld = resource.getOrInstantiateEditWorld(false);
|
||||
if (editWorld == null) {
|
||||
MessageUtil.sendMessage(player, DMessage.ERROR_TOO_MANY_INSTANCES.getMessage());
|
||||
@ -78,7 +81,7 @@ public class EditCommand extends DCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
new DEditPlayer(plugin, player, editWorld);
|
||||
Bukkit.getPluginManager().callEvent(new EditPlayerEditEvent(new DEditPlayer(plugin, player, editWorld), newlyLoaded));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,11 +18,13 @@ package de.erethon.dungeonsxl.command;
|
||||
|
||||
import de.erethon.commons.chat.MessageUtil;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.api.event.player.EditPlayerLeaveEvent;
|
||||
import de.erethon.dungeonsxl.api.player.EditPlayer;
|
||||
import de.erethon.dungeonsxl.api.player.PlayerGroup;
|
||||
import de.erethon.dungeonsxl.api.world.EditWorld;
|
||||
import de.erethon.dungeonsxl.config.DMessage;
|
||||
import de.erethon.dungeonsxl.player.DPermission;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -50,6 +52,12 @@ public class EscapeCommand extends DCommand {
|
||||
MessageUtil.sendMessage(player, DMessage.ERROR_LEAVE_DUNGEON.getMessage());
|
||||
|
||||
} else if (editPlayer != null) {
|
||||
EditPlayerLeaveEvent event = new EditPlayerLeaveEvent(editPlayer, true, true);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
editPlayer.escape();
|
||||
|
||||
EditWorld editWorld = editPlayer.getEditWorld();
|
||||
@ -57,7 +65,7 @@ public class EscapeCommand extends DCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
if (editWorld.getWorld().getPlayers().isEmpty()) {
|
||||
if (editWorld.getWorld().getPlayers().isEmpty() && event.getUnloadIfEmpty()) {
|
||||
editWorld.delete(false);
|
||||
}
|
||||
|
||||
|
@ -20,11 +20,12 @@ import de.erethon.commons.chat.MessageUtil;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.api.dungeon.Game;
|
||||
import de.erethon.dungeonsxl.api.event.group.GroupPlayerLeaveEvent;
|
||||
import de.erethon.dungeonsxl.api.event.player.EditPlayerLeaveEvent;
|
||||
import de.erethon.dungeonsxl.api.player.EditPlayer;
|
||||
import de.erethon.dungeonsxl.api.player.GamePlayer;
|
||||
import de.erethon.dungeonsxl.api.player.GlobalPlayer;
|
||||
import de.erethon.dungeonsxl.api.player.PlayerGroup;
|
||||
import de.erethon.dungeonsxl.config.DMessage;
|
||||
import de.erethon.dungeonsxl.player.DEditPlayer;
|
||||
import de.erethon.dungeonsxl.player.DGlobalPlayer;
|
||||
import de.erethon.dungeonsxl.player.DInstancePlayer;
|
||||
import de.erethon.dungeonsxl.player.DPermission;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -48,7 +49,7 @@ public class LeaveCommand extends DCommand {
|
||||
@Override
|
||||
public void onExecute(String[] args, CommandSender sender) {
|
||||
Player player = (Player) sender;
|
||||
DGlobalPlayer dPlayer = (DGlobalPlayer) dPlayers.get(player);
|
||||
GlobalPlayer globalPlayer = dPlayers.get(player);
|
||||
Game game = plugin.getGame(player);
|
||||
|
||||
if (game != null && game.isTutorial()) {
|
||||
@ -56,23 +57,29 @@ public class LeaveCommand extends DCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerGroup dGroup = dPlayer.getGroup();
|
||||
PlayerGroup group = globalPlayer.getGroup();
|
||||
|
||||
if (dGroup == null && !(dPlayer instanceof DEditPlayer)) {
|
||||
if (group == null && !(globalPlayer instanceof EditPlayer)) {
|
||||
MessageUtil.sendMessage(player, DMessage.ERROR_JOIN_GROUP.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
GroupPlayerLeaveEvent groupPlayerLeaveEvent = new GroupPlayerLeaveEvent(dGroup, dPlayer);
|
||||
Bukkit.getPluginManager().callEvent(groupPlayerLeaveEvent);
|
||||
if (groupPlayerLeaveEvent.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (dPlayer instanceof DInstancePlayer) {
|
||||
((DInstancePlayer) dPlayer).leave();
|
||||
if (globalPlayer instanceof GamePlayer) {
|
||||
GroupPlayerLeaveEvent event = new GroupPlayerLeaveEvent(group, globalPlayer);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
((GamePlayer) globalPlayer).leave();
|
||||
} else if (globalPlayer instanceof EditPlayer) {
|
||||
EditPlayerLeaveEvent event = new EditPlayerLeaveEvent((EditPlayer) globalPlayer, false, true);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
((EditPlayer) globalPlayer).leave(event.getUnloadIfEmpty());
|
||||
} else {
|
||||
dGroup.removeMember(player);
|
||||
group.removeMember(player);
|
||||
}
|
||||
|
||||
MessageUtil.sendMessage(player, DMessage.CMD_LEAVE_SUCCESS.getMessage());
|
||||
|
@ -138,12 +138,12 @@ public class DEditPlayer extends DInstancePlayer implements EditPlayer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void leave() {
|
||||
public void leave(boolean unloadIfEmpty) {
|
||||
delete();
|
||||
|
||||
reset(false);
|
||||
|
||||
if (!plugin.isLoadingWorld() && editWorld != null && editWorld.getPlayers().isEmpty()) {
|
||||
if (unloadIfEmpty && !plugin.isLoadingWorld() && editWorld != null && editWorld.getPlayers().isEmpty()) {
|
||||
editWorld.delete();
|
||||
new ProgressBar(player, config.getEditInstanceRemovalDelay()) {
|
||||
@Override
|
||||
|
@ -26,6 +26,7 @@ import de.erethon.dungeonsxl.api.dungeon.GameGoal;
|
||||
import de.erethon.dungeonsxl.api.dungeon.GameRule;
|
||||
import de.erethon.dungeonsxl.api.dungeon.GameRuleContainer;
|
||||
import de.erethon.dungeonsxl.api.event.group.GroupPlayerKickEvent;
|
||||
import de.erethon.dungeonsxl.api.event.group.GroupScoreEvent;
|
||||
import de.erethon.dungeonsxl.api.event.player.GamePlayerDeathEvent;
|
||||
import de.erethon.dungeonsxl.api.event.player.GamePlayerFinishEvent;
|
||||
import de.erethon.dungeonsxl.api.event.player.GlobalPlayerRewardPayOutEvent;
|
||||
@ -332,6 +333,11 @@ public class DGamePlayer extends DInstancePlayer implements GamePlayer {
|
||||
return;
|
||||
}
|
||||
|
||||
GroupScoreEvent event = new GroupScoreEvent(getGroup(), this, stealing);
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
game.sendMessage(DMessage.GROUP_FLAG_CAPTURED.getMessage(getName(), stealing.getName()));
|
||||
|
||||
GameRuleContainer rules = game.getRules();
|
||||
|
@ -387,6 +387,10 @@ public class DGameWorld extends DInstanceWorld implements GameWorld {
|
||||
|
||||
@Override
|
||||
public Dungeon getDungeon() {
|
||||
if (getGame() != null) {
|
||||
return getGame().getDungeon();
|
||||
}
|
||||
|
||||
for (Dungeon dungeon : plugin.getDungeonRegistry()) {
|
||||
if (dungeon.containsFloor(getResource())) {
|
||||
return dungeon;
|
||||
|
@ -24,6 +24,7 @@ import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.api.dungeon.Dungeon;
|
||||
import de.erethon.dungeonsxl.api.dungeon.GameRuleContainer;
|
||||
import de.erethon.dungeonsxl.api.event.world.EditWorldGenerateEvent;
|
||||
import de.erethon.dungeonsxl.api.event.world.ResourceWorldInstantiateEvent;
|
||||
import de.erethon.dungeonsxl.api.player.EditPlayer;
|
||||
import de.erethon.dungeonsxl.api.world.EditWorld;
|
||||
import de.erethon.dungeonsxl.api.world.GameWorld;
|
||||
@ -199,6 +200,10 @@ public class DResourceWorld implements ResourceWorld {
|
||||
}
|
||||
|
||||
DInstanceWorld instance = game ? new DGameWorld(plugin, this, instanceFolder) : new DEditWorld(plugin, this, instanceFolder);
|
||||
ResourceWorldInstantiateEvent event = new ResourceWorldInstantiateEvent(this, name);
|
||||
if (event.isCancelled()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
FileUtil.copyDir(folder, instanceFolder, DungeonsXL.EXCLUDED_FILES);
|
||||
instance.world = Bukkit.createWorld(WorldCreator.name(name).environment(getWorldEnvironment())).getName();
|
||||
@ -284,7 +289,7 @@ public class DResourceWorld implements ResourceWorld {
|
||||
DEditWorld editWorld = new DEditWorld(plugin, this, folder);
|
||||
this.editWorld = editWorld;
|
||||
|
||||
EditWorldGenerateEvent event = new EditWorldGenerateEvent(editWorld);
|
||||
ResourceWorldInstantiateEvent event = new ResourceWorldInstantiateEvent(this, name);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
return null;
|
||||
@ -298,6 +303,7 @@ public class DResourceWorld implements ResourceWorld {
|
||||
editWorld.world = creator.createWorld().getName();
|
||||
editWorld.generateIdFile();
|
||||
|
||||
Bukkit.getPluginManager().callEvent(new EditWorldGenerateEvent(editWorld));
|
||||
return editWorld;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user