Update siege spoils feature.

Previously transferred all items from defender to attacker if the
defender was killed.  Will now transfer only those which would have been
dropped (other plugins can remove from and otherwise change the drop
list before GP does anything with it).
This commit is contained in:
ryanhamshire 2016-05-05 08:39:20 -07:00
parent 4d9175e9a9
commit fe2446b757
3 changed files with 10 additions and 17 deletions

View File

@ -957,7 +957,7 @@ public abstract class DataStore
//ends a siege
//either winnerName or loserName can be null, but not both
synchronized public void endSiege(SiegeData siegeData, String winnerName, String loserName, boolean death)
synchronized public void endSiege(SiegeData siegeData, String winnerName, String loserName, List<ItemStack> drops)
{
boolean grantAccess = false;
@ -1043,7 +1043,7 @@ public abstract class DataStore
}
//if the siege ended due to death, transfer inventory to winner
if(death)
if(drops != null)
{
@SuppressWarnings("deprecation")
Player winner = GriefPrevention.instance.getServer().getPlayer(winnerName);
@ -1051,16 +1051,12 @@ public abstract class DataStore
Player loser = GriefPrevention.instance.getServer().getPlayer(loserName);
if(winner != null && loser != null)
{
//get loser's inventory, then clear it
ItemStack [] loserItems = loser.getInventory().getContents();
loser.getInventory().clear();
//try to add it to the winner's inventory
for(int j = 0; j < loserItems.length; j++)
//try to add any drops to the winner's inventory
for(ItemStack stack : drops)
{
if(loserItems[j] == null || loserItems[j].getType() == Material.AIR || loserItems[j].getAmount() == 0) continue;
if(stack == null || stack.getType() == Material.AIR || stack.getAmount() == 0) continue;
HashMap<Integer, ItemStack> wontFitItems = winner.getInventory().addItem(loserItems[j]);
HashMap<Integer, ItemStack> wontFitItems = winner.getInventory().addItem(stack);
//drop any remainder on the ground at his feet
Object [] keys = wontFitItems.keySet().toArray();

View File

@ -455,11 +455,8 @@ public class EntityEventHandler implements Listener
//if involved in a siege
if(playerData.siegeData != null)
{
//don't drop items as usual, they will be sent to the siege winner
event.getDrops().clear();
//end it, with the dieing player being the loser
this.dataStore.endSiege(playerData.siegeData, null, player.getName(), true /*ended due to death*/);
this.dataStore.endSiege(playerData.siegeData, null, player.getName(), event.getDrops());
}
//FEATURE: lock dropped items to player who dropped them

View File

@ -65,13 +65,13 @@ class SiegeCheckupTask implements Runnable
//otherwise attacker wins if the defender runs away
else if(attackerRemains && !defenderRemains)
{
dataStore.endSiege(this.siegeData, attacker.getName(), defender.getName(), false);
dataStore.endSiege(this.siegeData, attacker.getName(), defender.getName(), null);
}
//or defender wins if the attacker leaves
else if(!attackerRemains && defenderRemains)
{
dataStore.endSiege(this.siegeData, defender.getName(), attacker.getName(), false);
dataStore.endSiege(this.siegeData, defender.getName(), attacker.getName(), null);
}
//if they both left, but are still close together, the battle continues (check again later)
@ -83,7 +83,7 @@ class SiegeCheckupTask implements Runnable
//otherwise they both left and aren't close to each other, so call the attacker the winner (defender escaped, possibly after a chase)
else
{
dataStore.endSiege(this.siegeData, attacker.getName(), defender.getName(), false);
dataStore.endSiege(this.siegeData, attacker.getName(), defender.getName(), null);
}
}