Full support for lives and keeping inventory in dungeons (0.9)

This commit is contained in:
Daniel Saukel 2015-07-14 18:36:34 +02:00
parent efbc9decc1
commit 57a177a8cf
7 changed files with 79 additions and 7 deletions

View File

@ -30,6 +30,8 @@ public class DConfig {
private CopyOnWriteArrayList<String> invitedPlayers = new CopyOnWriteArrayList<String>(); private CopyOnWriteArrayList<String> invitedPlayers = new CopyOnWriteArrayList<String>();
private CopyOnWriteArrayList<Material> secureObjects = new CopyOnWriteArrayList<Material>(); private CopyOnWriteArrayList<Material> secureObjects = new CopyOnWriteArrayList<Material>();
private int initialLives = 3;
private boolean isLobbyDisabled = false; private boolean isLobbyDisabled = false;
private int timeToNextPlay = 0; private int timeToNextPlay = 0;
private int timeToNextLoot = 0; private int timeToNextLoot = 0;
@ -152,6 +154,13 @@ public class DConfig {
keepInventory = mainConfig.keepInventory; keepInventory = mainConfig.keepInventory;
} }
/* keep Inventory */
if (configFile.contains("initialLives")) {
initialLives = configFile.getInt("initialLives");
} else {
initialLives = mainConfig.getInitialLives();
}
/* Lobby */ /* Lobby */
if (configFile.contains("isLobbyDisabled")) { if (configFile.contains("isLobbyDisabled")) {
isLobbyDisabled = configFile.getBoolean("isLobbyDisabled"); isLobbyDisabled = configFile.getBoolean("isLobbyDisabled");
@ -297,6 +306,10 @@ public class DConfig {
return keepInventory; return keepInventory;
} }
public int getInitialLives() {
return initialLives;
}
public boolean isLobbyDisabled() { public boolean isLobbyDisabled() {
return isLobbyDisabled; return isLobbyDisabled;
} }
@ -331,4 +344,5 @@ public class DConfig {
public Set<DMobType> getMobTypes() { public Set<DMobType> getMobTypes() {
return mobTypes; return mobTypes;
} }
} }

View File

