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:
parent
4d9175e9a9
commit
fe2446b757
|
|
@ -957,7 +957,7 @@ public abstract class DataStore
|
||||||
|
|
||||||
//ends a siege
|
//ends a siege
|
||||||
//either winnerName or loserName can be null, but not both
|
//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;
|
boolean grantAccess = false;
|
||||||
|
|
||||||
|
|
@ -1043,7 +1043,7 @@ public abstract class DataStore
|
||||||
}
|
}
|
||||||
|
|
||||||
//if the siege ended due to death, transfer inventory to winner
|
//if the siege ended due to death, transfer inventory to winner
|
||||||
if(death)
|
if(drops != null)
|
||||||
{
|
{
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
Player winner = GriefPrevention.instance.getServer().getPlayer(winnerName);
|
Player winner = GriefPrevention.instance.getServer().getPlayer(winnerName);
|
||||||
|
|
@ -1051,16 +1051,12 @@ public abstract class DataStore
|
||||||
Player loser = GriefPrevention.instance.getServer().getPlayer(loserName);
|
Player loser = GriefPrevention.instance.getServer().getPlayer(loserName);
|
||||||
if(winner != null && loser != null)
|
if(winner != null && loser != null)
|
||||||
{
|
{
|
||||||
//get loser's inventory, then clear it
|
//try to add any drops to the winner's inventory
|
||||||
ItemStack [] loserItems = loser.getInventory().getContents();
|
for(ItemStack stack : drops)
|
||||||
loser.getInventory().clear();
|
|
||||||
|
|
||||||
//try to add it to the winner's inventory
|
|
||||||
for(int j = 0; j < loserItems.length; j++)
|
|
||||||
{
|
{
|
||||||
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
|
//drop any remainder on the ground at his feet
|
||||||
Object [] keys = wontFitItems.keySet().toArray();
|
Object [] keys = wontFitItems.keySet().toArray();
|
||||||
|
|
|
||||||
|
|
@ -455,11 +455,8 @@ public class EntityEventHandler implements Listener
|
||||||
//if involved in a siege
|
//if involved in a siege
|
||||||
if(playerData.siegeData != null)
|
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
|
//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
|
//FEATURE: lock dropped items to player who dropped them
|
||||||
|
|
|
||||||
|
|
@ -65,13 +65,13 @@ class SiegeCheckupTask implements Runnable
|
||||||
//otherwise attacker wins if the defender runs away
|
//otherwise attacker wins if the defender runs away
|
||||||
else if(attackerRemains && !defenderRemains)
|
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
|
//or defender wins if the attacker leaves
|
||||||
else if(!attackerRemains && defenderRemains)
|
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)
|
//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)
|
//otherwise they both left and aren't close to each other, so call the attacker the winner (defender escaped, possibly after a chase)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dataStore.endSiege(this.siegeData, attacker.getName(), defender.getName(), false);
|
dataStore.endSiege(this.siegeData, attacker.getName(), defender.getName(), null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user