Continue overhaul

This commit includes the PlayerListener and a bugfix in onJoin at
servers without Vault.
This commit is contained in:
Daniel Saukel 2015-12-25 15:48:11 +01:00
parent 56f98e6826
commit a018664102
7 changed files with 299 additions and 254 deletions

View File

@ -1,6 +1,3 @@
/* TODO: Cleanup - Overhaul DPlayer, GameWorld, GameChest & Listeners - MiscUtil - FileUtil -
* Variable names - Triggers */
package io.github.dre2n.dungeonsxl; package io.github.dre2n.dungeonsxl;
import io.github.dre2n.dungeonsxl.command.DCommands; import io.github.dre2n.dungeonsxl.command.DCommands;

View File

@ -92,15 +92,15 @@ public class PlayCommand extends DCommand {
DGroup dGroup = new DGroup(player, identifier, multiFloor); DGroup dGroup = new DGroup(player, identifier, multiFloor);
if (dGroup.getGWorld() == null) { if (dGroup.getGameWorld() == null) {
dGroup.setGWorld(GameWorld.load(DGroup.get(player).getMapName())); dGroup.setGameWorld(GameWorld.load(DGroup.get(player).getMapName()));
} }
if (dGroup.getGWorld().getLocLobby() == null) { if (dGroup.getGameWorld().getLocLobby() == null) {
new DPlayer(player, dGroup.getGWorld().getWorld(), dGroup.getGWorld().getWorld().getSpawnLocation(), false); new DPlayer(player, dGroup.getGameWorld().getWorld(), dGroup.getGameWorld().getWorld().getSpawnLocation(), false);
} else { } else {
new DPlayer(player, dGroup.getGWorld().getWorld(), dGroup.getGWorld().getLocLobby(), false); new DPlayer(player, dGroup.getGameWorld().getWorld(), dGroup.getGameWorld().getLocLobby(), false);
} }
} }

View File

@ -67,17 +67,17 @@ public class TestCommand extends DCommand {
DGroup dGroup = new DGroup(player, identifier, multiFloor); DGroup dGroup = new DGroup(player, identifier, multiFloor);
if (dGroup.getGWorld() == null) { if (dGroup.getGameWorld() == null) {
dGroup.setGWorld(GameWorld.load(DGroup.get(player).getMapName())); dGroup.setGameWorld(GameWorld.load(DGroup.get(player).getMapName()));
} }
DPlayer newDPlayer; DPlayer newDPlayer;
if (dGroup.getGWorld().getLocLobby() == null) { if (dGroup.getGameWorld().getLocLobby() == null) {
newDPlayer = new DPlayer(player, dGroup.getGWorld().getWorld(), dGroup.getGWorld().getWorld().getSpawnLocation(), false); newDPlayer = new DPlayer(player, dGroup.getGameWorld().getWorld(), dGroup.getGameWorld().getWorld().getSpawnLocation(), false);
} else { } else {
newDPlayer = new DPlayer(player, dGroup.getGWorld().getWorld(), dGroup.getGWorld().getLocLobby(), false); newDPlayer = new DPlayer(player, dGroup.getGameWorld().getWorld(), dGroup.getGameWorld().getLocLobby(), false);
} }
newDPlayer.setIsInTestMode(true); newDPlayer.setIsInTestMode(true);

View File

@ -89,19 +89,19 @@ public class DPortal {
MessageUtil.sendMessage(player, plugin.getDMessages().get("Error_NotInGroup")); MessageUtil.sendMessage(player, plugin.getDMessages().get("Error_NotInGroup"));
} }
if (dgroup.getGWorld() == null) { if (dgroup.getGameWorld() == null) {
dgroup.setGWorld(GameWorld.load(DGroup.get(player).getMapName())); dgroup.setGameWorld(GameWorld.load(DGroup.get(player).getMapName()));
} }
if (dgroup.getGWorld() == null) { if (dgroup.getGameWorld() == null) {
MessageUtil.sendMessage(player, plugin.getDMessages().get("Error_DungeonNotExist", DGroup.get(player).getMapName())); MessageUtil.sendMessage(player, plugin.getDMessages().get("Error_DungeonNotExist", DGroup.get(player).getMapName()));
} }
if (dgroup.getGWorld().getLocLobby() == null) { if (dgroup.getGameWorld().getLocLobby() == null) {
new DPlayer(player, dgroup.getGWorld().getWorld(), dgroup.getGWorld().getWorld().getSpawnLocation(), false); new DPlayer(player, dgroup.getGameWorld().getWorld(), dgroup.getGameWorld().getWorld().getSpawnLocation(), false);
} else { } else {
new DPlayer(player, dgroup.getGWorld().getWorld(), dgroup.getGWorld().getLocLobby(), false); new DPlayer(player, dgroup.getGameWorld().getWorld(), dgroup.getGameWorld().getLocLobby(), false);
} }
} }

