use of net.dzikoysk.funnyguilds.event.guild.GuildEnlargeEvent in project FunnyGuilds by FunnyGuilds.
the class ExcEnlarge method execute.
@Override
public void execute(CommandSender sender, String[] args) {
MessagesConfig messages = Messages.getInstance();
PluginConfig config = Settings.getConfig();
Player player = (Player) sender;
User user = User.get(player);
if (!config.regionsEnabled) {
player.sendMessage(messages.regionsDisabled);
return;
}
if (!config.enlargeEnable) {
return;
}
if (!user.hasGuild()) {
player.sendMessage(messages.generalHasNoGuild);
return;
}
if (!user.isOwner() && !user.isDeputy()) {
player.sendMessage(messages.generalIsNotOwner);
return;
}
Region region = Region.get(user.getGuild().getRegion());
int enlarge = region.getEnlarge();
if (enlarge > config.enlargeItems.size() - 1) {
player.sendMessage(messages.enlargeMaxSize);
return;
}
ItemStack need = config.enlargeItems.get(enlarge);
if (!player.getInventory().containsAtLeast(need, need.getAmount())) {
StringBuilder messageBuilder = new StringBuilder();
messageBuilder.append(need.getAmount());
messageBuilder.append(" ");
messageBuilder.append(need.getType().toString().toLowerCase());
player.sendMessage(messages.enlargeItem.replace("{ITEM}", messageBuilder.toString()));
return;
}
if (RegionUtils.isNear(region.getCenter())) {
player.sendMessage(messages.enlargeIsNear);
return;
}
if (!SimpleEventHandler.handle(new GuildEnlargeEvent(EventCause.USER, user, user.getGuild()))) {
return;
}
player.getInventory().removeItem(need);
region.setEnlarge(++enlarge);
region.setSize(region.getSize() + config.enlargeSize);
String enlargeDoneMessage = messages.enlargeDone.replace("{SIZE}", Integer.toString(region.getSize())).replace("{LEVEL}", Integer.toString(region.getEnlarge()));
user.getGuild().broadcast(enlargeDoneMessage);
}
Aggregations