Skip to content

Commit

Permalink
Finished player handling rewrite. Resolves #63
Browse files Browse the repository at this point in the history
  • Loading branch information
Sataniel98 committed May 10, 2016
1 parent e8dfdd9 commit 722a97a
Show file tree
Hide file tree
Showing 11 changed files with 468 additions and 332 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.github.dre2n</groupId>
<artifactId>dungeonsxl</artifactId>
<version>0.11.1</version>
<version>0.12-SNAPSHOT</version>
<packaging>jar</packaging>
<name>DungeonsXL</name>
<url>https://dre2n.github.io</url>
Expand Down Expand Up @@ -55,7 +55,7 @@
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.9.2-R0.1-SNAPSHOT</version>
<version>1.9.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.github.dre2n.commons.util.messageutil.MessageUtil;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.config.DMessages;
import io.github.dre2n.dungeonsxl.player.DEditPlayer;
import io.github.dre2n.dungeonsxl.player.DGamePlayer;
import io.github.dre2n.dungeonsxl.player.DPermissions;
import io.github.dre2n.dungeonsxl.world.EditWorld;
Expand Down Expand Up @@ -95,7 +96,7 @@ public void onExecute(String[] args, CommandSender sender) {
MessageUtil.log(plugin, DMessages.LOG_WORLD_GENERATION_FINISHED.getMessage());

// Tp Player
new DGamePlayer(player, editWorld.getWorld(), true);
new DEditPlayer(player, editWorld.getWorld());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.github.dre2n.commons.util.messageutil.MessageUtil;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.config.DMessages;
import io.github.dre2n.dungeonsxl.player.DEditPlayer;
import io.github.dre2n.dungeonsxl.player.DGamePlayer;
import io.github.dre2n.dungeonsxl.player.DGroup;
import io.github.dre2n.dungeonsxl.player.DPermissions;
Expand Down Expand Up @@ -71,7 +72,7 @@ public void onExecute(String[] args, CommandSender sender) {
return;
}

new DGamePlayer(player, editWorld.getWorld(), true);
new DEditPlayer(player, editWorld.getWorld());

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

import io.github.dre2n.commons.command.BRCommand;
import io.github.dre2n.commons.util.messageutil.MessageUtil;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.config.DMessages;
import io.github.dre2n.dungeonsxl.player.DEditPlayer;
import io.github.dre2n.dungeonsxl.player.DGamePlayer;
import io.github.dre2n.dungeonsxl.player.DGroup;
import io.github.dre2n.dungeonsxl.player.DPermissions;
Expand All @@ -32,8 +32,6 @@
*/
public class EscapeCommand extends BRCommand {

DungeonsXL plugin = DungeonsXL.getInstance();

public EscapeCommand() {
setCommand("escape");
setMinArgs(0);
Expand All @@ -46,14 +44,12 @@ public EscapeCommand() {
@Override
public void onExecute(String[] args, CommandSender sender) {
Player player = (Player) sender;
DGamePlayer dPlayer = DGamePlayer.getByPlayer(player);
if (dPlayer != null) {
DEditPlayer dPlayer = DEditPlayer.getByPlayer(player);

if (!dPlayer.isEditing()) {
MessageUtil.sendMessage(player, DMessages.ERROR_LEAVE_DUNGEON.getMessage());
return;
}
if (DGamePlayer.getByPlayer(player) != null) {
MessageUtil.sendMessage(player, DMessages.ERROR_LEAVE_DUNGEON.getMessage());

} else if (dPlayer != null) {
dPlayer.escape();

EditWorld editWorld = EditWorld.getByWorld(dPlayer.getWorld());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
package io.github.dre2n.dungeonsxl.event.dplayer;

import io.github.dre2n.dungeonsxl.player.DGamePlayer;
import io.github.dre2n.dungeonsxl.player.DInstancePlayer;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;

Expand All @@ -35,7 +35,7 @@ public class DPlayerUpdateEvent extends DPlayerEvent implements Cancellable {
private boolean kick;
private boolean triggerAllInDistance;

public DPlayerUpdateEvent(DGamePlayer dPlayer, boolean locationValid, boolean teleportWolf, boolean respawnInventory, boolean offline, boolean kick, boolean triggerAllInDistance) {
public DPlayerUpdateEvent(DInstancePlayer dPlayer, boolean locationValid, boolean teleportWolf, boolean respawnInventory, boolean offline, boolean kick, boolean triggerAllInDistance) {
super(dPlayer);
this.locationValid = locationValid;
this.teleportWolf = teleportWolf;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@
import io.github.dre2n.dungeonsxl.global.GlobalProtection;
import io.github.dre2n.dungeonsxl.global.GroupSign;
import io.github.dre2n.dungeonsxl.global.LeaveSign;
import io.github.dre2n.dungeonsxl.player.DEditPlayer;
import io.github.dre2n.dungeonsxl.player.DGamePlayer;
import io.github.dre2n.dungeonsxl.player.DGlobalPlayer;
import io.github.dre2n.dungeonsxl.player.DGroup;
import io.github.dre2n.dungeonsxl.player.DInstancePlayer;
import io.github.dre2n.dungeonsxl.player.DPermissions;
import io.github.dre2n.dungeonsxl.player.DPlayers;
import io.github.dre2n.dungeonsxl.player.DSavePlayer;
Expand Down Expand Up @@ -216,7 +218,7 @@ public void onInteract(PlayerInteractEvent event) {
if (EditWorld.getByWorld(player.getWorld()) != null) {
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
if (item.getType() == Material.STICK) {
DGamePlayer dPlayer = DGamePlayer.getByPlayer(player);
DEditPlayer dPlayer = DEditPlayer.getByPlayer(player);
if (dPlayer != null) {
dPlayer.poke(clickedBlock);
event.setCancelled(true);
Expand Down Expand Up @@ -315,15 +317,21 @@ public void onInteract(PlayerInteractEvent event) {
public void onDropItem(PlayerDropItemEvent event) {
Player player = event.getPlayer();

DGamePlayer dPlayer = DGamePlayer.getByPlayer(player);
DGlobalPlayer dPlayer = dPlayers.getByPlayer(player);
if (dPlayer == null) {
return;
}

if (dPlayer.isEditing() && !plugin.getMainConfig().getDropItems() && !DPermissions.hasPermission(player, DPermissions.INSECURE)) {
if (dPlayer instanceof DEditPlayer && !plugin.getMainConfig().getDropItems() && !DPermissions.hasPermission(player, DPermissions.INSECURE)) {
event.setCancelled(true);
}

if (!(dPlayer instanceof DGamePlayer)) {
return;
}

DGamePlayer gamePlayer = (DGamePlayer) dPlayer;

DGroup dGroup = DGroup.getByPlayer(player);
if (dGroup == null) {
return;
Expand All @@ -334,12 +342,12 @@ public void onDropItem(PlayerDropItemEvent event) {
return;
}

if (!dPlayer.isReady()) {
if (!gamePlayer.isReady()) {
event.setCancelled(true);
return;
}

GameWorld gameWorld = GameWorld.getByWorld(dPlayer.getWorld());
GameWorld gameWorld = GameWorld.getByWorld(gamePlayer.getWorld());

for (Material material : gameWorld.getConfig().getSecureObjects()) {
if (material == event.getItemDrop().getItemStack().getType()) {
Expand All @@ -355,13 +363,13 @@ public void onRespawn(PlayerRespawnEvent event) {
Player player = event.getPlayer();
plugin.getDPlayers().getByPlayer(player).applyRespawnInventory();

DGamePlayer dPlayer = DGamePlayer.getByPlayer(player);
DGlobalPlayer dPlayer = DGamePlayer.getByPlayer(player);
if (dPlayer == null) {
return;
}

if (dPlayer.isEditing()) {
EditWorld editWorld = EditWorld.getByWorld(dPlayer.getWorld());
if (dPlayer instanceof DEditPlayer) {
EditWorld editWorld = EditWorld.getByWorld(((DEditPlayer) dPlayer).getWorld());
if (editWorld == null) {
return;
}
Expand All @@ -373,16 +381,18 @@ public void onRespawn(PlayerRespawnEvent event) {
event.setRespawnLocation(editWorld.getLobbyLocation());
}

} else {
GameWorld gameWorld = GameWorld.getByWorld(dPlayer.getWorld());
} else if (dPlayer instanceof DGamePlayer) {
DGamePlayer gamePlayer = (DGamePlayer) dPlayer;

GameWorld gameWorld = GameWorld.getByWorld(gamePlayer.getWorld());

if (gameWorld == null) {
return;
}

DGroup dGroup = DGroup.getByPlayer(dPlayer.getPlayer());

Location respawn = dPlayer.getCheckpoint();
Location respawn = gamePlayer.getCheckpoint();

if (respawn == null) {
respawn = dGroup.getGameWorld().getStartLocation();
Expand All @@ -400,8 +410,8 @@ public void onRespawn(PlayerRespawnEvent event) {
new RespawnTask(player, respawn).runTaskLater(plugin, 10);

// Don't forget Doge!
if (dPlayer.getWolf() != null) {
dPlayer.getWolf().teleport(respawn);
if (gamePlayer.getWolf() != null) {
gamePlayer.getWolf().teleport(respawn);
}
}
}
Expand Down Expand Up @@ -448,7 +458,10 @@ public void onChat(AsyncPlayerChatEvent event) {
@EventHandler(priority = EventPriority.HIGH)
public void onQuit(PlayerQuitEvent event) {
Player player = event.getPlayer();
DGamePlayer dPlayer = DGamePlayer.getByPlayer(player);
if (!(dPlayers.getByPlayer(player) instanceof DInstancePlayer)) {
return;
}
DInstancePlayer dPlayer = (DInstancePlayer) dPlayers.getByPlayer(player);

if (dPlayer == null) {
dPlayers.removePlayer(dPlayer);
Expand All @@ -467,13 +480,13 @@ public void onQuit(PlayerQuitEvent event) {

} else if (timeUntilKickOfflinePlayer > 0) {
dGroup.sendMessage(DMessages.PLAYER_OFFLINE.getMessage(dPlayer.getPlayer().getName(), String.valueOf(timeUntilKickOfflinePlayer)), player);
dPlayer.setOfflineTime(System.currentTimeMillis() + timeUntilKickOfflinePlayer * 1000);
((DGamePlayer) dPlayer).setOfflineTime(System.currentTimeMillis() + timeUntilKickOfflinePlayer * 1000);

} else {
dGroup.sendMessage(DMessages.PLAYER_OFFLINE_NEVER.getMessage(dPlayer.getPlayer().getName()), player);
}

} else if (dPlayer.isEditing()) {
} else if (dPlayer instanceof DEditPlayer) {
dPlayer.leave();
}
}
Expand Down Expand Up @@ -566,17 +579,17 @@ public void onCommand(PlayerCommandPreprocessEvent event) {
return;
}

DGamePlayer dPlayer = DGamePlayer.getByPlayer(event.getPlayer());
if (dPlayer == null) {
if (!(dPlayers.getByPlayer(event.getPlayer()) instanceof DInstancePlayer)) {
return;
}
DInstancePlayer dPlayer = (DInstancePlayer) dPlayers.getByPlayer(event.getPlayer());

String command = event.getMessage().toLowerCase();
ArrayList<String> commandWhitelist = new ArrayList<>();

GameWorld gameWorld = GameWorld.getByWorld(dPlayer.getWorld());

if (dPlayer.isEditing()) {
if (dPlayer instanceof DEditPlayer) {
if (DPermissions.hasPermission(event.getPlayer(), DPermissions.CMD_EDIT)) {
return;

Expand Down
Loading

0 comments on commit 722a97a

Please sign in to comment.