Extra checks for ItemContainer deleteMe method.

This commit is contained in:
MobiusDevelopment 2022-11-02 02:10:32 +00:00
parent a08a71c145
commit c95be5ef68
33 changed files with 225 additions and 106 deletions

View File

@ -601,15 +601,20 @@ public abstract class ItemContainer
*/
public void deleteMe()
{
if (getOwner() != null)
if ((this instanceof PlayerInventory) || (this instanceof PlayerWarehouse) || (getOwner() != null))
{
for (Item item : _items)
{
item.updateDatabase(true);
item.stopAllTasks();
World.getInstance().removeObject(item);
}
}
for (Item item : _items)
{
World.getInstance().removeObject(item);
}
_items.clear();
}

View File

@ -601,15 +601,20 @@ public abstract class ItemContainer
*/
public void deleteMe()
{
if (getOwner() != null)
if ((this instanceof PlayerInventory) || (this instanceof PlayerWarehouse) || (getOwner() != null))
{
for (Item item : _items)
{
item.updateDatabase(true);
item.stopAllTasks();
World.getInstance().removeObject(item);
}
}
for (Item item : _items)
{
World.getInstance().removeObject(item);
}
_items.clear();
}

View File

@ -601,15 +601,20 @@ public abstract class ItemContainer
*/
public void deleteMe()
{
if (getOwner() != null)
if ((this instanceof PlayerInventory) || (this instanceof PlayerWarehouse) || (getOwner() != null))
{
for (Item item : _items)
{
item.updateDatabase(true);
item.stopAllTasks();
World.getInstance().removeObject(item);
}
}
for (Item item : _items)
{
World.getInstance().removeObject(item);
}
_items.clear();
}

View File

@ -601,15 +601,20 @@ public abstract class ItemContainer
*/
public void deleteMe()
{
if (getOwner() != null)
if ((this instanceof PlayerInventory) || (this instanceof PlayerWarehouse) || (getOwner() != null))
{
for (Item item : _items)
{
item.updateDatabase(true);
item.stopAllTasks();
World.getInstance().removeObject(item);
}
}
for (Item item : _items)
{
World.getInstance().removeObject(item);
}
_items.clear();
}

View File

@ -601,15 +601,20 @@ public abstract class ItemContainer
*/
public void deleteMe()
{
if (getOwner() != null)
if ((this instanceof PlayerInventory) || (this instanceof PlayerWarehouse) || (getOwner() != null))
{
for (Item item : _items)
{
item.updateDatabase(true);
item.stopAllTasks();
World.getInstance().removeObject(item);
}
}
for (Item item : _items)
{
World.getInstance().removeObject(item);
}
_items.clear();
}

View File

@ -601,15 +601,20 @@ public abstract class ItemContainer
*/
public void deleteMe()
{
if (getOwner() != null)
if ((this instanceof PlayerInventory) || (this instanceof PlayerWarehouse) || (getOwner() != null))
{
for (Item item : _items)
{
item.updateDatabase(true);
item.stopAllTasks();
World.getInstance().removeObject(item);
}
}
for (Item item : _items)
{
World.getInstance().removeObject(item);
}
_items.clear();
}

View File

@ -601,15 +601,20 @@ public abstract class ItemContainer
*/
public void deleteMe()
{
if (getOwner() != null)
if ((this instanceof PlayerInventory) || (this instanceof PlayerWarehouse) || (getOwner() != null))
{
for (Item item : _items)
{
item.updateDatabase(true);
item.stopAllTasks();
World.getInstance().removeObject(item);
}
}
for (Item item : _items)
{
World.getInstance().removeObject(item);
}
_items.clear();
}

View File

@ -601,15 +601,20 @@ public abstract class ItemContainer
*/
public void deleteMe()
{
if (getOwner() != null)
if ((this instanceof PlayerInventory) || (this instanceof PlayerWarehouse) || (getOwner() != null))
{
for (Item item : _items)
{
item.updateDatabase(true);
item.stopAllTasks();
World.getInstance().removeObject(item);
}
}
for (Item item : _items)
{
World.getInstance().removeObject(item);
}
_items.clear();
}

View File

