use of net.dzikoysk.funnyguilds.basic.User in project FunnyGuilds by FunnyGuilds.
the class ExcLeave method execute.
@Override
public void execute(CommandSender sender, String[] args) {
MessagesConfig messages = Messages.getInstance();
Player player = (Player) sender;
User user = User.get(player);
if (!user.hasGuild()) {
player.sendMessage(messages.generalHasNoGuild);
return;
}
if (user.isOwner()) {
player.sendMessage(messages.leaveIsOwner);
return;
}
Guild guild = user.getGuild();
if (!SimpleEventHandler.handle(new GuildMemberLeaveEvent(EventCause.USER, user, guild, user))) {
return;
}
guild.removeMember(user);
user.removeGuild();
// IndependentThread.action(ActionType.PREFIX_GLOBAL_REMOVE_PLAYER, user.getName());
// IndependentThread.action(ActionType.PREFIX_GLOBAL_UPDATE_PLAYER, player);
ConcurrencyManager concurrencyManager = FunnyGuilds.getInstance().getConcurrencyManager();
concurrencyManager.postRequests(new PrefixGlobalRemovePlayerRequest(user.getName()), new PrefixGlobalUpdatePlayer(player));
MessageTranslator translator = new MessageTranslator().register("{GUILD}", guild.getName()).register("{TAG}", guild.getTag()).register("{PLAYER}", user.getName());
player.sendMessage(translator.translate(messages.leaveToUser));
Bukkit.broadcastMessage(translator.translate(messages.broadcastLeave));
}
use of net.dzikoysk.funnyguilds.basic.User 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.basic.User in project FunnyGuilds by FunnyGuilds.
the class AxcAdd method execute.
@Override
public void execute(CommandSender sender, String[] args) {
MessagesConfig messages = Messages.getInstance();
if (args.length < 1) {
sender.sendMessage(messages.generalNoTagGiven);
return;
}
if (!GuildUtils.tagExists(args[0])) {
sender.sendMessage(messages.generalNoGuildFound);
return;
}
if (args.length < 2) {
sender.sendMessage(messages.generalNoNickGiven);
return;
}
if (!UserUtils.playedBefore(args[1])) {
sender.sendMessage(messages.generalNotPlayedBefore);
return;
}
User user = User.get(args[1]);
if (user.hasGuild()) {
sender.sendMessage(messages.generalUserHasGuild);
return;
}
Guild guild = GuildUtils.getByTag(args[0]);
if (guild == null) {
sender.sendMessage(messages.generalNoGuildFound);
return;
}
User admin = (sender instanceof Player) ? User.get(sender.getName()) : null;
if (!SimpleEventHandler.handle(new GuildMemberJoinEvent(admin == null ? EventCause.CONSOLE : EventCause.ADMIN, admin, guild, user))) {
return;
}
guild.addMember(user);
user.setGuild(guild);
// IndependentThread.action(ActionType.PREFIX_GLOBAL_ADD_PLAYER, user.getName());
ConcurrencyManager concurrencyManager = FunnyGuilds.getInstance().getConcurrencyManager();
concurrencyManager.postRequests(new PrefixGlobalAddPlayerRequest(user.getName()));
MessageTranslator translator = new MessageTranslator().register("{GUILD}", guild.getName()).register("{TAG}", guild.getTag()).register("{PLAYER}", user.getName());
Player player = user.getPlayer();
Player owner = guild.getOwner().getPlayer();
if (player != null) {
player.sendMessage(translator.translate(messages.joinToMember));
}
if (owner != null) {
owner.sendMessage(translator.translate(messages.joinToOwner));
}
Bukkit.broadcastMessage(translator.translate(messages.broadcastJoin));
}
use of net.dzikoysk.funnyguilds.basic.User in project FunnyGuilds by FunnyGuilds.
the class AxcBan method execute.
@Override
public void execute(CommandSender sender, String[] args) {
MessagesConfig messages = Messages.getInstance();
if (args.length < 1) {
sender.sendMessage(messages.generalNoTagGiven);
return;
} else if (args.length < 2) {
sender.sendMessage(messages.adminNoBanTimeGiven);
return;
} else if (args.length < 3) {
sender.sendMessage(messages.adminNoReasonGiven);
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;
}
StringBuilder reasonBuilder = new StringBuilder();
for (int i = 2; i < args.length; i++) {
reasonBuilder.append(args[i]);
reasonBuilder.append(" ");
}
String reason = reasonBuilder.toString();
User admin = (sender instanceof Player) ? User.get(sender.getName()) : null;
if (!SimpleEventHandler.handle(new GuildBanEvent(admin == null ? EventCause.CONSOLE : EventCause.ADMIN, admin, guild, time, reason))) {
return;
}
BanUtils.ban(guild, time, reason);
MessageTranslator translator = new MessageTranslator().register("{GUILD", guild.getName()).register("{TAG}", guild.getTag()).register("{TIME}", args[1]).register("{REASON}", StringUtils.colored(reason));
sender.sendMessage(translator.translate(messages.adminGuildBan));
Bukkit.broadcastMessage(translator.translate(messages.broadcastBan));
}
use of net.dzikoysk.funnyguilds.basic.User 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