Search in sources :

Example 1 with GuildMoveEvent

use of net.dzikoysk.funnyguilds.event.guild.GuildMoveEvent in project FunnyGuilds by FunnyGuilds.

the class AxcMove method execute.

@SuppressWarnings("deprecation")
@Override
public void execute(CommandSender sender, String[] args) {
    MessagesConfig messages = Messages.getInstance();
    PluginConfig config = Settings.getConfig();
    Player player = (Player) sender;
    if (!config.regionsEnabled) {
        player.sendMessage(messages.regionsDisabled);
        return;
    }
    if (args.length < 1) {
        player.sendMessage(messages.generalNoTagGiven);
        return;
    }
    Guild guild = GuildUtils.getByTag(args[0]);
    if (guild == null) {
        player.sendMessage(messages.generalNoGuildFound);
        return;
    }
    Location location = player.getLocation();
    if (config.createCenterY != 0) {
        location.setY(config.createCenterY);
    }
    int d = config.regionSize + config.createDistance;
    if (config.enlargeItems != null) {
        d = config.enlargeItems.size() * config.enlargeSize + d;
    }
    if (d > player.getWorld().getSpawnLocation().distance(location)) {
        player.sendMessage(messages.createSpawn.replace("{DISTANCE}", Integer.toString(d)));
        return;
    }
    if (RegionUtils.isNear(location)) {
        player.sendMessage(messages.createIsNear);
        return;
    }
    User admin = User.get(player);
    if (!SimpleEventHandler.handle(new GuildMoveEvent(EventCause.ADMIN, admin, guild, location))) {
        return;
    }
    Region region = RegionUtils.get(guild.getRegion());
    if (region == null) {
        region = new Region(guild, location, config.regionSize);
    } else {
        if (config.createEntityType != null) {
            EntityUtil.despawn(guild);
        } else if (config.createMaterialData != null && config.createMaterialData.getItemType() != Material.AIR) {
            Block block = region.getCenter().getBlock().getRelative(BlockFace.DOWN);
            Bukkit.getScheduler().runTask(FunnyGuilds.getInstance(), () -> {
                if (block.getLocation().getBlockY() > 1) {
                    block.setType(Material.AIR);
                }
            });
        }
        region.setCenter(location);
    }
    if (config.createCenterSphere) {
        List<Location> sphere = SpaceUtils.sphere(location, 3, 3, false, true, 0);
        for (Location l : sphere) {
            if (l.getBlock().getType() != Material.BEDROCK) {
                l.getBlock().setType(Material.AIR);
            }
        }
    }
    if (config.createMaterialData != null && config.createMaterialData.getItemType() != Material.AIR) {
        Block heart = location.getBlock().getRelative(BlockFace.DOWN);
        heart.setType(config.createMaterialData.getItemType());
        heart.setData(config.createMaterialData.getData());
    } else if (config.createEntityType != null) {
        EntityUtil.spawn(guild);
    }
    player.sendMessage(messages.adminGuildRelocated.replace("{GUILD}", guild.getName()).replace("{REGION}", region.getName()));
}
Also used : PluginConfig(net.dzikoysk.funnyguilds.data.configs.PluginConfig) Player(org.bukkit.entity.Player) User(net.dzikoysk.funnyguilds.basic.User) GuildMoveEvent(net.dzikoysk.funnyguilds.event.guild.GuildMoveEvent) Region(net.dzikoysk.funnyguilds.basic.Region) Block(org.bukkit.block.Block) MessagesConfig(net.dzikoysk.funnyguilds.data.configs.MessagesConfig) Guild(net.dzikoysk.funnyguilds.basic.Guild) Location(org.bukkit.Location)

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 GuildMoveEvent (net.dzikoysk.funnyguilds.event.guild.GuildMoveEvent)1 Location (org.bukkit.Location)1 Block (org.bukkit.block.Block)1 Player (org.bukkit.entity.Player)1