@ -601,15 +601,20 @@ public abstract class ItemContainer
*/
public void deleteMe()
{
if (getOwner() != null)
if ((this instanceof PlayerInventory) || (this instanceof PlayerWarehouse) || (getOwner() != null))
{
for (Item item : _items)
{
item.updateDatabase(true);
item.stopAllTasks();
World.getInstance().removeObject(item);
}
}
for (Item item : _items)
{
World.getInstance().removeObject(item);
}
_items.clear();
}

View File

@ -601,15 +601,20 @@ public abstract class ItemContainer
*/
public void deleteMe()
{
if (getOwner() != null)
if ((this instanceof PlayerInventory) || (this instanceof PlayerWarehouse) || (getOwner() != null))
{
for (Item item : _items)
{
item.updateDatabase(true);
item.stopAllTasks();
World.getInstance().removeObject(item);
}
}
for (Item item : _items)
{
World.getInstance().removeObject(item);
}
_items.clear();
}

View File

@ -601,15 +601,20 @@ public abstract class ItemContainer
*/
public void deleteMe()
{
if (getOwner() != null)
if ((this instanceof PlayerInventory) || (this instanceof PlayerWarehouse) || (getOwner() != null))
{
for (Item item : _items)
{
item.updateDatabase(true);
item.stopAllTasks();
World.getInstance().removeObject(item);
}
}
for (Item item : _items)
{
World.getInstance().removeObject(item);
}
_items.clear();
}

View File

@ -601,15 +601,20 @@ public abstract class ItemContainer
*/
public void deleteMe()
{
if (getOwner() != null)
if ((this instanceof PlayerInventory) || (this instanceof PlayerWarehouse) || (getOwner() != null))
{
for (Item item : _items)
{
item.updateDatabase(true);
item.stopAllTasks();
World.getInstance().removeObject(item);
}
}
for (Item item : _items)
{
World.getInstance().removeObject(item);
}
_items.clear();
}

View File

