Fixed overzealous protection of death drops.
Hash overlaps are to blame, I think. Limiting protections to the immediate area where the player died.
This commit is contained in:
parent
81db249b2e
commit
2d94e6fdc7
|
|
@ -240,7 +240,7 @@ class EntityEventHandler implements Listener
|
|||
List<ItemStack> drops = event.getDrops();
|
||||
for(ItemStack stack : drops)
|
||||
{
|
||||
GriefPrevention.instance.itemStackOwnerMap.put(stack, player.getUniqueId());
|
||||
GriefPrevention.instance.itemStackOwnerMap.put(stack, new ItemStackOwnerInfo(player.getUniqueId(), player.getLocation()));
|
||||
}
|
||||
|
||||
//allow the player to receive a message about how to unlock any drops
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ public class GriefPrevention extends JavaPlugin
|
|||
public DataStore dataStore;
|
||||
|
||||
//this remembers which item stacks dropped in the world belong to which players
|
||||
ConcurrentHashMap<ItemStack, UUID> itemStackOwnerMap = new ConcurrentHashMap<ItemStack, UUID>();
|
||||
ConcurrentHashMap<ItemStack, ItemStackOwnerInfo> itemStackOwnerMap = new ConcurrentHashMap<ItemStack, ItemStackOwnerInfo>();
|
||||
|
||||
//configuration variables, loaded/saved from a config.yml
|
||||
|
||||
|
|
|
|||
17
src/me/ryanhamshire/GriefPrevention/ItemStackOwnerInfo.java
Normal file
17
src/me/ryanhamshire/GriefPrevention/ItemStackOwnerInfo.java
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
package me.ryanhamshire.GriefPrevention;
|
||||
|
||||
import java.util.UUID;
|
||||
import org.bukkit.Location;
|
||||
|
||||
//tracks an item stack's owner. ownership is limited to a locality due to problems with hash overlaps overprotecting item stacks
|
||||
class ItemStackOwnerInfo
|
||||
{
|
||||
public UUID ownerID;
|
||||
public Location locality;
|
||||
|
||||
public ItemStackOwnerInfo(UUID ownerID, Location location)
|
||||
{
|
||||
this.ownerID = ownerID;
|
||||
this.locality = location;
|
||||
}
|
||||
}
|
||||
|
|
@ -929,18 +929,24 @@ class PlayerEventHandler implements Listener
|
|||
|
||||
//who owns this stack?
|
||||
ItemStack stack = event.getItem().getItemStack();
|
||||
UUID ownerID = GriefPrevention.instance.itemStackOwnerMap.get(stack);
|
||||
if(ownerID != null)
|
||||
ItemStackOwnerInfo ownerInfo = GriefPrevention.instance.itemStackOwnerMap.get(stack);
|
||||
if(ownerInfo != null)
|
||||
{
|
||||
//has that player unlocked his drops?
|
||||
OfflinePlayer owner = GriefPrevention.instance.getServer().getOfflinePlayer(ownerID);
|
||||
String ownerName = GriefPrevention.lookupPlayerName(ownerID);
|
||||
OfflinePlayer owner = GriefPrevention.instance.getServer().getOfflinePlayer(ownerInfo.ownerID);
|
||||
String ownerName = GriefPrevention.lookupPlayerName(ownerInfo.ownerID);
|
||||
if(owner.isOnline() && !player.equals(owner))
|
||||
{
|
||||
PlayerData playerData = this.dataStore.getPlayerData(ownerID);
|
||||
PlayerData playerData = this.dataStore.getPlayerData(ownerInfo.ownerID);
|
||||
Location location = event.getItem().getLocation();
|
||||
|
||||
//if locked, don't allow pickup
|
||||
if(!playerData.dropsAreUnlocked)
|
||||
//if locked and in locality of protection, don't allow pickup
|
||||
if(!playerData.dropsAreUnlocked
|
||||
&& location.getX() > ownerInfo.locality.getX() - 10
|
||||
&& location.getX() < ownerInfo.locality.getX() + 10
|
||||
&& location.getZ() < ownerInfo.locality.getZ() + 10
|
||||
&& location.getZ() > ownerInfo.locality.getZ() - 10
|
||||
&& location.getY() < ownerInfo.locality.getY() + 5)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user