View File

@ -54,40 +54,44 @@ public class PlayerListener implements Listener {
final DPlayer dPlayer = DPlayer.get(player); final DPlayer dPlayer = DPlayer.get(player);
GameWorld gameWorld = GameWorld.get(player.getLocation().getWorld()); GameWorld gameWorld = GameWorld.get(player.getLocation().getWorld());
if (gameWorld != null) { if (gameWorld == null) {
WorldConfig dConfig = gameWorld.getConfig(); return;
}
WorldConfig dConfig = gameWorld.getConfig();
if (dPlayer == null) {
return;
}
dPlayer.setLives(dPlayer.getLives() - 1);
if (dPlayer.getLives() == 0 && dPlayer.isReady()) {
Bukkit.broadcastMessage(plugin.getDMessages().get("Player_DeathKick").replaceAll("v1", player.getName()).replaceAll("&", "\u00a7"));
// TODO: This Runnable is a workaround for a bug I couldn't find, yet...
new BukkitRunnable() {
public void run() {
dPlayer.leave();
}
}.runTaskLater(plugin, 1L);
if (dPlayer != null) { } else if ( !(dPlayer.getLives() == -1)) {
dPlayer.setLives(dPlayer.getLives() - 1); MessageUtil.sendMessage(player, plugin.getDMessages().get("Player_Death").replaceAll("v1", String.valueOf(dPlayer.getLives())));
if (dPlayer.getLives() == 0 && dPlayer.isReady()) { } else if (dConfig != null) {
Bukkit.broadcastMessage(plugin.getDMessages().get("Player_DeathKick").replaceAll("v1", player.getName()).replaceAll("&", "\u00a7")); if (dConfig.getKeepInventoryOnDeath()) {
// TODO: This Runnable is a workaround for a bug I couldn't find, yet... dPlayer.setRespawnInventory(event.getEntity().getInventory().getContents());
new BukkitRunnable() { dPlayer.setRespawnArmor(event.getEntity().getInventory().getArmorContents());
public void run() { // Delete all drops
dPlayer.leave(); for (ItemStack istack : event.getDrops()) {
} istack.setType(Material.AIR);
}.runTaskLater(plugin, 1L);
} else if ( !(dPlayer.getLives() == -1)) {
MessageUtil.sendMessage(player, plugin.getDMessages().get("Player_Death").replaceAll("v1", String.valueOf(dPlayer.getLives())));
} else if (dConfig != null) {
if (dConfig.getKeepInventoryOnDeath()) {
dPlayer.setRespawnInventory(event.getEntity().getInventory().getContents());
dPlayer.setRespawnArmor(event.getEntity().getInventory().getArmorContents());
// Delete all drops
for (ItemStack istack : event.getDrops()) {
istack.setType(Material.AIR);
}
}
} }
} }
} }
} }
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerInteract(PlayerInteractEvent event) { public void onInteract(PlayerInteractEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
Block clickedBlock = event.getClickedBlock(); Block clickedBlock = event.getClickedBlock();
@ -96,13 +100,13 @@ public class PlayerListener implements Listener {
if (GameWorld.get(player.getWorld()) != null || EditWorld.get(player.getWorld()) != null) { if (GameWorld.get(player.getWorld()) != null || EditWorld.get(player.getWorld()) != null) {
if (event.getAction() != Action.LEFT_CLICK_BLOCK) { if (event.getAction() != Action.LEFT_CLICK_BLOCK) {
if (clickedBlock.getType() == Material.ENDER_CHEST) { if (clickedBlock.getType() == Material.ENDER_CHEST) {
if ( !player.isOp()) {// TODO: Permission if ( !player.hasPermission("dxl.bypass")) {
MessageUtil.sendMessage(player, plugin.getDMessages().get("Error_Enderchest")); MessageUtil.sendMessage(player, plugin.getDMessages().get("Error_Enderchest"));
event.setCancelled(true); event.setCancelled(true);
} }
} else if (clickedBlock.getType() == Material.BED_BLOCK) { } else if (clickedBlock.getType() == Material.BED_BLOCK) {
if ( !player.isOp()) {// TODO: Permission if ( !player.hasPermission("dxl.bypass")) {
MessageUtil.sendMessage(player, plugin.getDMessages().get("Error_Bed")); MessageUtil.sendMessage(player, plugin.getDMessages().get("Error_Bed"));
event.setCancelled(true); event.setCancelled(true);
} }
@ -114,7 +118,7 @@ public class PlayerListener implements Listener {
if (GameWorld.get(player.getWorld()) != null) { if (GameWorld.get(player.getWorld()) != null) {
if (event.getAction() != Action.LEFT_CLICK_BLOCK) { if (event.getAction() != Action.LEFT_CLICK_BLOCK) {
if (clickedBlock.getType() == Material.DISPENSER) { if (clickedBlock.getType() == Material.DISPENSER) {
if ( !player.isOp()) { if ( !player.hasPermission("dxl.bypass")) {
MessageUtil.sendMessage(player, plugin.getDMessages().get("Error_Dispenser")); MessageUtil.sendMessage(player, plugin.getDMessages().get("Error_Dispenser"));
event.setCancelled(true); event.setCancelled(true);
} }
@ -152,9 +156,9 @@ public class PlayerListener implements Listener {
if (EditWorld.get(player.getWorld()) != null) { if (EditWorld.get(player.getWorld()) != null) {
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
if (item.getType() == Material.STICK) { if (item.getType() == Material.STICK) {
DPlayer dplayer = DPlayer.get(player); DPlayer dPlayer = DPlayer.get(player);
if (dplayer != null) { if (dPlayer != null) {
dplayer.poke(clickedBlock); dPlayer.poke(clickedBlock);
event.setCancelled(true); event.setCancelled(true);
} }
} }
@ -162,10 +166,10 @@ public class PlayerListener implements Listener {
} }
// Trigger UseItem Signs // Trigger UseItem Signs
GameWorld gworld = GameWorld.get(player.getWorld()); GameWorld gameWorld = GameWorld.get(player.getWorld());
if (gworld != null) { if (gameWorld != null) {
if (event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_AIR) { if (event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_AIR) {
if (UseItemTrigger.hasTriggers(gworld)) { if (UseItemTrigger.hasTriggers(gameWorld)) {
String name = null; String name = null;
if (item.hasItemMeta()) { if (item.hasItemMeta()) {
if (item.getItemMeta().hasDisplayName()) { if (item.getItemMeta().hasDisplayName()) {
@ -183,7 +187,7 @@ public class PlayerListener implements Listener {
if (name == null) { if (name == null) {
name = item.getType().toString(); name = item.getType().toString();
} }
UseItemTrigger trigger = UseItemTrigger.get(name, gworld); UseItemTrigger trigger = UseItemTrigger.get(name, gameWorld);
if (trigger != null) { if (trigger != null) {
trigger.onTrigger(player); trigger.onTrigger(player);
} }
@ -206,15 +210,15 @@ public class PlayerListener implements Listener {
event.setCancelled(true); event.setCancelled(true);
} }
DPlayer dplayer = DPlayer.get(player); DPlayer dPlayer = DPlayer.get(player);
if (dplayer != null) { if (dPlayer != null) {
// Check GameWorld Signs // Check GameWorld Signs
GameWorld gworld = GameWorld.get(player.getWorld()); GameWorld gameWorld = GameWorld.get(player.getWorld());
if (gworld != null) { if (gameWorld != null) {
// Trigger InteractTrigger // Trigger InteractTrigger
InteractTrigger trigger = InteractTrigger.get(clickedBlock, gworld); InteractTrigger trigger = InteractTrigger.get(clickedBlock, gameWorld);
if (trigger != null) { if (trigger != null) {
if (event.getAction() == Action.LEFT_CLICK_BLOCK) { if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
trigger.onTrigger(player); trigger.onTrigger(player);
@ -224,11 +228,11 @@ public class PlayerListener implements Listener {
} }
// Class Signs // Class Signs
for (Sign classSign : gworld.getSignClass()) { for (Sign classSign : gameWorld.getSignClass()) {
if (classSign != null) { if (classSign != null) {
if (classSign.getLocation().distance(clickedBlock.getLocation()) < 1) { if (classSign.getLocation().distance(clickedBlock.getLocation()) < 1) {
if (event.getAction() == Action.LEFT_CLICK_BLOCK) { if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
dplayer.setDClass(ChatColor.stripColor(classSign.getLine(1))); dPlayer.setDClass(ChatColor.stripColor(classSign.getLine(1)));
} else { } else {
MessageUtil.sendMessage(player, plugin.getDMessages().get("Error_Leftklick")); MessageUtil.sendMessage(player, plugin.getDMessages().get("Error_Leftklick"));
} }
@ -244,89 +248,99 @@ public class PlayerListener implements Listener {
} }
@EventHandler(priority = EventPriority.HIGH) @EventHandler(priority = EventPriority.HIGH)
public void onPlayerDropItem(PlayerDropItemEvent event) { public void onDropItem(PlayerDropItemEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
// Deny dropping things at the lobby // Deny dropping things at the lobby
DGroup dgroup = DGroup.get(player); DGroup dGroup = DGroup.get(player);
if (dgroup != null) { if (dGroup == null) {
if ( !dgroup.isPlaying()) { return;
event.setCancelled(true); }
return;
} if ( !dGroup.isPlaying()) {
if ( !DPlayer.get(player).isReady()) { event.setCancelled(true);
event.setCancelled(true); return;
return; }
}
if ( !DPlayer.get(player).isReady()) {
DPlayer dplayer = DPlayer.get(player); event.setCancelled(true);
GameWorld gworld = GameWorld.get(dplayer.getWorld()); return;
if (dplayer != null) { }
for (Material material : gworld.getConfig().getSecureObjects()) {
if (material == event.getItemDrop().getItemStack().getType()) { DPlayer dPlayer = DPlayer.get(player);
event.setCancelled(true); GameWorld gameWorld = GameWorld.get(dPlayer.getWorld());
MessageUtil.sendMessage(player, plugin.getDMessages().get("Error_Drop"));
return; if (dPlayer != null) {
} for (Material material : gameWorld.getConfig().getSecureObjects()) {
if (material == event.getItemDrop().getItemStack().getType()) {
event.setCancelled(true);
MessageUtil.sendMessage(player, plugin.getDMessages().get("Error_Drop"));
return;
} }
} }
} }
} }
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerRespawn(PlayerRespawnEvent event) { public void onRespawn(PlayerRespawnEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
DPlayer dplayer = DPlayer.get(player); DPlayer dPlayer = DPlayer.get(player);
if (dplayer != null) { if (dPlayer == null) {
if (dplayer.isEditing()) { return;
EditWorld eworld = EditWorld.get(dplayer.getWorld()); }
if (eworld != null) {
if (eworld.getLobby() == null) { if (dPlayer.isEditing()) {
event.setRespawnLocation(eworld.getWorld().getSpawnLocation()); EditWorld editWorld = EditWorld.get(dPlayer.getWorld());
if (editWorld == null) {
} else { return;
event.setRespawnLocation(eworld.getLobby()); }
}
if (editWorld.getLobby() == null) {
event.setRespawnLocation(editWorld.getWorld().getSpawnLocation());
} else {
event.setRespawnLocation(editWorld.getLobby());
}
} else {
GameWorld gameWorld = GameWorld.get(dPlayer.getWorld());
if (gameWorld == null) {
return;
}
DGroup dGroup = DGroup.get(dPlayer.getPlayer());
if (dPlayer.getCheckpoint() == null) {
event.setRespawnLocation(dGroup.getGameWorld().getLocStart());
// Da einige Plugins einen anderen Respawn setzen wird
// ein Scheduler gestartet der den Player nach einer
// Sekunde teleportiert.
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new RespawnRunnable(player, dGroup.getGameWorld().getLocStart()), 10);
if (dPlayer.getWolf() != null) {
dPlayer.getWolf().teleport(dGroup.getGameWorld().getLocStart());
} }
} else { } else {
GameWorld gworld = GameWorld.get(dplayer.getWorld()); event.setRespawnLocation(dPlayer.getCheckpoint());
if (gworld != null) { // Da einige Plugins einen anderen Respawn setzen wird
DGroup dgroup = DGroup.get(dplayer.getPlayer()); // ein Scheduler gestartet der den Player nach einer
// Sekunde teleportiert.
if (dplayer.getCheckpoint() == null) { plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new RespawnRunnable(player, dPlayer.getCheckpoint()), 10);
event.setRespawnLocation(dgroup.getGWorld().getLocStart());
if (dPlayer.getWolf() != null) {
// Da einige Plugins einen anderen Respawn setzen wird dPlayer.getWolf().teleport(dPlayer.getCheckpoint());
// ein Scheduler gestartet der den Player nach einer
// Sekunde teleportiert.
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new RespawnRunnable(player, dgroup.getGWorld().getLocStart()), 10);
if (dplayer.getWolf() != null) {
dplayer.getWolf().teleport(dgroup.getGWorld().getLocStart());
}
} else {
event.setRespawnLocation(dplayer.getCheckpoint());
// Da einige Plugins einen anderen Respawn setzen wird
// ein Scheduler gestartet der den Player nach einer
// Sekunde teleportiert.
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new RespawnRunnable(player, dplayer.getCheckpoint()), 10);
if (dplayer.getWolf() != null) {
dplayer.getWolf().teleport(dplayer.getCheckpoint());
}
}
} }
} }
} }
} }
@EventHandler(priority = EventPriority.HIGH) @EventHandler(priority = EventPriority.HIGH)
public void onPlayerPortalEvent(PlayerPortalEvent event) { public void onPortal(PlayerPortalEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
Location location = event.getFrom(); Location location = event.getFrom();
DPortal dportal = DPortal.get(location); DPortal dportal = DPortal.get(location);
@ -338,125 +352,145 @@ public class PlayerListener implements Listener {
} }
@EventHandler(priority = EventPriority.HIGH) @EventHandler(priority = EventPriority.HIGH)
public void onPlayerTeleport(PlayerTeleportEvent event) { public void onTeleport(PlayerTeleportEvent event) {
Player player = event.getPlayer();
DPlayer dplayer = DPlayer.get(player);
if (dplayer != null) {
if (dplayer.getWorld() != event.getTo().getWorld()) {
if ( !player.isOp()) {
event.setCancelled(true);
}
}
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerChat(AsyncPlayerChatEvent event) {
Player player = event.getPlayer();
DPlayer dplayer = DPlayer.get(player);
if (dplayer != null) {
if (dplayer.isInDungeonChat()) {
dplayer.msg(player.getDisplayName() + ": " + event.getMessage());
event.setCancelled(true);
}
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerQuit(PlayerQuitEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
DPlayer dPlayer = DPlayer.get(player); DPlayer dPlayer = DPlayer.get(player);
if (dPlayer != null) { if (dPlayer == null) {
// Check GameWorld return;
GameWorld gWorld = GameWorld.get(player.getWorld()); }
if (gWorld != null) {
int timeUntilKickOfflinePlayer = gWorld.getConfig().getTimeUntilKickOfflinePlayer(); if (dPlayer.getWorld() == event.getTo().getWorld()) {
return;
if (timeUntilKickOfflinePlayer == 0) { }
dPlayer.leave();
if ( !player.hasPermission("dxl.bypass")) {
} else if (timeUntilKickOfflinePlayer > 0) { event.setCancelled(true);
dPlayer.msg(plugin.getDMessages().get("Player_Offline", dPlayer.getPlayer().getName(), "" + timeUntilKickOfflinePlayer)); }
dPlayer.setOfflineTime(System.currentTimeMillis() + timeUntilKickOfflinePlayer * 1000); }
} else { @EventHandler(priority = EventPriority.HIGH)
dPlayer.msg(plugin.getDMessages().get("Player_OfflineNeverKick", dPlayer.getPlayer().getName())); public void onChat(AsyncPlayerChatEvent event) {
} Player player = event.getPlayer();
DPlayer dPlayer = DPlayer.get(player);
} else if (dPlayer.isEditing()) { if (dPlayer == null) {
return;
}
if (dPlayer.isInDungeonChat()) {
dPlayer.msg(player.getDisplayName() + ": " + event.getMessage());
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onQuit(PlayerQuitEvent event) {
Player player = event.getPlayer();
DPlayer dPlayer = DPlayer.get(player);
if (dPlayer == null) {
return;
}
// Check GameWorld
GameWorld gameWorld = GameWorld.get(player.getWorld());
if (gameWorld != null) {
int timeUntilKickOfflinePlayer = gameWorld.getConfig().getTimeUntilKickOfflinePlayer();
if (timeUntilKickOfflinePlayer == 0) {
dPlayer.leave(); dPlayer.leave();
} else if (timeUntilKickOfflinePlayer > 0) {
dPlayer.msg(plugin.getDMessages().get("Player_Offline", dPlayer.getPlayer().getName(), "" + timeUntilKickOfflinePlayer));
dPlayer.setOfflineTime(System.currentTimeMillis() + timeUntilKickOfflinePlayer * 1000);
} else {
dPlayer.msg(plugin.getDMessages().get("Player_OfflineNeverKick", dPlayer.getPlayer().getName()));
} }
} else if (dPlayer.isEditing()) {
dPlayer.leave();
} }
} }
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL)
public void onPlayerJoin(PlayerJoinEvent event) { public void onJoin(PlayerJoinEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
// Check dplayers // Check dPlayers
DPlayer dplayer = DPlayer.get(player.getName()); DPlayer dPlayer = DPlayer.get(player.getName());
if (dplayer != null) { if (dPlayer != null) {
DGroup dgroup = DGroup.get(dplayer.getPlayer()); DGroup dGroup = DGroup.get(dPlayer.getPlayer());
if (dgroup != null) { if (dGroup != null) {
dgroup.getPlayers().remove(dplayer.getPlayer()); dGroup.getPlayers().remove(dPlayer.getPlayer());
dgroup.getPlayers().add(player); dGroup.getPlayers().add(player);
} }
dplayer.setPlayer(player); dPlayer.setPlayer(player);
// Check offlineTime // Check offlineTime
dplayer.setOfflineTime(0); dPlayer.setOfflineTime(0);
} }
// Tutorial Mode // Tutorial Mode
if (plugin.getMainConfig().isTutorialActivated()) { if ( !plugin.getMainConfig().isTutorialActivated()) {
if (DPlayer.get(player) == null) { return;
if (plugin.getMainConfig().getTutorialDungeon() != null && plugin.getMainConfig().getTutorialStartGroup() != null && plugin.getMainConfig().getTutorialEndGroup() != null) { }
for (String group : plugin.getPermissionProvider().getPlayerGroups(player)) {
if (plugin.getMainConfig().getTutorialStartGroup().equalsIgnoreCase(group)) { if (DPlayer.get(player) != null) {
DGroup dgroup = new DGroup(player, plugin.getMainConfig().getTutorialDungeon(), false); return;
}
if (dgroup.getGWorld() == null) {
dgroup.setGWorld(GameWorld.load(DGroup.get(player).getMapName())); if (plugin.getPermissionProvider() == null) {
dgroup.getGWorld().setTutorial(true); return;
} }
if (dgroup.getGWorld() != null) { if ((plugin.getMainConfig().getTutorialDungeon() == null || plugin.getMainConfig().getTutorialStartGroup() == null || plugin.getMainConfig().getTutorialEndGroup() == null)) {
if (dgroup.getGWorld().getLocLobby() == null) { return;
}
} else {
new DPlayer(player, dgroup.getGWorld().getWorld(), dgroup.getGWorld().getLocLobby(), false); for (String group : plugin.getPermissionProvider().getPlayerGroups(player)) {
} if ( !plugin.getMainConfig().getTutorialStartGroup().equalsIgnoreCase(group)) {
continue;
} else { }
MessageUtil.sendMessage(player, plugin.getDMessages().get("Error_TutorialNotExist"));
} DGroup dGroup = new DGroup(player, plugin.getMainConfig().getTutorialDungeon(), false);
}
} if (dGroup.getGameWorld() == null) {
} dGroup.setGameWorld(GameWorld.load(DGroup.get(player).getMapName()));
dGroup.getGameWorld().setTutorial(true);
}
if (dGroup.getGameWorld() == null) {
MessageUtil.sendMessage(player, plugin.getDMessages().get("Error_TutorialNotExist"));
continue;
}
if (dGroup.getGameWorld().getLocLobby() != null) {
new DPlayer(player, dGroup.getGameWorld().getWorld(), dGroup.getGameWorld().getLocLobby(), false);
} }
} }
} }
// Deny Player Cmds // Deny Player Cmds
@EventHandler(priority = EventPriority.HIGH) @EventHandler(priority = EventPriority.HIGH)
public void onPlayerCommand(PlayerCommandPreprocessEvent event) { public void onCommand(PlayerCommandPreprocessEvent event) {
if (event.getPlayer().hasPermission("dungeonsxl.cmd")) { if (event.getPlayer().hasPermission("dxl.bypass")) {
return; return;
} }
DPlayer dplayer = DPlayer.get(event.getPlayer()); DPlayer dPlayer = DPlayer.get(event.getPlayer());
if (dplayer != null) { if (dPlayer == null) {
if (dplayer.isEditing() && event.getPlayer().hasPermission("dungeonsxl.cmdedit") || event.getPlayer().isOp()) { return;
return; }
}
if (dPlayer.isEditing() && event.getPlayer().hasPermission("dxl.cmdedit")) {
String[] splittedCmd = event.getMessage().split(" "); return;
if ( !splittedCmd[0].equalsIgnoreCase("/dungeon") && !splittedCmd[0].equalsIgnoreCase("/dungeonsxl") && !splittedCmd[0].equalsIgnoreCase("/dxl")) { }
MessageUtil.sendMessage(event.getPlayer(), plugin.getDMessages().get("Error_Cmd"));
event.setCancelled(true); String[] splittedCmd = event.getMessage().split(" ");
} if ( !splittedCmd[0].equalsIgnoreCase("/dungeon") && !splittedCmd[0].equalsIgnoreCase("/dungeonsxl") && !splittedCmd[0].equalsIgnoreCase("/dxl")) {
MessageUtil.sendMessage(event.getPlayer(), plugin.getDMessages().get("Error_Cmd"));
event.setCancelled(true);
} }
} }
@ -469,36 +503,45 @@ public class PlayerListener implements Listener {
@EventHandler @EventHandler
public void onInventoryClose(InventoryCloseEvent event) { public void onInventoryClose(InventoryCloseEvent event) {
Player player = (Player) event.getPlayer(); Player player = (Player) event.getPlayer();
for (DLootInventory inventory : plugin.getDLootInventories()) { for (DLootInventory inventory : plugin.getDLootInventories()) {
if (event.getView() == inventory.getInventoryView()) { if (event.getView() != inventory.getInventoryView()) {
if (System.currentTimeMillis() - inventory.getTime() > 500) { continue;
for (ItemStack istack : inventory.getInventory().getContents()) { }
if (istack != null) {
player.getWorld().dropItem(player.getLocation(), istack); if (System.currentTimeMillis() - inventory.getTime() <= 500) {
} continue;
} }
plugin.getDLootInventories().remove(inventory); for (ItemStack istack : inventory.getInventory().getContents()) {
if (istack != null) {
player.getWorld().dropItem(player.getLocation(), istack);
} }
} }
plugin.getDLootInventories().remove(inventory);
} }
} }
// Player move // Player move
@EventHandler @EventHandler
public void onPlayerMove(PlayerMoveEvent event) { public void onMove(PlayerMoveEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
DLootInventory inventory = DLootInventory.get(player); DLootInventory inventory = DLootInventory.get(player);
if (inventory != null) { if (inventory == null) {
if (player.getLocation().getBlock().getType() != Material.PORTAL) { return;
if (player.getLocation().getBlock().getRelative(0, 1, 0).getType() != Material.PORTAL && player.getLocation().getBlock().getRelative(0, -1, 0).getType() != Material.PORTAL }
&& player.getLocation().getBlock().getRelative(1, 0, 0).getType() != Material.PORTAL && player.getLocation().getBlock().getRelative( -1, 0, 0).getType() != Material.PORTAL
&& player.getLocation().getBlock().getRelative(0, 0, 1).getType() != Material.PORTAL && player.getLocation().getBlock().getRelative(0, 0, -1).getType() != Material.PORTAL) { if (player.getLocation().getBlock().getType() == Material.PORTAL) {
inventory.setInventoryView(inventory.getPlayer().openInventory(inventory.getInventory())); return;
inventory.setTime(System.currentTimeMillis()); }
}
} if (player.getLocation().getBlock().getRelative(0, 1, 0).getType() != Material.PORTAL && player.getLocation().getBlock().getRelative(0, -1, 0).getType() != Material.PORTAL
&& player.getLocation().getBlock().getRelative(1, 0, 0).getType() != Material.PORTAL && player.getLocation().getBlock().getRelative( -1, 0, 0).getType() != Material.PORTAL
&& player.getLocation().getBlock().getRelative(0, 0, 1).getType() != Material.PORTAL && player.getLocation().getBlock().getRelative(0, 0, -1).getType() != Material.PORTAL) {
inventory.setInventoryView(inventory.getPlayer().openInventory(inventory.getInventory()));
inventory.setTime(System.currentTimeMillis());
} }
} }
@ -519,17 +562,20 @@ public class PlayerListener implements Listener {
MiscUtil.secureTeleport(player, location); MiscUtil.secureTeleport(player, location);
} }
DPlayer dplayer = DPlayer.get(player); DPlayer dPlayer = DPlayer.get(player);
if (dplayer != null) { if (dPlayer == null) {
// Respawn Items return;
if (dplayer.getRespawnInventory() != null || dplayer.getRespawnArmor() != null) { }
player.getInventory().setContents(dplayer.getRespawnInventory());
player.getInventory().setArmorContents(dplayer.getRespawnArmor()); // Respawn Items
dplayer.setRespawnInventory(null); if (dPlayer.getRespawnInventory() != null || dPlayer.getRespawnArmor() != null) {
dplayer.setRespawnArmor(null); player.getInventory().setContents(dPlayer.getRespawnInventory());
} player.getInventory().setArmorContents(dPlayer.getRespawnArmor());
dPlayer.setRespawnInventory(null);
dPlayer.setRespawnArmor(null);
} }
} }
} }
} }

View File

@ -33,7 +33,9 @@ public class DGroup {
if (multiFloor) { if (multiFloor) {
this.dungeonName = identifier; this.dungeonName = identifier;
this.mapName = plugin.getDungeons().getDungeon(dungeonName).getConfig().getStartFloor(); this.mapName = plugin.getDungeons().getDungeon(dungeonName).getConfig().getStartFloor();
System.out.println("This one?");
this.unplayedFloors = plugin.getDungeons().getDungeon(dungeonName).getConfig().getFloors(); this.unplayedFloors = plugin.getDungeons().getDungeon(dungeonName).getConfig().getFloors();
System.out.println("If this shows p,");
} else { } else {
this.mapName = identifier; this.mapName = identifier;
@ -87,7 +89,7 @@ public class DGroup {
/** /**
* @return the gameWorld * @return the gameWorld
*/ */
public GameWorld getGWorld() { public GameWorld getGameWorld() {
return gameWorld; return gameWorld;
} }
@ -95,7 +97,7 @@ public class DGroup {
* @param gameWorld * @param gameWorld
* the gameWorld to set * the gameWorld to set
*/ */
public void setGWorld(GameWorld gameWorld) { public void setGameWorld(GameWorld gameWorld) {
this.gameWorld = gameWorld; this.gameWorld = gameWorld;
} }
@ -256,7 +258,7 @@ public class DGroup {
public static DGroup get(GameWorld gameWorld) { public static DGroup get(GameWorld gameWorld) {
for (DGroup dGroup : plugin.getDGroups()) { for (DGroup dGroup : plugin.getDGroups()) {
if (dGroup.getGWorld() == gameWorld) { if (dGroup.getGameWorld() == gameWorld) {
return dGroup; return dGroup;
} }
} }

View File

@ -232,7 +232,7 @@ public class DPlayer {
public void respawn() { public void respawn() {
DGroup dGroup = DGroup.get(getPlayer()); DGroup dGroup = DGroup.get(getPlayer());
if (checkpoint == null) { if (checkpoint == null) {
MiscUtil.secureTeleport(getPlayer(), dGroup.getGWorld().getLocStart()); MiscUtil.secureTeleport(getPlayer(), dGroup.getGameWorld().getLocStart());
} else { } else {
MiscUtil.secureTeleport(getPlayer(), checkpoint); MiscUtil.secureTeleport(getPlayer(), checkpoint);
} }
@ -305,10 +305,10 @@ public class DPlayer {
} }
dGroup.removeUnplayedFloor(dGroup.getMapName()); dGroup.removeUnplayedFloor(dGroup.getMapName());
dGroup.setMapName(newFloor); dGroup.setMapName(newFloor);
dGroup.setGWorld(GameWorld.load(newFloor)); dGroup.setGameWorld(GameWorld.load(newFloor));
for (Player player : dGroup.getPlayers()) { for (Player player : dGroup.getPlayers()) {
DPlayer dPlayer = get(player); DPlayer dPlayer = get(player);
dPlayer.checkpoint = dGroup.getGWorld().getLocStart(); dPlayer.checkpoint = dGroup.getGameWorld().getLocStart();
} }
dGroup.startGame(); dGroup.startGame();
} }
@ -816,9 +816,9 @@ public class DPlayer {
if (gameWorld != null) { if (gameWorld != null) {
DGroup dGroup = DGroup.get(dplayer.getPlayer()); DGroup dGroup = DGroup.get(dplayer.getPlayer());
if (dplayer.checkpoint == null) { if (dplayer.checkpoint == null) {
MiscUtil.secureTeleport(dplayer.getPlayer(), dGroup.getGWorld().getLocStart()); MiscUtil.secureTeleport(dplayer.getPlayer(), dGroup.getGameWorld().getLocStart());
if (dplayer.wolf != null) { if (dplayer.wolf != null) {
dplayer.wolf.teleport(dGroup.getGWorld().getLocStart()); dplayer.wolf.teleport(dGroup.getGameWorld().getLocStart());
} }
} else { } else {
MiscUtil.secureTeleport(dplayer.getPlayer(), dplayer.checkpoint); MiscUtil.secureTeleport(dplayer.getPlayer(), dplayer.checkpoint);