mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-12-02 23:43:38 +01:00
Implement DPlayer events
This commit is contained in:
parent
80ebdeeda3
commit
6157df9703
@ -1,6 +1,7 @@
|
|||||||
package io.github.dre2n.dungeonsxl.command;
|
package io.github.dre2n.dungeonsxl.command;
|
||||||
|
|
||||||
import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld;
|
import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld;
|
||||||
|
import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerEscapeEvent;
|
||||||
import io.github.dre2n.dungeonsxl.file.DMessages.Messages;
|
import io.github.dre2n.dungeonsxl.file.DMessages.Messages;
|
||||||
import io.github.dre2n.dungeonsxl.player.DGroup;
|
import io.github.dre2n.dungeonsxl.player.DGroup;
|
||||||
import io.github.dre2n.dungeonsxl.player.DPlayer;
|
import io.github.dre2n.dungeonsxl.player.DPlayer;
|
||||||
@ -33,6 +34,12 @@ public class LeaveCommand extends DCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (dPlayer != null) {
|
if (dPlayer != null) {
|
||||||
|
DPlayerEscapeEvent event = new DPlayerEscapeEvent(dPlayer);
|
||||||
|
|
||||||
|
if (event.isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
dPlayer.leave();
|
dPlayer.leave();
|
||||||
MessageUtil.sendMessage(player, dMessages.getMessage(Messages.CMD_LEAVE_SUCCESS));
|
MessageUtil.sendMessage(player, dMessages.getMessage(Messages.CMD_LEAVE_SUCCESS));
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package io.github.dre2n.dungeonsxl.event.dplayer;
|
package io.github.dre2n.dungeonsxl.event.dplayer;
|
||||||
|
|
||||||
|
import io.github.dre2n.dungeonsxl.player.DGroup;
|
||||||
import io.github.dre2n.dungeonsxl.player.DPlayer;
|
import io.github.dre2n.dungeonsxl.player.DPlayer;
|
||||||
|
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
@ -11,10 +12,12 @@ public class DPlayerJoinDGroupEvent extends DPlayerEvent implements Cancellable
|
|||||||
private boolean cancelled;
|
private boolean cancelled;
|
||||||
|
|
||||||
private boolean creator;
|
private boolean creator;
|
||||||
|
private DGroup dGroup;
|
||||||
|
|
||||||
public DPlayerJoinDGroupEvent(DPlayer dPlayer, boolean creator) {
|
public DPlayerJoinDGroupEvent(DPlayer dPlayer, boolean creator, DGroup dGroup) {
|
||||||
super(dPlayer);
|
super(dPlayer);
|
||||||
this.creator = creator;
|
this.creator = creator;
|
||||||
|
this.dGroup = dGroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -24,6 +27,13 @@ public class DPlayerJoinDGroupEvent extends DPlayerEvent implements Cancellable
|
|||||||
return creator;
|
return creator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the dGroup
|
||||||
|
*/
|
||||||
|
public DGroup getDGroup() {
|
||||||
|
return dGroup;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
|
@ -15,14 +15,16 @@ public class DPlayerUpdateEvent extends DPlayerEvent implements Cancellable {
|
|||||||
private boolean respawnInventory;
|
private boolean respawnInventory;
|
||||||
private boolean offline;
|
private boolean offline;
|
||||||
private boolean kick;
|
private boolean kick;
|
||||||
|
private boolean triggerAllInDistance;
|
||||||
|
|
||||||
public DPlayerUpdateEvent(DPlayer dPlayer, boolean locationValid, boolean teleportWolf, boolean respawnInventory, boolean offline, boolean kick) {
|
public DPlayerUpdateEvent(DPlayer dPlayer, boolean locationValid, boolean teleportWolf, boolean respawnInventory, boolean offline, boolean kick, boolean triggerAllInDistance) {
|
||||||
super(dPlayer);
|
super(dPlayer);
|
||||||
this.locationValid = locationValid;
|
this.locationValid = locationValid;
|
||||||
this.teleportWolf = teleportWolf;
|
this.teleportWolf = teleportWolf;
|
||||||
this.respawnInventory = respawnInventory;
|
this.respawnInventory = respawnInventory;
|
||||||
this.offline = offline;
|
this.offline = offline;
|
||||||
this.kick = kick;
|
this.kick = kick;
|
||||||
|
this.triggerAllInDistance = triggerAllInDistance;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -92,6 +94,21 @@ public class DPlayerUpdateEvent extends DPlayerEvent implements Cancellable {
|
|||||||
this.kick = kick;
|
this.kick = kick;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the triggerAllInDistance
|
||||||
|
*/
|
||||||
|
public boolean getTriggerAllInDistance() {
|
||||||
|
return triggerAllInDistance;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param triggerAllInDistance
|
||||||
|
* the triggerAllInDistance to set
|
||||||
|
*/
|
||||||
|
public void setTriggerAllInDistance(boolean triggerAllInDistance) {
|
||||||
|
this.triggerAllInDistance = triggerAllInDistance;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
|
@ -7,6 +7,7 @@ import io.github.dre2n.dungeonsxl.dungeon.EditWorld;
|
|||||||
import io.github.dre2n.dungeonsxl.dungeon.game.GameChest;
|
import io.github.dre2n.dungeonsxl.dungeon.game.GameChest;
|
||||||
import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld;
|
import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld;
|
||||||
import io.github.dre2n.dungeonsxl.event.dgroup.DGroupCreateEvent;
|
import io.github.dre2n.dungeonsxl.event.dgroup.DGroupCreateEvent;
|
||||||
|
import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerDeathEvent;
|
||||||
import io.github.dre2n.dungeonsxl.file.DMessages;
|
import io.github.dre2n.dungeonsxl.file.DMessages;
|
||||||
import io.github.dre2n.dungeonsxl.file.DMessages.Messages;
|
import io.github.dre2n.dungeonsxl.file.DMessages.Messages;
|
||||||
import io.github.dre2n.dungeonsxl.global.DPortal;
|
import io.github.dre2n.dungeonsxl.global.DPortal;
|
||||||
@ -67,7 +68,13 @@ public class PlayerListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
dPlayer.setLives(dPlayer.getLives() - 1);
|
DPlayerDeathEvent dPlayerDeathEvent = new DPlayerDeathEvent(dPlayer, event, 1);
|
||||||
|
|
||||||
|
if (dPlayerDeathEvent.isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
dPlayer.setLives(dPlayer.getLives() - dPlayerDeathEvent.getLostLives());
|
||||||
|
|
||||||
if (dPlayer.getLives() == 0 && dPlayer.isReady()) {
|
if (dPlayer.getLives() == 0 && dPlayer.isReady()) {
|
||||||
MessageUtil.broadcastMessage(dMessages.getMessage(Messages.PLAYER_DEATH_KICK, player.getName()));
|
MessageUtil.broadcastMessage(dMessages.getMessage(Messages.PLAYER_DEATH_KICK, player.getName()));
|
||||||
|
@ -8,6 +8,9 @@ import io.github.dre2n.dungeonsxl.dungeon.EditWorld;
|
|||||||
import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld;
|
import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld;
|
||||||
import io.github.dre2n.dungeonsxl.event.dgroup.DGroupFinishDungeonEvent;
|
import io.github.dre2n.dungeonsxl.event.dgroup.DGroupFinishDungeonEvent;
|
||||||
import io.github.dre2n.dungeonsxl.event.dgroup.DGroupFinishFloorEvent;
|
import io.github.dre2n.dungeonsxl.event.dgroup.DGroupFinishFloorEvent;
|
||||||
|
import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerFinishEvent;
|
||||||
|
import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerKickEvent;
|
||||||
|
import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerUpdateEvent;
|
||||||
import io.github.dre2n.dungeonsxl.file.DMessages;
|
import io.github.dre2n.dungeonsxl.file.DMessages;
|
||||||
import io.github.dre2n.dungeonsxl.file.DMessages.Messages;
|
import io.github.dre2n.dungeonsxl.file.DMessages.Messages;
|
||||||
import io.github.dre2n.dungeonsxl.reward.Reward;
|
import io.github.dre2n.dungeonsxl.reward.Reward;
|
||||||
@ -64,7 +67,7 @@ public class DPlayer {
|
|||||||
private ItemStack[] respawnArmor;
|
private ItemStack[] respawnArmor;
|
||||||
private String[] linesCopy;
|
private String[] linesCopy;
|
||||||
|
|
||||||
private Inventory treasureInv = DungeonsXL.getPlugin().getServer().createInventory(getPlayer(), 45, dMessages.getMessage(Messages.PLAYER_TREASURES));
|
private Inventory treasureInv = plugin.getServer().createInventory(getPlayer(), 45, dMessages.getMessage(Messages.PLAYER_TREASURES));
|
||||||
|
|
||||||
private int initialLives = -1;
|
private int initialLives = -1;
|
||||||
private int lives;
|
private int lives;
|
||||||
@ -343,17 +346,30 @@ public class DPlayer {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean first = true;
|
||||||
|
boolean hasToWait = false;
|
||||||
|
|
||||||
for (Player player : dGroup.getPlayers()) {
|
for (Player player : dGroup.getPlayers()) {
|
||||||
DPlayer dPlayer = getByPlayer(player);
|
DPlayer dPlayer = getByPlayer(player);
|
||||||
if ( !dPlayer.finished) {
|
if ( !dPlayer.finished) {
|
||||||
MessageUtil.sendMessage(this.getPlayer(), dMessages.getMessage(Messages.PLAYER_WAIT_FOR_OTHER_PLAYERS));
|
MessageUtil.sendMessage(this.getPlayer(), dMessages.getMessage(Messages.PLAYER_WAIT_FOR_OTHER_PLAYERS));
|
||||||
return;
|
hasToWait = true;
|
||||||
|
|
||||||
|
} else if (dPlayer != this) {
|
||||||
|
first = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DGroupFinishDungeonEvent event = new DGroupFinishDungeonEvent(dGroup);
|
DPlayerFinishEvent dPlayerFinishEvent = new DPlayerFinishEvent(this, first, hasToWait);
|
||||||
|
|
||||||
if (event.isCancelled()) {
|
if (dPlayerFinishEvent.isCancelled()) {
|
||||||
|
finished = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
DGroupFinishDungeonEvent dGroupFinishDungeonEvent = new DGroupFinishDungeonEvent(dGroup);
|
||||||
|
|
||||||
|
if (dGroupFinishDungeonEvent.isCancelled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -813,46 +829,53 @@ public class DPlayer {
|
|||||||
|
|
||||||
public static void update(boolean updateSecond) {
|
public static void update(boolean updateSecond) {
|
||||||
for (DPlayer dPlayer : plugin.getDPlayers()) {
|
for (DPlayer dPlayer : plugin.getDPlayers()) {
|
||||||
|
boolean locationValid = true;
|
||||||
|
Location teleportLocation = dPlayer.getPlayer().getLocation();
|
||||||
|
boolean teleportWolf = false;
|
||||||
|
boolean respawnInventory = false;
|
||||||
|
boolean offline = false;
|
||||||
|
boolean kick = false;
|
||||||
|
boolean triggerAllInDistance = false;
|
||||||
|
|
||||||
|
GameWorld gameWorld = GameWorld.getByWorld(dPlayer.world);
|
||||||
|
EditWorld editWorld = EditWorld.getByWorld(dPlayer.world);
|
||||||
|
|
||||||
if ( !updateSecond) {
|
if ( !updateSecond) {
|
||||||
if ( !dPlayer.getPlayer().getWorld().equals(dPlayer.world)) {
|
if ( !dPlayer.getPlayer().getWorld().equals(dPlayer.world)) {
|
||||||
|
locationValid = false;
|
||||||
|
|
||||||
if (dPlayer.editing) {
|
if (dPlayer.editing) {
|
||||||
EditWorld editWorld = EditWorld.getByWorld(dPlayer.world);
|
|
||||||
if (editWorld != null) {
|
if (editWorld != null) {
|
||||||
if (editWorld.getLobby() == null) {
|
if (editWorld.getLobby() == null) {
|
||||||
MiscUtil.secureTeleport(dPlayer.getPlayer(), editWorld.getWorld().getSpawnLocation());
|
teleportLocation = editWorld.getWorld().getSpawnLocation();
|
||||||
} else {
|
} else {
|
||||||
MiscUtil.secureTeleport(dPlayer.getPlayer(), editWorld.getLobby());
|
teleportLocation = editWorld.getLobby();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
GameWorld gameWorld = GameWorld.getByWorld(dPlayer.world);
|
|
||||||
if (gameWorld != null) {
|
if (gameWorld != null) {
|
||||||
DGroup dGroup = DGroup.getByPlayer(dPlayer.getPlayer());
|
DGroup dGroup = DGroup.getByPlayer(dPlayer.getPlayer());
|
||||||
if (dPlayer.checkpoint == null) {
|
if (dPlayer.checkpoint == null) {
|
||||||
MiscUtil.secureTeleport(dPlayer.getPlayer(), dGroup.getGameWorld().getLocStart());
|
teleportLocation = dGroup.getGameWorld().getLocStart();
|
||||||
if (dPlayer.wolf != null) {
|
if (dPlayer.wolf != null) {
|
||||||
dPlayer.wolf.teleport(dGroup.getGameWorld().getLocStart());
|
dPlayer.wolf.teleport(dGroup.getGameWorld().getLocStart());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
MiscUtil.secureTeleport(dPlayer.getPlayer(), dPlayer.checkpoint);
|
teleportLocation = dPlayer.getCheckpoint();
|
||||||
if (dPlayer.wolf != null) {
|
if (dPlayer.wolf != null) {
|
||||||
dPlayer.wolf.teleport(dPlayer.checkpoint);
|
teleportWolf = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Respawn Items
|
// Respawn Items
|
||||||
if (dPlayer.respawnInventory != null || dPlayer.respawnArmor != null) {
|
if (dPlayer.respawnInventory != null || dPlayer.respawnArmor != null) {
|
||||||
dPlayer.getPlayer().getInventory().setContents(dPlayer.respawnInventory);
|
respawnInventory = true;
|
||||||
dPlayer.getPlayer().getInventory().setArmorContents(dPlayer.respawnArmor);
|
|
||||||
dPlayer.respawnInventory = null;
|
|
||||||
dPlayer.respawnArmor = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
GameWorld gameWorld = GameWorld.getByWorld(dPlayer.world);
|
|
||||||
|
|
||||||
|
} else {
|
||||||
if (gameWorld != null) {
|
if (gameWorld != null) {
|
||||||
// Update Wolf
|
// Update Wolf
|
||||||
if (dPlayer.wolf != null) {
|
if (dPlayer.wolf != null) {
|
||||||
@ -869,15 +892,49 @@ public class DPlayer {
|
|||||||
|
|
||||||
// Kick offline plugin.getDPlayers()
|
// Kick offline plugin.getDPlayers()
|
||||||
if (dPlayer.offlineTime > 0) {
|
if (dPlayer.offlineTime > 0) {
|
||||||
|
offline = true;
|
||||||
|
|
||||||
if (dPlayer.offlineTime < System.currentTimeMillis()) {
|
if (dPlayer.offlineTime < System.currentTimeMillis()) {
|
||||||
dPlayer.leave();
|
kick = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check Distance Trigger Signs
|
triggerAllInDistance = true;
|
||||||
DistanceTrigger.triggerAllInDistance(dPlayer.getPlayer(), gameWorld);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DPlayerUpdateEvent event = new DPlayerUpdateEvent(dPlayer, locationValid, teleportWolf, respawnInventory, offline, kick, triggerAllInDistance);
|
||||||
|
|
||||||
|
if (event.isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !locationValid) {
|
||||||
|
MiscUtil.secureTeleport(dPlayer.getPlayer(), teleportLocation);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (teleportWolf) {
|
||||||
|
dPlayer.wolf.teleport(dPlayer.checkpoint);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (respawnInventory) {
|
||||||
|
dPlayer.getPlayer().getInventory().setContents(dPlayer.respawnInventory);
|
||||||
|
dPlayer.getPlayer().getInventory().setArmorContents(dPlayer.respawnArmor);
|
||||||
|
dPlayer.respawnInventory = null;
|
||||||
|
dPlayer.respawnArmor = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (kick) {
|
||||||
|
DPlayerKickEvent dPlayerKickEvent = new DPlayerKickEvent(dPlayer);
|
||||||
|
|
||||||
|
if ( !dPlayerKickEvent.isCancelled()) {
|
||||||
|
dPlayer.leave();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (triggerAllInDistance) {
|
||||||
|
DistanceTrigger.triggerAllInDistance(dPlayer.getPlayer(), gameWorld);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package io.github.dre2n.dungeonsxl.sign;
|
package io.github.dre2n.dungeonsxl.sign;
|
||||||
|
|
||||||
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
|
||||||
import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld;
|
import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld;
|
||||||
|
import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerEscapeEvent;
|
||||||
import io.github.dre2n.dungeonsxl.player.DPlayer;
|
import io.github.dre2n.dungeonsxl.player.DPlayer;
|
||||||
import io.github.dre2n.dungeonsxl.trigger.InteractTrigger;
|
import io.github.dre2n.dungeonsxl.trigger.InteractTrigger;
|
||||||
|
|
||||||
@ -46,6 +46,12 @@ public class LeaveSign extends DSign {
|
|||||||
public boolean onPlayerTrigger(Player player) {
|
public boolean onPlayerTrigger(Player player) {
|
||||||
DPlayer dPlayer = DPlayer.getByPlayer(player);
|
DPlayer dPlayer = DPlayer.getByPlayer(player);
|
||||||
if (dPlayer != null) {
|
if (dPlayer != null) {
|
||||||
|
DPlayerEscapeEvent event = new DPlayerEscapeEvent(dPlayer);
|
||||||
|
|
||||||
|
if (event.isCancelled()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
dPlayer.leave();
|
dPlayer.leave();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,7 +60,13 @@ public class LeaveSign extends DSign {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTrigger() {
|
public void onTrigger() {
|
||||||
for (DPlayer dPlayer : DungeonsXL.getPlugin().getDPlayers()) {
|
for (DPlayer dPlayer : plugin.getDPlayers()) {
|
||||||
|
DPlayerEscapeEvent event = new DPlayerEscapeEvent(dPlayer);
|
||||||
|
|
||||||
|
if (event.isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
dPlayer.leave();
|
dPlayer.leave();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user