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()));
}
Aggregations