@ -111,18 +111,6 @@ public class World
_allObjects.remove(object.getObjectId());
}
/**
* Removes the objects.
* @param list the list
*/
public void removeObjects(List<WorldObject> list)
{
for (int i = 0; i < list.size(); i++)
{
_allObjects.remove(list.get(i).getObjectId());
}
}
/**
* Return the WorldObject object that belongs to an ID or null if no object found.<br>
* <br>

View File

@ -20,9 +20,7 @@ import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger;
@ -557,19 +555,20 @@ public abstract class ItemContainer
*/
public void deleteMe()
{
try
if ((this instanceof PlayerInventory) || (this instanceof PlayerWarehouse) || (getOwner() != null))
{
updateDatabase();
}
catch (Throwable t)
{
LOGGER.warning("deletedMe() " + t);
for (Item item : _items)
{
item.updateDatabase();
}
}
for (Item item : _items)
{
World.getInstance().removeObject(item);
}
final List<WorldObject> items = new ArrayList<>(_items);
_items.clear();
World.getInstance().removeObjects(items);
}
/**
@ -577,7 +576,7 @@ public abstract class ItemContainer
*/
public void updateDatabase()
{
if ((getOwner() != null) && (_items != null))
if (getOwner() != null)
{
for (Item item : _items)
{

View File

@ -111,18 +111,6 @@ public class World
_allObjects.remove(object.getObjectId());
}
/**
* Removes the objects.
* @param list the list
*/
public void removeObjects(List<WorldObject> list)
{
for (int i = 0; i < list.size(); i++)
{
_allObjects.remove(list.get(i).getObjectId());
}
}
/**
* Return the WorldObject object that belongs to an ID or null if no object found.<br>
* <br>

View File

@ -20,9 +20,7 @@ import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger;
@ -560,19 +558,20 @@ public abstract class ItemContainer
*/
public void deleteMe()
{
try
if ((this instanceof PlayerInventory) || (this instanceof PlayerWarehouse) || (getOwner() != null))
{
updateDatabase();
}
catch (Throwable t)
{
LOGGER.warning("deletedMe() " + t);
for (Item item : _items)
{
item.updateDatabase();
}
}
for (Item item : _items)
{
World.getInstance().removeObject(item);
}
final List<WorldObject> items = new ArrayList<>(_items);
_items.clear();
World.getInstance().removeObjects(items);
}
/**
@ -580,7 +579,7 @@ public abstract class ItemContainer
*/
public void updateDatabase()
{
if ((getOwner() != null) && (_items != null))
if (getOwner() != null)
{
for (Item item : _items)
{

View File

@ -534,15 +534,20 @@ public abstract class ItemContainer
*/
public void deleteMe()
{
if (getOwner() != null)
if ((this instanceof PlayerInventory) || (this instanceof PlayerWarehouse) || (getOwner() != null))
{
for (Item item : _items)
{
item.updateDatabase(true);
item.stopAllTasks();
World.getInstance().removeObject(item);
}
}
for (Item item : _items)
{
World.getInstance().removeObject(item);
}
_items.clear();
}

View File

@ -534,15 +534,20 @@ public abstract class ItemContainer
*/
public void deleteMe()
{
if (getOwner() != null)
if ((this instanceof PlayerInventory) || (this instanceof PlayerWarehouse) || (getOwner() != null))
{
for (Item item : _items)
{
item.updateDatabase(true);
item.stopAllTasks();
World.getInstance().removeObject(item);
}
}
for (Item item : _items)
{
World.getInstance().removeObject(item);
}
_items.clear();
}

View File

@ -534,15 +534,20 @@ public abstract class ItemContainer
*/
public void deleteMe()
{
if (getOwner() != null)
if ((this instanceof PlayerInventory) || (this instanceof PlayerWarehouse) || (getOwner() != null))
{
for (Item item : _items)
{
item.updateDatabase(true);
item.stopAllTasks();
World.getInstance().removeObject(item);
}
}
for (Item item : _items)
{
World.getInstance().removeObject(item);
}
_items.clear();
}

View File

@ -601,15 +601,20 @@ public abstract class ItemContainer
*/
public void deleteMe()
{
if (getOwner() != null)
if ((this instanceof PlayerInventory) || (this instanceof PlayerWarehouse) || (getOwner() != null))
{
for (Item item : _items)
{
item.updateDatabase(true);
item.stopAllTasks();
World.getInstance().removeObject(item);
}
}
for (Item item : _items)
{
World.getInstance().removeObject(item);
}
_items.clear();
}

View File

@ -601,15 +601,20 @@ public abstract class ItemContainer
*/
public void deleteMe()
{
if (getOwner() != null)
if ((this instanceof PlayerInventory) || (this instanceof PlayerWarehouse) || (getOwner() != null))
{
for (Item item : _items)
{
item.updateDatabase(true);
item.stopAllTasks();
World.getInstance().removeObject(item);
}
}
for (Item item : _items)
{
World.getInstance().removeObject(item);
}
_items.clear();
}

View File

@ -601,15 +601,20 @@ public abstract class ItemContainer
*/
public void deleteMe()
{
if (getOwner() != null)
if ((this instanceof PlayerInventory) || (this instanceof PlayerWarehouse) || (getOwner() != null))
{
for (Item item : _items)
{
item.updateDatabase(true);
item.stopAllTasks();
World.getInstance().removeObject(item);
}
}
for (Item item : _items)
{
World.getInstance().removeObject(item);
}
_items.clear();
}

View File

@ -601,15 +601,20 @@ public abstract class ItemContainer
*/
public void deleteMe()
{
if (getOwner() != null)
if ((this instanceof PlayerInventory) || (this instanceof PlayerWarehouse) || (getOwner() != null))
{
for (Item item : _items)
{
item.updateDatabase(true);
item.stopAllTasks();
World.getInstance().removeObject(item);
}
}
for (Item item : _items)
{
World.getInstance().removeObject(item);
}
_items.clear();
}

View File

@ -601,15 +601,20 @@ public abstract class ItemContainer
*/
public void deleteMe()
{
if (getOwner() != null)
if ((this instanceof PlayerInventory) || (this instanceof PlayerWarehouse) || (getOwner() != null))
{
for (Item item : _items)
{
item.updateDatabase(true);
item.stopAllTasks();
World.getInstance().removeObject(item);
}
}
for (Item item : _items)
{
World.getInstance().removeObject(item);
}
_items.clear();
}

View File

@ -601,15 +601,20 @@ public abstract class ItemContainer
*/
public void deleteMe()
{
if (getOwner() != null)
if ((this instanceof PlayerInventory) || (this instanceof PlayerWarehouse) || (getOwner() != null))
{
for (Item item : _items)
{
item.updateDatabase(true);
item.stopAllTasks();
World.getInstance().removeObject(item);
}
}
for (Item item : _items)
{
World.getInstance().removeObject(item);
}
_items.clear();
}

View File

@ -601,15 +601,20 @@ public abstract class ItemContainer
*/
public void deleteMe()
{
if (getOwner() != null)
if ((this instanceof PlayerInventory) || (this instanceof PlayerWarehouse) || (getOwner() != null))
{
for (Item item : _items)
{
item.updateDatabase(true);
item.stopAllTasks();
World.getInstance().removeObject(item);
}
}
for (Item item : _items)
{
World.getInstance().removeObject(item);
}
_items.clear();
}

View File

@ -601,15 +601,20 @@ public abstract class ItemContainer
*/
public void deleteMe()
{
if (getOwner() != null)
if ((this instanceof PlayerInventory) || (this instanceof PlayerWarehouse) || (getOwner() != null))
{
for (Item item : _items)
{
item.updateDatabase(true);
item.stopAllTasks();
World.getInstance().removeObject(item);
}
}
for (Item item : _items)
{
World.getInstance().removeObject(item);
}
_items.clear();
}

View File

@ -601,15 +601,20 @@ public abstract class ItemContainer
*/
public void deleteMe()
{
if (getOwner() != null)
if ((this instanceof PlayerInventory) || (this instanceof PlayerWarehouse) || (getOwner() != null))
{
for (Item item : _items)
{
item.updateDatabase(true);
item.stopAllTasks();
World.getInstance().removeObject(item);
}
}
for (Item item : _items)
{
World.getInstance().removeObject(item);
}
_items.clear();
}

View File

@ -601,15 +601,20 @@ public abstract class ItemContainer
*/
public void deleteMe()
{
if (getOwner() != null)
if ((this instanceof PlayerInventory) || (this instanceof PlayerWarehouse) || (getOwner() != null))
{
for (Item item : _items)
{
item.updateDatabase(true);
item.stopAllTasks();
World.getInstance().removeObject(item);
}
}
for (Item item : _items)
{
World.getInstance().removeObject(item);
}
_items.clear();
}

View File

@ -601,15 +601,20 @@ public abstract class ItemContainer
*/
public void deleteMe()
{
if (getOwner() != null)
if ((this instanceof PlayerInventory) || (this instanceof PlayerWarehouse) || (getOwner() != null))
{
for (Item item : _items)
{
item.updateDatabase(true);
item.stopAllTasks();
World.getInstance().removeObject(item);
}
}
for (Item item : _items)
{
World.getInstance().removeObject(item);
}
_items.clear();
}

View File

@ -601,15 +601,20 @@ public abstract class ItemContainer
*/
public void deleteMe()
{
if (getOwner() != null)
if ((this instanceof PlayerInventory) || (this instanceof PlayerWarehouse) || (getOwner() != null))
{
for (Item item : _items)
{
item.updateDatabase(true);
item.stopAllTasks();
World.getInstance().removeObject(item);
}
}
for (Item item : _items)
{
World.getInstance().removeObject(item);
}
_items.clear();
}

View File

@ -601,15 +601,20 @@ public abstract class ItemContainer
*/
public void deleteMe()
{
if (getOwner() != null)
if ((this instanceof PlayerInventory) || (this instanceof PlayerWarehouse) || (getOwner() != null))
{
for (Item item : _items)
{
item.updateDatabase(true);
item.stopAllTasks();
World.getInstance().removeObject(item);
}
}
for (Item item : _items)
{
World.getInstance().removeObject(item);
}
_items.clear();
}

View File

@ -601,15 +601,20 @@ public abstract class ItemContainer
*/
public void deleteMe()
{
if (getOwner() != null)
if ((this instanceof PlayerInventory) || (this instanceof PlayerWarehouse) || (getOwner() != null))
{
for (Item item : _items)
{
item.updateDatabase(true);
item.stopAllTasks();
World.getInstance().removeObject(item);
}
}
for (Item item : _items)
{
World.getInstance().removeObject(item);
}
_items.clear();
}