Search in sources :

Example 1 with GuildRenameEvent

use of net.dzikoysk.funnyguilds.event.guild.GuildRenameEvent 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)

Aggregations

Guild (net.dzikoysk.funnyguilds.basic.Guild)1 Region (net.dzikoysk.funnyguilds.basic.Region)1 User (net.dzikoysk.funnyguilds.basic.User)1 MessagesConfig (net.dzikoysk.funnyguilds.data.configs.MessagesConfig)1 PluginConfig (net.dzikoysk.funnyguilds.data.configs.PluginConfig)1 DatabaseGuild (net.dzikoysk.funnyguilds.data.database.DatabaseGuild)1 DatabaseRegion (net.dzikoysk.funnyguilds.data.database.DatabaseRegion)1 GuildRenameEvent (net.dzikoysk.funnyguilds.event.guild.GuildRenameEvent)1 Player (org.bukkit.entity.Player)1