mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-24 19:45:43 +01:00
Full support for lives and keeping inventory in dungeons (0.9)
This commit is contained in:
parent
efbc9decc1
commit
57a177a8cf
@ -30,6 +30,8 @@ public class DConfig {
|
||||
private CopyOnWriteArrayList<String> invitedPlayers = new CopyOnWriteArrayList<String>();
|
||||
private CopyOnWriteArrayList<Material> secureObjects = new CopyOnWriteArrayList<Material>();
|
||||
|
||||
private int initialLives = 3;
|
||||
|
||||
private boolean isLobbyDisabled = false;
|
||||
private int timeToNextPlay = 0;
|
||||
private int timeToNextLoot = 0;
|
||||
@ -152,6 +154,13 @@ public class DConfig {
|
||||
keepInventory = mainConfig.keepInventory;
|
||||
}
|
||||
|
||||
/* keep Inventory */
|
||||
if (configFile.contains("initialLives")) {
|
||||
initialLives = configFile.getInt("initialLives");
|
||||
} else {
|
||||
initialLives = mainConfig.getInitialLives();
|
||||
}
|
||||
|
||||
/* Lobby */
|
||||
if (configFile.contains("isLobbyDisabled")) {
|
||||
isLobbyDisabled = configFile.getBoolean("isLobbyDisabled");
|
||||
@ -297,6 +306,10 @@ public class DConfig {
|
||||
return keepInventory;
|
||||
}
|
||||
|
||||
public int getInitialLives() {
|
||||
return initialLives;
|
||||
}
|
||||
|
||||
public boolean isLobbyDisabled() {
|
||||
return isLobbyDisabled;
|
||||
}
|
||||
@ -331,4 +344,5 @@ public class DConfig {
|
||||
public Set<DMobType> getMobTypes() {
|
||||
return mobTypes;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -66,6 +66,7 @@ public class DPlayer {
|
||||
this.savePlayer = new DSavePlayer(player.getName(), player.getUniqueId(), player.getLocation(), player.getInventory().getContents(), player.getInventory().getArmorContents(), player.getLevel(),
|
||||
player.getTotalExperience(), (int) health, player.getFoodLevel(), player.getFireTicks(), player.getGameMode(), player.getActivePotionEffects());
|
||||
|
||||
if (!(GameWorld.get(world).config.getKeepInventory())) {
|
||||
this.player.getInventory().clear();
|
||||
this.player.getInventory().setArmorContents(null);
|
||||
this.player.setTotalExperience(0);
|
||||
@ -75,6 +76,10 @@ public class DPlayer {
|
||||
for (PotionEffect effect : this.player.getActivePotionEffects()) {
|
||||
this.player.removePotionEffect(effect.getType());
|
||||
}
|
||||
}
|
||||
|
||||
// Lives
|
||||
P.lives.put(this.player, GameWorld.get(world).config.getInitialLives());
|
||||
|
||||
this.isEditing = isEditing;
|
||||
|
||||
@ -100,6 +105,9 @@ public class DPlayer {
|
||||
public void leave() {
|
||||
remove(this);
|
||||
|
||||
// Lives
|
||||
P.lives.remove(player);
|
||||
|
||||
this.savePlayer.reset();
|
||||
|
||||
if (this.isEditing) {
|
||||
@ -204,6 +212,7 @@ public class DPlayer {
|
||||
}
|
||||
|
||||
// Respawn Items
|
||||
if (!(GameWorld.get(world).config.getKeepInventory())) {
|
||||
if (this.respawnInventory != null || this.respawnArmor != null) {
|
||||
this.player.getInventory().setContents(this.respawnInventory);
|
||||
this.player.getInventory().setArmorContents(this.respawnArmor);
|
||||
@ -212,6 +221,7 @@ public class DPlayer {
|
||||
}
|
||||
// P.p.updateInventory(this.player);
|
||||
}
|
||||
}
|
||||
|
||||
public void finish() {
|
||||
p.msg(this.player, p.language.get("Player_FinishedDungeon"));
|
||||
|
@ -62,6 +62,8 @@ public class LanguageReader {
|
||||
defaults.put("Player_SignCreated", "&6Sign created!");
|
||||
defaults.put("Player_SignCopied", "&6Copied!");
|
||||
defaults.put("Player_BlockInfo", "&6Block-ID: &2&v1");
|
||||
defaults.put("Player_Death", "&6You died, lives left: &2v1");
|
||||
defaults.put("Player_DeathKick", "&2v1&6 died and lost his last life.");
|
||||
|
||||
/* Cmds */
|
||||
defaults.put("Cmd_Chat_DungeonChat", "&6You have entered the Dungeon-chat");
|
||||
@ -76,6 +78,7 @@ public class LanguageReader {
|
||||
defaults.put("Cmd_Reload_Done", "&6DungeonsXL was successfully reloaded!");
|
||||
defaults.put("Cmd_Save_Success", "&6Dungeon saved!");
|
||||
defaults.put("Cmd_Uninvite_Success", "&4&v1&6 was successfully uninvited to edit the Dungeon &4&v1&6!");
|
||||
defaults.put("Cmd_Lives", "&4v1&6 has &4v2 &6lives left.");
|
||||
|
||||
/* Errors */
|
||||
defaults.put("Error_Enderchest", "&4You cannot use an enderchest while in a Dungeon!");
|
||||
@ -121,6 +124,7 @@ public class LanguageReader {
|
||||
defaults.put("Help_Cmd_Save", "/dxl save - Saves the current dungeon");
|
||||
defaults.put("Help_Cmd_Test", "/dxl test [dungeon] - Tests a dungeon");
|
||||
defaults.put("Help_Cmd_Uninvite", "/dxl uninvite <player> <dungeon> - Uninvite a player to edit a dungeon");
|
||||
defaults.put("Help_Cmd_Lives", "/dxl lives <player> - show the lives a player has left");
|
||||
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
@ -37,6 +38,7 @@ import com.dre.dungeonsxl.commands.DCommandRoot;
|
||||
import com.dre.dungeonsxl.game.GameWorld;
|
||||
import com.dre.dungeonsxl.listener.BlockListener;
|
||||
import com.dre.dungeonsxl.listener.CommandListener;
|
||||
import com.dre.dungeonsxl.listener.DeathListener;
|
||||
import com.dre.dungeonsxl.listener.EntityListener;
|
||||
import com.dre.dungeonsxl.listener.HangingListener;
|
||||
import com.dre.dungeonsxl.listener.PlayerListener;
|
||||
@ -45,12 +47,16 @@ import com.dre.dungeonsxl.listener.WorldListener;
|
||||
public class P extends JavaPlugin {
|
||||
public static P p;
|
||||
|
||||
// Lives
|
||||
public static HashMap<Player, Integer> lives;
|
||||
|
||||
// Listener
|
||||
private static Listener entityListener;
|
||||
private static Listener playerListener;
|
||||
private static Listener blockListener;
|
||||
private static Listener worldListener;
|
||||
private static Listener hangingListener;
|
||||
private static Listener deathListener;
|
||||
|
||||
// Main Config Reader
|
||||
public MainConfig mainConfig;
|
||||
@ -65,6 +71,9 @@ public class P extends JavaPlugin {
|
||||
public void onEnable() {
|
||||
p = this;
|
||||
|
||||
// Lives
|
||||
lives = new HashMap<Player, Integer>();
|
||||
|
||||
// Commands
|
||||
getCommand("dungeonsxl").setExecutor(new CommandListener());
|
||||
|
||||
@ -92,12 +101,14 @@ public class P extends JavaPlugin {
|
||||
blockListener = new BlockListener();
|
||||
worldListener = new WorldListener();
|
||||
hangingListener = new HangingListener();
|
||||
deathListener = new DeathListener();
|
||||
|
||||
Bukkit.getServer().getPluginManager().registerEvents(entityListener, this);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(playerListener, this);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(blockListener, this);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(worldListener, this);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(hangingListener, this);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(deathListener, this);
|
||||
|
||||
// Load All
|
||||
this.loadAll();
|
||||
|
@ -25,6 +25,7 @@ public class DCommandRoot {
|
||||
public CMDTest cmdTest = new CMDTest();
|
||||
public CMDHelp cmdHelp = new CMDHelp();
|
||||
public CMDReload cmdReload = new CMDReload();
|
||||
public CMDLives cmdLives = new CMDLives();
|
||||
|
||||
// Methods
|
||||
public DCommandRoot() {
|
||||
@ -47,5 +48,6 @@ public class DCommandRoot {
|
||||
this.commands.add(cmdTest);
|
||||
this.commands.add(cmdHelp);
|
||||
this.commands.add(cmdReload);
|
||||
this.commands.add(cmdLives);
|
||||
}
|
||||
}
|
||||
|
31
src/com/dre/dungeonsxl/listener/DeathListener.java
Normal file
31
src/com/dre/dungeonsxl/listener/DeathListener.java
Normal file
@ -0,0 +1,31 @@
|
||||
package com.dre.dungeonsxl.listener;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
|
||||
import com.dre.dungeonsxl.P;
|
||||
|
||||
public class DeathListener implements Listener {
|
||||
|
||||
P p = P.p;
|
||||
int lives = -1;
|
||||
|
||||
@EventHandler
|
||||
public void onDeath(PlayerDeathEvent event) {
|
||||
Player player = event.getEntity();
|
||||
if (P.lives.containsKey(player)) {
|
||||
lives = P.lives.get(player) - 1;
|
||||
P.lives.put(player, lives);
|
||||
}
|
||||
if (lives == 0) {
|
||||
Bukkit.broadcastMessage(p.language.get("Player_DeathKick").replaceAll("v1", player.getName()).replaceAll("&", "\u00a76"));
|
||||
player.performCommand("dxl leave");
|
||||
} else if (!(lives == -1)) {
|
||||
p.msg(player, p.language.get("Player_Death").replaceAll("v1", String.valueOf(lives)));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
name: DungeonsXL
|
||||
main: com.dre.dungeonsxl.P
|
||||
version: 0.9-SNAPSHOT
|
||||
version: 0.9
|
||||
author: Frank Baumann
|
||||
authors: [Frank Baumann, Milan Albrecht, Tobias Schmitz, Daniel Saukel]
|
||||
website: http://www.dre2n.ml
|
||||
|
Loading…
Reference in New Issue
Block a user