mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-25 12:15:12 +01:00
Added KEEP_INVENTORY flag
Related to https://github.com/tastybento/bskyblock/issues/77 Also made some tiny adjustements, and tidied imports up.
This commit is contained in:
parent
2acace84cd
commit
00feaa4740
@ -1,18 +1,17 @@
|
||||
package us.tastybento.bskyblock.config;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import us.tastybento.bskyblock.database.BSBDatabase.DatabaseType;
|
||||
import us.tastybento.bskyblock.database.managers.OfflineHistoryMessages.HistoryMessageType;
|
||||
import us.tastybento.bskyblock.database.objects.Island.SettingsFlag;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* All the plugin settings are here
|
||||
* @author Tastybento
|
||||
@ -224,6 +223,5 @@ public class Settings {
|
||||
public static HashMap<String,Integer> limitedBlocks;
|
||||
public static boolean allowTNTPushing;
|
||||
public static boolean showInActionBar;
|
||||
public static boolean allowVisitorKeepInvOnDeath;
|
||||
|
||||
}
|
||||
|
@ -1,23 +1,18 @@
|
||||
package us.tastybento.bskyblock.database.objects;
|
||||
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.Entity;
|
||||
import us.tastybento.bskyblock.api.events.island.IslandLockEvent;
|
||||
import us.tastybento.bskyblock.api.events.island.IslandUnlockEvent;
|
||||
import us.tastybento.bskyblock.config.Settings;
|
||||
import us.tastybento.bskyblock.util.Util;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
import us.tastybento.bskyblock.api.events.island.IslandLockEvent;
|
||||
import us.tastybento.bskyblock.api.events.island.IslandUnlockEvent;
|
||||
import us.tastybento.bskyblock.config.Settings;
|
||||
import us.tastybento.bskyblock.util.Util;
|
||||
|
||||
/**
|
||||
* Stores all the info about an island
|
||||
* Managed by IslandsManager
|
||||
@ -169,6 +164,9 @@ public class Island extends DataObject {
|
||||
// Can pickup items
|
||||
ITEM_PICKUP,
|
||||
|
||||
// Keep inventory on death
|
||||
KEEP_INVENTORY,
|
||||
|
||||
// Can leash or unleash animals
|
||||
LEASH,
|
||||
|
||||
|
@ -1,12 +1,11 @@
|
||||
package us.tastybento.bskyblock.listeners.protection;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
|
||||
/**
|
||||
* Stashes inventories when required for a player
|
||||
*
|
||||
@ -63,4 +62,13 @@ public class InventorySave {
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the player's inventory has been stored to give him back.
|
||||
*
|
||||
* @param uuid UUID of the player
|
||||
* @return <code>true</code> if the inventory is stored, <code>false</code> otherwise
|
||||
*/
|
||||
public static boolean isStored(UUID uuid) {
|
||||
return instance.inventories.containsKey(uuid);
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ public class VisitorGuard implements Listener {
|
||||
* Also handles muting of death messages
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onVistorDeath(final PlayerDeathEvent e) {
|
||||
public void onVisitorDeath(final PlayerDeathEvent e) {
|
||||
if (DEBUG) {
|
||||
plugin.getLogger().info(e.getEventName());
|
||||
}
|
||||
@ -50,13 +50,10 @@ public class VisitorGuard implements Listener {
|
||||
if (Settings.muteDeathMessages) {
|
||||
e.setDeathMessage(null);
|
||||
}
|
||||
// If visitors will keep items and their level on death
|
||||
// This will override any global settings
|
||||
if (Settings.allowVisitorKeepInvOnDeath) {
|
||||
// If the player is not a visitor then they die and lose everything -
|
||||
// sorry :-(
|
||||
// If visitors will keep items and their level on death. This overrides any global settings.
|
||||
// If the player is not a visitor then they die and lose everything - sorry :-(
|
||||
Island island = plugin.getIslands().getProtectedIslandAt(e.getEntity().getLocation());
|
||||
if (island != null && !island.getMembers().contains(e.getEntity().getUniqueId())) {
|
||||
if (island != null && !island.getMembers().contains(e.getEntity().getUniqueId()) && island.getFlag(SettingsFlag.KEEP_INVENTORY)) {
|
||||
// They are a visitor
|
||||
InventorySave.getInstance().savePlayerInventory(e.getEntity());
|
||||
e.getDrops().clear();
|
||||
@ -64,15 +61,14 @@ public class VisitorGuard implements Listener {
|
||||
e.setDroppedExp(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onVistorSpawn(final PlayerRespawnEvent e) {
|
||||
public void onVisitorSpawn(final PlayerRespawnEvent e) {
|
||||
if (DEBUG) {
|
||||
plugin.getLogger().info(e.getEventName());
|
||||
}
|
||||
// This will override any global settings
|
||||
if (Settings.allowVisitorKeepInvOnDeath) {
|
||||
// If the player died on an island and his inventory has been saved, give it him back. This will override any global settings.
|
||||
if (InventorySave.isStored(e.getPlayer().getUniqueId())) {
|
||||
InventorySave.getInstance().loadPlayerInventory(e.getPlayer());
|
||||
InventorySave.getInstance().clearSavedInventory(e.getPlayer());
|
||||
}
|
||||
@ -147,7 +143,7 @@ public class VisitorGuard implements Listener {
|
||||
* @param e
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onVisitorGetDamage(EntityDamageEvent e){
|
||||
public void onVisitorReceiveDamage(EntityDamageEvent e){
|
||||
if(!Settings.invincibleVisitor) return;
|
||||
if(!(e.getEntity() instanceof Player)) return;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user