Skip to content

Commit

Permalink
Fix player respawn location after exhausting all lives in dungeon; re…
Browse files Browse the repository at this point in the history
…solves #341
  • Loading branch information
Sataniel98 committed Jun 20, 2018
1 parent b65b4df commit 2b825e1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ If you want to learn how to use DungeonsXL step by step, please have a look at t

## Compatibility
### Server
DungeonsXL works with 1.8.8 and higher. However, support for 1.12.x / 1.11.x / 1.10.x / 1.9.x has a higher priority than support for 1.8.8. Old builds that support older versions are unusable for production environments. See [here](../../wiki/legacy-support) for detailed information. Some cosmetic features require the Spigot API and will therefore not work with CraftBukkit.
DungeonsXL works with 1.8.8 and higher. However, support for 1.13 / 1.12.x / 1.11.x / 1.10.x / 1.9.x has a higher priority than support for 1.8.8. Old builds that support older versions are unusable for production environments. See [here](../../wiki/legacy-support) for detailed information. Some cosmetic features require the Spigot API and will therefore not work with CraftBukkit.

### Building information and dependencies
Building DungeonsXL from source requires [Apache Maven](https://maven.apache.org/).
Maven automatically fetches all dependencies and builds DungeonsXL; just run _build.bat_ or enter the command _mvn clean install_.

#### DRECommons
[DRECommons](https://github.com/DRE2N/DRECommons) is a util library for common tasks. DungeonsXL contains DRECommons 4.2.
[DRECommons](https://github.com/DRE2N/DRECommons) is a util library for common tasks. DungeonsXL contains DRECommons 4.2.1.

#### Caliburn API
[Caliburn](https://github.com/DRE2N/CaliburnAPI) is an API to read custom items and mobs from config files. DungeonsXL contains Caliburn Beta 0.4.1.
[Caliburn](https://github.com/DRE2N/CaliburnAPI) is an API to read custom items and mobs from config files. DungeonsXL contains Caliburn Beta 0.4.2.

### Java
Make sure that your server uses Java 8 or higher.
Expand All @@ -69,6 +69,7 @@ Supported.
### Known incompatibilities
* Towny
* Corpses
* PerWorldInventory

Many incompatibilities can be fixed with [PerWorldPlugins](http://dev.bukkit.org/bukkit-plugins/perworldplugins/) ([fork for 1.8+](https://www.spigotmc.org/resources/perworldplugins-unofficial-update-version.6454/)).
Try to add the incompatible plugins only to the worlds where you need them.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
<dependency>
<groupId>de.erethon</groupId>
<artifactId>caliburn</artifactId>
<version>0.4.1</version>
<version>0.4.2</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down
24 changes: 18 additions & 6 deletions src/main/java/de/erethon/dungeonsxl/player/DGlobalPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@
import java.util.List;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.attribute.Attribute;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.scheduler.BukkitRunnable;

/**
* Represents a player in the non-DXL worlds of the server.
Expand Down Expand Up @@ -322,7 +324,23 @@ public void sendMessage(String message) {
* Respawns the player at his old position before he was in a dungeon
*/
public void reset(boolean keepInventory) {
final Location tpLoc = data.getOldLocation().getWorld() != null ? data.getOldLocation() : Bukkit.getWorlds().get(0).getSpawnLocation();
if (player.isDead()) {
new BukkitRunnable() {
@Override
public void run() {
PlayerUtil.respawn(player);
reset(tpLoc, keepInventory);
}
}.runTaskLater(plugin, 1L);
} else {
reset(tpLoc, keepInventory);
}
}

private void reset(Location tpLoc, boolean keepInventory) {
try {
PlayerUtil.secureTeleport(player, tpLoc);
if (!keepInventory) {
while (data.getOldInventory().size() > 36) {
data.getOldInventory().remove(36);
Expand All @@ -348,12 +366,6 @@ public void reset(boolean keepInventory) {
player.addPotionEffects(data.getOldPotionEffects());
}

if (data.getOldLocation().getWorld() != null) {
PlayerUtil.secureTeleport(player, data.getOldLocation());
} else {
PlayerUtil.secureTeleport(player, Bukkit.getWorlds().get(0).getSpawnLocation());
}

} catch (NullPointerException exception) {
exception.printStackTrace();
player.setHealth(0);
Expand Down

0 comments on commit 2b825e1

Please sign in to comment.