Split keepInventory (WIP)

This commit is contained in:
Daniel Saukel 2015-08-12 17:05:53 +02:00
parent c562999f11
commit c8a9b510d4
6 changed files with 109 additions and 54 deletions

View File

@ -23,6 +23,10 @@ public class DConfig {
private File file;
private boolean keepInventory = false;
private boolean keepInventoryOnEnter = false;
private boolean keepInventoryOnEscape = false;
private boolean keepInventoryOnFinish = false;
private boolean keepInventoryOnDeath = true;
private CopyOnWriteArrayList<DClass> dClasses = new CopyOnWriteArrayList<DClass>();
private Map<Integer, String> msgs = new HashMap<Integer, String>();
@ -149,14 +153,40 @@ public class DConfig {
}
}
/* keep Inventory */
/* Keep Inventory */
if (configFile.contains("keepInventory")) {
keepInventory = configFile.getBoolean("keepInventory");
keepInventoryOnEnter = configFile.getBoolean("keepInventory");
keepInventoryOnEscape = configFile.getBoolean("keepInventory");
keepInventoryOnFinish = configFile.getBoolean("keepInventory");
} else {
keepInventory = mainConfig.keepInventory;
}
/* keep Inventory */
if (configFile.contains("keepInventoryOnEnter")) {
keepInventoryOnEnter = configFile.getBoolean("keepInventoryOnEnter");
} else {
keepInventoryOnEnter = mainConfig.keepInventoryOnEnter;
}
if (configFile.contains("keepInventoryOnEscape")) {
keepInventoryOnEscape = configFile.getBoolean("keepInventoryOnEscape");
} else {
keepInventoryOnEscape = mainConfig.keepInventoryOnEscape;
}
if (configFile.contains("keepInventoryOnFinish")) {
keepInventoryOnFinish = configFile.getBoolean("keepInventoryOnFinish");
} else {
keepInventoryOnFinish = mainConfig.keepInventoryOnFinish;
}
if (configFile.contains("keepInventoryOnDeath")) {
keepInventoryOnDeath = configFile.getBoolean("keepInventoryOnDeath");
} else {
keepInventoryOnDeath = mainConfig.keepInventoryOnDeath;
}
/* Lives */
if (configFile.contains("initialLives")) {
initialLives = configFile.getInt("initialLives");
} else {
@ -316,6 +346,22 @@ public class DConfig {
return keepInventory;
}
public boolean getKeepInventoryOnEnter() {
return keepInventoryOnEnter;
}
public boolean getKeepInventoryOnEscape() {
return keepInventoryOnEscape;
}
public boolean getKeepInventoryOnFinish() {
return keepInventoryOnFinish;
}
public boolean getKeepInventoryOnDeath() {
return keepInventoryOnDeath;
}
public int getInitialLives() {
return initialLives;
}

View File

@ -76,7 +76,7 @@ public class DPlayer {
this.clearPlayerData();
} else {
this.player.setGameMode(GameMode.SURVIVAL);
if (!(GameWorld.get(world).config.getKeepInventory())) {
if (!(GameWorld.get(world).config.getKeepInventoryOnEnter())) {
this.clearPlayerData();
}
if (GameWorld.get(world).config.isLobbyDisabled()) {
@ -218,7 +218,7 @@ public class DPlayer {
}
// Respawn Items
if (!(GameWorld.get(world).config.getKeepInventory())) {
if (!(GameWorld.get(world).config.getKeepInventoryOnDeath())) {
if (this.respawnInventory != null || this.respawnArmor != null) {
this.player.getInventory().setContents(this.respawnInventory);
this.player.getInventory().setArmorContents(this.respawnArmor);

View File

@ -32,11 +32,11 @@ 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;
import com.dre.dungeonsxl.listener.WorldListener;
import com.dre.dungeonsxl.listener.player.PlayerDeathListener;
import com.dre.dungeonsxl.multiversionhandler.MultiVersionHandler;
public class P extends JavaPlugin {
@ -51,7 +51,7 @@ public class P extends JavaPlugin {
private static Listener blockListener;
private static Listener worldListener;
private static Listener hangingListener;
private static Listener deathListener;
private static Listener playerDeathListener;
// Main Config Reader
public MainConfig mainConfig;
@ -99,14 +99,14 @@ public class P extends JavaPlugin {
blockListener = new BlockListener();
worldListener = new WorldListener();
hangingListener = new HangingListener();
deathListener = new DeathListener();
playerDeathListener = new PlayerDeathListener();
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);
Bukkit.getServer().getPluginManager().registerEvents(playerDeathListener, this);
// Load All
this.loadAll();

View File

@ -1,31 +0,0 @@
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

@ -10,7 +10,6 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent;
@ -378,19 +377,6 @@ public class PlayerListener implements Listener {
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerDeath(PlayerDeathEvent event) {
DPlayer dplayer = DPlayer.get(event.getEntity());
if (dplayer != null) {
dplayer.respawnInventory = event.getEntity().getInventory().getContents();
dplayer.respawnArmor = event.getEntity().getInventory().getArmorContents();
// Delete all drops
for (ItemStack istack : event.getDrops()) {
istack.setType(Material.AIR);
}
}
}
// Deny Player Cmds
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerCommand(PlayerCommandPreprocessEvent event) {

View File

@ -0,0 +1,54 @@
package com.dre.dungeonsxl.listener.player;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.inventory.ItemStack;
import com.dre.dungeonsxl.DConfig;
import com.dre.dungeonsxl.DPlayer;
import com.dre.dungeonsxl.P;
import com.dre.dungeonsxl.game.GameWorld;
public class PlayerDeathListener implements Listener {
P p = P.p;
int lives = -1;
@EventHandler(priority = EventPriority.HIGH)
public void onDeath(PlayerDeathEvent event) {
Player player = event.getEntity();
DPlayer dplayer = DPlayer.get(player);
DConfig dConfig = GameWorld.get(player.getLocation().getWorld()).config;
if (dConfig.getKeepInventoryOnDeath()) {
if (dplayer != null) {
dplayer.respawnInventory = event.getEntity().getInventory().getContents();
dplayer.respawnArmor = event.getEntity().getInventory().getArmorContents();
// Delete all drops
for (ItemStack istack : event.getDrops()) {
istack.setType(Material.AIR);
}
}
}
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)));
}
}
}