Search in sources :

Example 1 with DeletedRegionEvent

use of me.wiefferink.areashop.events.notify.DeletedRegionEvent in project AreaShop by NLthijs48.

the class FileManager method removeBuy.

/**
 * Remove a buy from the list.
 * @param buy           The BuyRegion to remove
 * @param giveMoneyBack true if money should be given back to the player, otherwise false
 * @return true if the buy has been removed, false otherwise
 */
public boolean removeBuy(BuyRegion buy, boolean giveMoneyBack) {
    boolean result = false;
    if (buy != null) {
        buy.setDeleted();
        if (buy.isSold()) {
            buy.sell(giveMoneyBack, null);
        }
        // Handle schematics and run commands
        buy.handleSchematicEvent(RegionEvent.DELETED);
        buy.runEventCommands(RegionEvent.DELETED, true);
        // Delete the sign and the variable
        if (buy.getWorld() != null) {
            for (Location sign : buy.getSignsFeature().getSignLocations()) {
                sign.getBlock().setType(Material.AIR);
            }
        }
        regions.remove(buy.getLowerCaseName());
        buy.resetRegionFlags();
        // Removing from groups
        for (RegionGroup group : getGroups()) {
            group.removeMember(buy);
        }
        // Deleting the file
        File file = new File(plugin.getDataFolder() + File.separator + AreaShop.regionsFolder + File.separator + buy.getLowerCaseName() + ".yml");
        boolean deleted;
        if (file.exists()) {
            try {
                deleted = file.delete();
            } catch (Exception e) {
                deleted = false;
            }
            if (!deleted) {
                AreaShop.warn("File could not be deleted: " + file.toString());
            }
        }
        result = true;
        // Broadcast event
        Bukkit.getPluginManager().callEvent(new DeletedRegionEvent(buy));
        // Run commands
        buy.runEventCommands(RegionEvent.DELETED, false);
    }
    return result;
}
Also used : DeletedRegionEvent(me.wiefferink.areashop.events.notify.DeletedRegionEvent) File(java.io.File) RegionGroup(me.wiefferink.areashop.regions.RegionGroup) IOException(java.io.IOException) Location(org.bukkit.Location)

Example 2 with DeletedRegionEvent

use of me.wiefferink.areashop.events.notify.DeletedRegionEvent in project AreaShop by NLthijs48.

the class FileManager method removeRent.

/**
 * Remove a rent from the list.
 * @param rent          The region to remove
 * @param giveMoneyBack use true to give money back to the player if someone is currently renting this region, otherwise false
 * @return true if the rent has been removed, false otherwise
 */
public boolean removeRent(RentRegion rent, boolean giveMoneyBack) {
    boolean result = false;
    if (rent != null) {
        rent.setDeleted();
        if (rent.isRented()) {
            rent.unRent(giveMoneyBack, null);
        }
        // Handle schematics and run commands
        rent.handleSchematicEvent(RegionEvent.DELETED);
        rent.runEventCommands(RegionEvent.DELETED, true);
        // Delete the signs and the variable
        if (rent.getWorld() != null) {
            for (Location sign : rent.getSignsFeature().getSignLocations()) {
                sign.getBlock().setType(Material.AIR);
                AreaShop.debug("Removed sign at: " + sign.toString());
            }
        }
        RegionGroup[] groups = getGroups().toArray(new RegionGroup[getGroups().size()]);
        for (RegionGroup group : groups) {
            group.removeMember(rent);
        }
        rent.resetRegionFlags();
        regions.remove(rent.getLowerCaseName());
        File file = new File(plugin.getDataFolder() + File.separator + AreaShop.regionsFolder + File.separator + rent.getLowerCaseName() + ".yml");
        boolean deleted;
        if (file.exists()) {
            try {
                deleted = file.delete();
            } catch (Exception e) {
                deleted = false;
            }
            if (!deleted) {
                AreaShop.warn("File could not be deleted: " + file.toString());
            }
        }
        result = true;
        // Broadcast event
        Bukkit.getPluginManager().callEvent(new DeletedRegionEvent(rent));
        // Run commands
        rent.runEventCommands(RegionEvent.DELETED, false);
    }
    return result;
}
Also used : DeletedRegionEvent(me.wiefferink.areashop.events.notify.DeletedRegionEvent) File(java.io.File) RegionGroup(me.wiefferink.areashop.regions.RegionGroup) IOException(java.io.IOException) Location(org.bukkit.Location)

Aggregations

File (java.io.File)2 IOException (java.io.IOException)2 DeletedRegionEvent (me.wiefferink.areashop.events.notify.DeletedRegionEvent)2 RegionGroup (me.wiefferink.areashop.regions.RegionGroup)2 Location (org.bukkit.Location)2