use of net.dzikoysk.funnyguilds.event.guild.GuildExtendValidityEvent in project FunnyGuilds by FunnyGuilds.
the class ExcValidity method execute.
@Override
public void execute(CommandSender sender, String[] args) {
PluginConfig config = Settings.getConfig();
MessagesConfig messages = Messages.getInstance();
Player player = (Player) sender;
User user = User.get(player);
Guild guild = user.getGuild();
if (!user.hasGuild()) {
player.sendMessage(messages.generalHasNoGuild);
return;
}
if (!user.isOwner() && !user.isDeputy()) {
player.sendMessage(messages.generalIsNotOwner);
return;
}
if (config.validityWhen != 0) {
long c = guild.getValidity();
long d = c - System.currentTimeMillis();
if (d > config.validityWhen) {
long when = d - config.validityWhen;
player.sendMessage(messages.validityWhen.replace("{TIME}", TimeUtils.getDurationBreakdown(when)));
return;
}
}
List<ItemStack> requiredItems = config.validityItems;
for (ItemStack requiredItem : requiredItems) {
if (player.getInventory().containsAtLeast(requiredItem, requiredItem.getAmount())) {
continue;
}
String msg = ItemUtils.translatePlaceholder(messages.validityItems, requiredItems, requiredItem);
player.sendMessage(msg);
return;
}
if (!SimpleEventHandler.handle(new GuildExtendValidityEvent(EventCause.USER, user, guild, config.validityTime))) {
return;
}
player.getInventory().removeItem(ItemUtils.toArray(requiredItems));
long c = guild.getValidity();
if (c == 0) {
c = System.currentTimeMillis();
}
c += config.validityTime;
guild.setValidity(c);
player.sendMessage(messages.validityDone.replace("{DATE}", config.dateFormat.format(new Date(c))));
}
use of net.dzikoysk.funnyguilds.event.guild.GuildExtendValidityEvent in project FunnyGuilds by FunnyGuilds.
the class AxcValidity 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.adminNoValidityTimeGiven);
return;
}
Guild guild = GuildUtils.getByTag(args[0]);
if (guild == null) {
sender.sendMessage(messages.generalNoGuildFound);
return;
}
if (guild.isBanned()) {
sender.sendMessage(messages.adminGuildBanned);
return;
}
long time = Parser.parseTime(args[1]);
if (time < 1) {
sender.sendMessage(messages.adminTimeError);
return;
}
User admin = (sender instanceof Player) ? User.get(sender.getName()) : null;
if (!SimpleEventHandler.handle(new GuildExtendValidityEvent(admin == null ? EventCause.CONSOLE : EventCause.ADMIN, admin, guild, time))) {
return;
}
long validity = guild.getValidity();
if (validity == 0) {
validity = System.currentTimeMillis();
}
validity += time;
guild.setValidity(validity);
String date = config.dateFormat.format(new Date(validity));
sender.sendMessage(messages.adminNewValidity.replace("{GUILD}", guild.getName()).replace("{VALIDITY}", date));
}
Aggregations