@ -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(), 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()); 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().clear();
this.player.getInventory().setArmorContents(null); this.player.getInventory().setArmorContents(null);
this.player.setTotalExperience(0); this.player.setTotalExperience(0);
@ -75,6 +76,10 @@ public class DPlayer {
for (PotionEffect effect : this.player.getActivePotionEffects()) { for (PotionEffect effect : this.player.getActivePotionEffects()) {
this.player.removePotionEffect(effect.getType()); this.player.removePotionEffect(effect.getType());
} }
}
// Lives
P.lives.put(this.player, GameWorld.get(world).config.getInitialLives());
this.isEditing = isEditing; this.isEditing = isEditing;
@ -100,6 +105,9 @@ public class DPlayer {
public void leave() { public void leave() {
remove(this); remove(this);
// Lives
P.lives.remove(player);
this.savePlayer.reset(); this.savePlayer.reset();
if (this.isEditing) { if (this.isEditing) {
@ -204,13 +212,15 @@ public class DPlayer {
} }
// Respawn Items // Respawn Items
if (this.respawnInventory != null || this.respawnArmor != null) { if (!(GameWorld.get(world).config.getKeepInventory())) {
this.player.getInventory().setContents(this.respawnInventory); if (this.respawnInventory != null || this.respawnArmor != null) {
this.player.getInventory().setArmorContents(this.respawnArmor); this.player.getInventory().setContents(this.respawnInventory);
this.respawnInventory = null; this.player.getInventory().setArmorContents(this.respawnArmor);
this.respawnArmor = null; this.respawnInventory = null;
} this.respawnArmor = null;
}
// P.p.updateInventory(this.player); // P.p.updateInventory(this.player);
}
} }
public void finish() { public void finish() {

View File

@ -62,6 +62,8 @@ public class LanguageReader {
defaults.put("Player_SignCreated", "&6Sign created!"); defaults.put("Player_SignCreated", "&6Sign created!");
defaults.put("Player_SignCopied", "&6Copied!"); defaults.put("Player_SignCopied", "&6Copied!");
defaults.put("Player_BlockInfo", "&6Block-ID: &2&v1"); 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 */ /* Cmds */
defaults.put("Cmd_Chat_DungeonChat", "&6You have entered the Dungeon-chat"); 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_Reload_Done", "&6DungeonsXL was successfully reloaded!");
defaults.put("Cmd_Save_Success", "&6Dungeon saved!"); 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_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 */ /* Errors */
defaults.put("Error_Enderchest", "&4You cannot use an enderchest while in a Dungeon!"); 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_Save", "/dxl save - Saves the current dungeon");
defaults.put("Help_Cmd_Test", "/dxl test [dungeon] - Tests a 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_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");
} }

View File

@ -7,6 +7,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.nio.channels.FileChannel; import java.nio.channels.FileChannel;
import java.util.HashMap;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.CopyOnWriteArrayList; 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.game.GameWorld;
import com.dre.dungeonsxl.listener.BlockListener; import com.dre.dungeonsxl.listener.BlockListener;
import com.dre.dungeonsxl.listener.CommandListener; import com.dre.dungeonsxl.listener.CommandListener;
import com.dre.dungeonsxl.listener.DeathListener;
import com.dre.dungeonsxl.listener.EntityListener; import com.dre.dungeonsxl.listener.EntityListener;
import com.dre.dungeonsxl.listener.HangingListener; import com.dre.dungeonsxl.listener.HangingListener;
import com.dre.dungeonsxl.listener.PlayerListener; import com.dre.dungeonsxl.listener.PlayerListener;
@ -45,12 +47,16 @@ import com.dre.dungeonsxl.listener.WorldListener;
public class P extends JavaPlugin { public class P extends JavaPlugin {
public static P p; public static P p;
// Lives
public static HashMap<Player, Integer> lives;
// Listener // Listener
private static Listener entityListener; private static Listener entityListener;
private static Listener playerListener; private static Listener playerListener;
private static Listener blockListener; private static Listener blockListener;
private static Listener worldListener; private static Listener worldListener;
private static Listener hangingListener; private static Listener hangingListener;
private static Listener deathListener;
// Main Config Reader // Main Config Reader
public MainConfig mainConfig; public MainConfig mainConfig;
@ -65,6 +71,9 @@ public class P extends JavaPlugin {
public void onEnable() { public void onEnable() {
p = this; p = this;
// Lives
lives = new HashMap<Player, Integer>();
// Commands // Commands
getCommand("dungeonsxl").setExecutor(new CommandListener()); getCommand("dungeonsxl").setExecutor(new CommandListener());
@ -92,12 +101,14 @@ public class P extends JavaPlugin {
blockListener = new BlockListener(); blockListener = new BlockListener();
worldListener = new WorldListener(); worldListener = new WorldListener();
hangingListener = new HangingListener(); hangingListener = new HangingListener();
deathListener = new DeathListener();
Bukkit.getServer().getPluginManager().registerEvents(entityListener, this); Bukkit.getServer().getPluginManager().registerEvents(entityListener, this);
Bukkit.getServer().getPluginManager().registerEvents(playerListener, this); Bukkit.getServer().getPluginManager().registerEvents(playerListener, this);
Bukkit.getServer().getPluginManager().registerEvents(blockListener, this); Bukkit.getServer().getPluginManager().registerEvents(blockListener, this);
Bukkit.getServer().getPluginManager().registerEvents(worldListener, this); Bukkit.getServer().getPluginManager().registerEvents(worldListener, this);
Bukkit.getServer().getPluginManager().registerEvents(hangingListener, this); Bukkit.getServer().getPluginManager().registerEvents(hangingListener, this);
Bukkit.getServer().getPluginManager().registerEvents(deathListener, this);
// Load All // Load All
this.loadAll(); this.loadAll();

View File

@ -25,6 +25,7 @@ public class DCommandRoot {
public CMDTest cmdTest = new CMDTest(); public CMDTest cmdTest = new CMDTest();
public CMDHelp cmdHelp = new CMDHelp(); public CMDHelp cmdHelp = new CMDHelp();
public CMDReload cmdReload = new CMDReload(); public CMDReload cmdReload = new CMDReload();
public CMDLives cmdLives = new CMDLives();
// Methods // Methods
public DCommandRoot() { public DCommandRoot() {
@ -47,5 +48,6 @@ public class DCommandRoot {
this.commands.add(cmdTest); this.commands.add(cmdTest);
this.commands.add(cmdHelp); this.commands.add(cmdHelp);
this.commands.add(cmdReload); this.commands.add(cmdReload);
this.commands.add(cmdLives);
} }
} }

View 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)));
}
}
}

View File

@ -1,6 +1,6 @@
name: DungeonsXL name: DungeonsXL
main: com.dre.dungeonsxl.P main: com.dre.dungeonsxl.P
version: 0.9-SNAPSHOT version: 0.9
author: Frank Baumann author: Frank Baumann
authors: [Frank Baumann, Milan Albrecht, Tobias Schmitz, Daniel Saukel] authors: [Frank Baumann, Milan Albrecht, Tobias Schmitz, Daniel Saukel]
website: http://www.dre2n.ml website: http://www.dre2n.ml