Search in sources :

Example 1 with DatabaseGuild

use of net.dzikoysk.funnyguilds.data.database.DatabaseGuild in project FunnyGuilds by FunnyGuilds.

the class GuildUtils method deleteGuild.

public static void deleteGuild(final Guild guild) {
    PluginConfig config = Settings.getConfig();
    if (guild == null) {
        return;
    }
    Manager.getInstance().stop();
    if (config.regionsEnabled) {
        Region region = RegionUtils.get(guild.getRegion());
        if (region != null) {
            if (config.createEntityType != null) {
                EntityUtil.despawn(guild);
            } else if (config.createMaterialData != null && config.createMaterialData.getItemType() != Material.AIR) {
                Bukkit.getScheduler().runTask(FunnyGuilds.getInstance(), () -> {
                    Block block = region.getCenter().getBlock().getRelative(BlockFace.DOWN);
                    if (block.getLocation().getBlockY() > 1) {
                        block.setType(Material.AIR);
                    }
                });
            }
        }
        for (String name : guild.getRegions()) {
            Region r = RegionUtils.get(name);
            if (r != null) {
                RegionUtils.delete(r);
            }
        }
        RegionUtils.delete(Region.get(guild.getRegion()));
    }
    // IndependentThread.action(ActionType.PREFIX_GLOBAL_REMOVE_GUILD, guild);
    ConcurrencyManager concurrencyManager = FunnyGuilds.getInstance().getConcurrencyManager();
    concurrencyManager.postRequests(new PrefixGlobalRemoveGuildRequest(guild));
    UserUtils.removeGuild(guild.getMembers());
    RankManager.getInstance().remove(guild);
    for (Guild allay : guild.getAllies()) {
        allay.removeAlly(guild);
    }
    for (Guild enemy : guild.getEnemies()) {
        enemy.removeEnemy(guild);
    }
    if (Settings.getConfig().dataType.flat) {
        Flat.getGuildFile(guild).delete();
    }
    if (Settings.getConfig().dataType.mysql) {
        new DatabaseGuild(guild).delete();
    }
    guild.delete();
    Manager.getInstance().start();
}
Also used : PluginConfig(net.dzikoysk.funnyguilds.data.configs.PluginConfig) ConcurrencyManager(net.dzikoysk.funnyguilds.concurrency.ConcurrencyManager) DatabaseGuild(net.dzikoysk.funnyguilds.data.database.DatabaseGuild) PrefixGlobalRemoveGuildRequest(net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalRemoveGuildRequest) Region(net.dzikoysk.funnyguilds.basic.Region) Block(org.bukkit.block.Block) DatabaseGuild(net.dzikoysk.funnyguilds.data.database.DatabaseGuild) Guild(net.dzikoysk.funnyguilds.basic.Guild)

Example 2 with DatabaseGuild

use of net.dzikoysk.funnyguilds.data.database.DatabaseGuild in project FunnyGuilds by FunnyGuilds.

the class AxcName method execute.

@Override
public void execute(CommandSender sender, String[] args) {
    MessagesConfig messages = Messages.getInstance();
    PluginConfig config = Settings.getConfig();
    if (args.length < 1) {
        sender.sendMessage(messages.generalNoTagGiven);
        return;
    } else if (args.length < 2) {
        sender.sendMessage(messages.adminNoNewNameGiven);
        return;
    }
    Guild guild = GuildUtils.getByTag(args[0]);
    if (guild == null) {
        sender.sendMessage(messages.generalNoGuildFound);
        return;
    }
    if (GuildUtils.nameExists(args[1])) {
        sender.sendMessage(messages.createNameExists);
        return;
    }
    User admin = (sender instanceof Player) ? User.get(sender.getName()) : null;
    if (!SimpleEventHandler.handle(new GuildRenameEvent(admin == null ? EventCause.CONSOLE : EventCause.ADMIN, admin, guild, args[1]))) {
        return;
    }
    Manager.getInstance().stop();
    PluginConfig.DataType dataType = Settings.getConfig().dataType;
    if (config.regionsEnabled) {
        Region region = RegionUtils.get(guild.getRegion());
        if (dataType.flat) {
            Flat.getRegionFile(region).delete();
        }
        if (dataType.mysql) {
            new DatabaseRegion(region).delete();
        }
        region.setName(args[1]);
    }
    if (dataType.flat) {
        Flat.getGuildFile(guild).delete();
    }
    if (dataType.mysql) {
        new DatabaseGuild(guild).delete();
    }
    guild.setName(args[1]);
    Manager.getInstance().start();
    sender.sendMessage(messages.adminNameChanged.replace("{GUILD}", guild.getName()));
}
Also used : PluginConfig(net.dzikoysk.funnyguilds.data.configs.PluginConfig) Player(org.bukkit.entity.Player) User(net.dzikoysk.funnyguilds.basic.User) DatabaseGuild(net.dzikoysk.funnyguilds.data.database.DatabaseGuild) DatabaseRegion(net.dzikoysk.funnyguilds.data.database.DatabaseRegion) DatabaseRegion(net.dzikoysk.funnyguilds.data.database.DatabaseRegion) Region(net.dzikoysk.funnyguilds.basic.Region) MessagesConfig(net.dzikoysk.funnyguilds.data.configs.MessagesConfig) DatabaseGuild(net.dzikoysk.funnyguilds.data.database.DatabaseGuild) Guild(net.dzikoysk.funnyguilds.basic.Guild) GuildRenameEvent(net.dzikoysk.funnyguilds.event.guild.GuildRenameEvent)

Example 3 with DatabaseGuild

use of net.dzikoysk.funnyguilds.data.database.DatabaseGuild in project FunnyGuilds by FunnyGuilds.

the class DatabaseUpdateGuildPointsRequest method execute.

@Override
public void execute() throws Exception {
    DatabaseGuild databaseGuild = new DatabaseGuild(guild);
    databaseGuild.updatePoints();
}
Also used : DatabaseGuild(net.dzikoysk.funnyguilds.data.database.DatabaseGuild)

Aggregations

DatabaseGuild (net.dzikoysk.funnyguilds.data.database.DatabaseGuild)3 Guild (net.dzikoysk.funnyguilds.basic.Guild)2 Region (net.dzikoysk.funnyguilds.basic.Region)2 PluginConfig (net.dzikoysk.funnyguilds.data.configs.PluginConfig)2 User (net.dzikoysk.funnyguilds.basic.User)1 ConcurrencyManager (net.dzikoysk.funnyguilds.concurrency.ConcurrencyManager)1 PrefixGlobalRemoveGuildRequest (net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalRemoveGuildRequest)1 MessagesConfig (net.dzikoysk.funnyguilds.data.configs.MessagesConfig)1 DatabaseRegion (net.dzikoysk.funnyguilds.data.database.DatabaseRegion)1 GuildRenameEvent (net.dzikoysk.funnyguilds.event.guild.GuildRenameEvent)1 Block (org.bukkit.block.Block)1 Player (org.bukkit.entity.Player)1