mirror of
https://github.com/EpicEricEE/ShopChest.git
synced 2024-11-08 11:50:14 +01:00
Fix removing double chest shops without chests
When AreaShop integration was enabled and a region with double chest shops was reset and sold/unrented, those shops woudn't be removed. A method to remove a shop by its ID was introduced as a fix.
This commit is contained in:
parent
9c7170e109
commit
6d57267492
@ -57,7 +57,7 @@ public class AreaShopListener implements Listener {
|
||||
|
||||
for (IWrappedRegion r : WorldGuardWrapper.getInstance().getRegions(shop.getLocation())) {
|
||||
if (generalRegion.getLowerCaseName().equals(r.getId())) {
|
||||
plugin.getShopUtils().removeShop(shop, true);
|
||||
plugin.getShopUtils().removeShopById(shop.getID(), true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ShopUtils {
|
||||
|
||||
@ -114,10 +115,11 @@ public class ShopUtils {
|
||||
addShop(shop, addToDatabase, null);
|
||||
}
|
||||
|
||||
/** Remove a shop
|
||||
/** Remove a shop. May not work properly if double chest doesn't exist!
|
||||
* @param shop Shop to remove
|
||||
* @param removeFromDatabase Whether the shop should also be removed from the database
|
||||
* @param callback Callback that - if succeeded - returns null
|
||||
* @see ShopUtils#removeShopById(int, boolean, Callback)
|
||||
*/
|
||||
public void removeShop(Shop shop, boolean removeFromDatabase, Callback<Void> callback) {
|
||||
plugin.debug("Removing shop (#" + shop.getID() + ")");
|
||||
@ -146,14 +148,57 @@ public class ShopUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a shop
|
||||
* Remove a shop. May not work properly if double chest doesn't exist!
|
||||
* @param shop Shop to remove
|
||||
* @param removeFromDatabase Whether the shop should also be removed from the database
|
||||
* @see ShopUtils#removeShopById(int, boolean)
|
||||
*/
|
||||
public void removeShop(Shop shop, boolean removeFromDatabase) {
|
||||
removeShop(shop, removeFromDatabase, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a shop by its ID
|
||||
* @param shopId ID of the shop to remove
|
||||
* @param removeFromDatabase Whether the shop should also be removed from the database
|
||||
* @param callback Callback that - if succeeded - returns null
|
||||
*/
|
||||
public void removeShopById(int shopId, boolean removeFromDatabase, Callback<Void> callback) {
|
||||
Map<Location, Shop> toRemove = shopLocation.entrySet().stream()
|
||||
.filter(e -> e.getValue().getID() == shopId)
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||
|
||||
plugin.debug(String.format("Removing %d shop(s) with ID %d", toRemove.size(), shopId));
|
||||
|
||||
if (toRemove.isEmpty()) {
|
||||
if (callback != null) callback.callSyncResult(null);
|
||||
return;
|
||||
}
|
||||
|
||||
toRemove.forEach((loc, shop) -> {
|
||||
shopLocation.remove(loc);
|
||||
|
||||
shop.removeItem();
|
||||
shop.removeHologram();
|
||||
});
|
||||
|
||||
// Database#removeShop removes shop by ID so this only needs to be called once
|
||||
if (removeFromDatabase) {
|
||||
plugin.getShopDatabase().removeShop(toRemove.values().iterator().next(), callback);
|
||||
} else {
|
||||
if (callback != null) callback.callSyncResult(null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a shop by its ID
|
||||
* @param shopId ID of the shop to remove
|
||||
* @param removeFromDatabase Whether the shop should also be removed from the database
|
||||
*/
|
||||
public void removeShopById(int shopId, boolean removeFromDatabase) {
|
||||
removeShopById(shopId, removeFromDatabase, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the shop limits of a player
|
||||
* @param p Player, whose shop limits should be returned
|
||||
|
Loading…
Reference in New Issue
Block a user