Skip to content

Commit

Permalink
Delete / remove from MFDs upon /dxl delete; resolves #768
Browse files Browse the repository at this point in the history
  • Loading branch information
Sataniel98 committed Oct 29, 2020
1 parent 0e3189c commit a603441
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@
import de.erethon.commons.chat.MessageUtil;
import de.erethon.commons.misc.FileUtil;
import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.api.dungeon.Dungeon;
import de.erethon.dungeonsxl.api.world.ResourceWorld;
import de.erethon.dungeonsxl.config.DMessage;
import de.erethon.dungeonsxl.dungeon.DDungeon;
import de.erethon.dungeonsxl.dungeon.DungeonConfig;
import de.erethon.dungeonsxl.player.DPermission;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.command.CommandSender;
Expand Down Expand Up @@ -81,6 +86,27 @@ public void onExecute(String[] args, CommandSender sender) {
}
}

List<Dungeon> toRemove = new ArrayList<>();
for (Dungeon dungeon : plugin.getDungeonRegistry()) {
if (dungeon.getStartFloor().equals(resource)) {
toRemove.add(dungeon);
if (dungeon.isMultiFloor()) {
((DDungeon) dungeon).getConfig().getFile().delete();
}
} else if (dungeon.isMultiFloor() && dungeon.getEndFloor().equals(resource)) {
toRemove.add(dungeon);
((DDungeon) dungeon).getConfig().getFile().delete();
} else if (dungeon.isMultiFloor() && dungeon.getFloors().contains(resource)) {
dungeon.getFloors().remove(resource);
DungeonConfig config = ((DDungeon) dungeon).getConfig();
List<String> floors = config.getConfig().getStringList("floors");
floors.remove(resource.getName());
config.getConfig().set("floors", floors);
config.save();
}
}
toRemove.forEach(plugin.getDungeonRegistry()::remove);

MessageUtil.sendMessage(sender, DMessage.CMD_DELETE_SUCCESS.getMessage(args[1]));
}

Expand Down

0 comments on commit a603441

Please sign in to comment.