@ -7,32 +7,57 @@ import org.bukkit.Chunk;
import org.bukkit.Location ;
import org.bukkit.Location ;
import org.bukkit.entity.Item ;
import org.bukkit.entity.Item ;
import org.bukkit.entity.Player ;
import org.bukkit.entity.Player ;
import org.bukkit.inventory.Inventory ;
import org.bukkit.inventory.ItemStack ;
import org.bukkit.inventory.ItemStack ;
import sig.plugin.TwosideKeeper.HelperStructures.Utils.InventoryUtils ;
public class DropDeathItems implements Runnable {
public class DropDeathItems implements Runnable {
Player p = null ;
Player p = null ;
Location deathloc = null ;
Location deathloc = null ;
List < ItemStack > contents ;
List < ItemStack > contents ;
Inventory inv_contents ;
DropDeathItems ( Player p , List < ItemStack > contents , Location deathloc ) {
DropDeathItems ( Player p , List < ItemStack > contents , Location deathloc ) {
this . p = p ;
this . p = p ;
this . deathloc = deathloc ;
this . deathloc = deathloc ;
this . contents = contents ;
this . contents = contents ;
this . inv_contents = Bukkit . createInventory ( p , 36 ) ;
for ( ItemStack it : contents ) {
if ( it ! = null ) {
inv_contents . addItem ( it ) ;
}
}
}
}
@Override
@Override
public void run ( ) {
public void run ( ) {
if ( ! AttemptToDropItems ( p , deathloc ) ) {
if ( ! AttemptToDropItems ( p , deathloc ) ) {
Bukkit . getScheduler ( ) . scheduleSyncDelayedTask ( TwosideKeeper . plugin , new DropDeathItems ( p , contents , deathloc ) , 1 ) ; //Keep trying until the chunk is loaded!!!
Bukkit . getScheduler ( ) . scheduleSyncDelayedTask ( TwosideKeeper . plugin , new DropDeathItems ( p , contents , deathloc ) , 1 ) ; //Keep trying until the chunk is loaded!!!
TwosideKeeper . temporary_chunks . clear ( ) ;
}
}
}
}
public boolean AttemptToDropItems ( Player p , Location deathloc ) {
public boolean AttemptToDropItems ( Player p , Location deathloc ) {
deathloc . getWorld ( ) . loadChunk ( deathloc . getChunk ( ) ) ;
TwosideKeeper . temporary_chunks . add ( deathloc . getChunk ( ) ) ;
deathloc . getChunk ( ) . load ( ) ;
if ( deathloc . getChunk ( ) . isLoaded ( ) ) {
if ( deathloc . getChunk ( ) . isLoaded ( ) ) {
TwosideKeeper . log ( "Respawn and Dropping..." , 2 ) ;
TwosideKeeper . log ( "Respawn and Dropping..." , 2 ) ;
while ( contents . size ( ) > 0 ) {
while ( ! InventoryUtils . hasEmptyInventory ( inv_contents ) ) {
if ( deathloc . getChunk ( ) . isLoaded ( ) ) {
Item it = deathloc . getWorld ( ) . dropItemNaturally ( deathloc , InventoryUtils . getFirstItemThatIsNotEmpty ( inv_contents ) ) ;
if ( it ! = null ) {
inv_contents . removeItem ( it . getItemStack ( ) ) ;
TwosideKeeper . log ( "Dropping " + it . getItemStack ( ) . toString ( ) + " at Death location " + deathloc , 2 ) ;
} else {
return false ;
}
} else {
return false ;
}
}
/ * while ( contents . size ( ) > 0 ) {
if ( deathloc . getChunk ( ) . isLoaded ( ) ) {
if ( deathloc . getChunk ( ) . isLoaded ( ) ) {
Item it = null ;
Item it = null ;
do {
do {
@ -41,11 +66,12 @@ public class DropDeathItems implements Runnable{
TwosideKeeper . temporary_chunks . add ( deathloc . getChunk ( ) ) ; } while ( it = = null | | ! it . isValid ( ) ) ;
TwosideKeeper . temporary_chunks . add ( deathloc . getChunk ( ) ) ; } while ( it = = null | | ! it . isValid ( ) ) ;
it . setInvulnerable ( true ) ;
it . setInvulnerable ( true ) ;
TwosideKeeper . log ( "Dropping " + contents . get ( 0 ) . toString ( ) + " at Death location " + deathloc , 2 ) ;
TwosideKeeper . log ( "Dropping " + contents . get ( 0 ) . toString ( ) + " at Death location " + deathloc , 2 ) ;
contents . remove ( 0 ) ;
//contents.remove(0);
} else {
} else {
deathloc . getWorld ( ) . loadChunk ( deathloc . getChunk ( ) ) ;
deathloc . getWorld ( ) . loadChunk ( deathloc . getChunk ( ) ) ;
}
}
}
} * /
for ( Chunk c : TwosideKeeper . temporary_chunks ) {
for ( Chunk c : TwosideKeeper . temporary_chunks ) {
c . unload ( true ) ;
c . unload ( true ) ;
}
}