use of net.dzikoysk.funnyguilds.basic.User in project FunnyGuilds by FunnyGuilds.
the class ExcBase 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);
if (!config.regionsEnabled) {
player.sendMessage(messages.regionsDisabled);
return;
}
if (!config.baseEnable) {
player.sendMessage(messages.baseTeleportationDisabled);
return;
}
if (!user.hasGuild()) {
player.sendMessage(messages.generalHasNoGuild);
return;
}
Guild guild = user.getGuild();
if (user.getTeleportation() != null) {
player.sendMessage(messages.baseIsTeleportation);
return;
}
Collection<ItemStack> requiredItems = config.baseItems;
for (ItemStack requiredItem : requiredItems) {
if (player.getInventory().containsAtLeast(requiredItem, requiredItem.getAmount())) {
continue;
}
String msg = ItemUtils.translatePlaceholder(messages.baseItems, requiredItems, requiredItem);
player.sendMessage(msg);
return;
}
ItemStack[] items = ItemUtils.toArray(requiredItems);
player.getInventory().removeItem(items);
if (config.baseDelay < 1) {
player.teleport(guild.getHome());
player.sendMessage(messages.baseTeleport);
return;
}
int time = config.baseDelay;
Location before = player.getLocation();
AtomicInteger i = new AtomicInteger(1);
user.setTeleportation(Bukkit.getScheduler().runTaskTimer(FunnyGuilds.getInstance(), () -> {
if (!player.isOnline()) {
user.getTeleportation().cancel();
user.setTeleportation(null);
return;
}
if (!LocationUtils.equals(player.getLocation(), before)) {
user.getTeleportation().cancel();
player.sendMessage(messages.baseMove);
user.setTeleportation(null);
player.getInventory().addItem(items);
return;
}
if (i.getAndIncrement() > time) {
user.getTeleportation().cancel();
player.sendMessage(messages.baseTeleport);
player.teleport(guild.getHome());
user.setTeleportation(null);
}
}, 0L, 20L));
player.sendMessage(messages.baseDontMove.replace("{TIME}", Integer.toString(time)));
}
use of net.dzikoysk.funnyguilds.basic.User in project FunnyGuilds by FunnyGuilds.
the class ExcBreak 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.generalIsNotOwner);
return;
}
Guild guild = user.getGuild();
if (guild.getAllies() == null || guild.getAllies().isEmpty()) {
player.sendMessage(messages.breakHasNotAllies);
return;
}
if (args.length < 1) {
List<String> list = messages.breakAlliesList;
String iss = StringUtils.toString(GuildUtils.getNames(guild.getAllies()), true);
for (String msg : list) {
player.sendMessage(msg.replace("{GUILDS}", iss));
}
return;
}
String tag = args[0];
Guild oppositeGuild = GuildUtils.getByTag(tag);
if (oppositeGuild == null) {
player.sendMessage(messages.generalGuildNotExists.replace("{TAG}", tag));
return;
}
if (!guild.getAllies().contains(oppositeGuild)) {
player.sendMessage(messages.breakAllyExists.replace("{GUILD}", oppositeGuild.getName()).replace("{TAG}", tag));
}
if (!SimpleEventHandler.handle(new GuildBreakAllyEvent(EventCause.USER, user, guild, oppositeGuild))) {
return;
}
Player owner = oppositeGuild.getOwner().getPlayer();
if (owner != null) {
owner.sendMessage(messages.breakIDone.replace("{GUILD}", guild.getName()).replace("{TAG}", guild.getTag()));
}
guild.removeAlly(oppositeGuild);
oppositeGuild.removeAlly(guild);
ConcurrencyManager concurrencyManager = FunnyGuilds.getInstance().getConcurrencyManager();
ConcurrencyTaskBuilder taskBuilder = ConcurrencyTask.builder();
for (User member : guild.getMembers()) {
// IndependentThread.action(ActionType.PREFIX_UPDATE_GUILD, member, oppositeGuild);
taskBuilder.delegate(new PrefixUpdateGuildRequest(member, oppositeGuild));
}
for (User member : oppositeGuild.getMembers()) {
// IndependentThread.action(ActionType.PREFIX_UPDATE_GUILD, member, guild);
taskBuilder.delegate(new PrefixUpdateGuildRequest(member, guild));
}
ConcurrencyTask task = taskBuilder.build();
concurrencyManager.postTask(task);
player.sendMessage(messages.breakDone.replace("{GUILD}", oppositeGuild.getName()).replace("{TAG}", oppositeGuild.getTag()));
}
use of net.dzikoysk.funnyguilds.basic.User in project FunnyGuilds by FunnyGuilds.
the class ExcConfirm 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.generalIsNotOwner);
return;
}
if (!Settings.getConfig().regionDeleteIfNear && user.getGuild().isSomeoneInRegion()) {
player.sendMessage(messages.deleteSomeoneIsNear);
return;
}
if (!ConfirmationList.contains(user.getUUID())) {
player.sendMessage(messages.deleteToConfirm);
return;
}
ConfirmationList.remove(user.getUUID());
Guild guild = user.getGuild();
if (!SimpleEventHandler.handle(new GuildDeleteEvent(EventCause.USER, user, guild))) {
return;
}
GuildUtils.deleteGuild(user.getGuild());
MessageTranslator translator = new MessageTranslator().register("{GUILD}", guild.getName()).register("{TAG}", guild.getTag()).register("{PLAYER}", player.getName());
player.sendMessage(translator.translate(messages.deleteSuccessful));
Bukkit.getServer().broadcastMessage(translator.translate(messages.broadcastDelete));
}
use of net.dzikoysk.funnyguilds.basic.User in project FunnyGuilds by FunnyGuilds.
the class ExcJoin 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.joinHasGuild);
return;
}
List<InvitationList.Invitation> invitations = InvitationList.getInvitationsFor(player);
if (invitations.size() == 0) {
player.sendMessage(messages.joinHasNotInvitation);
return;
}
if (args.length < 1) {
String guildNames = StringUtils.toString(InvitationList.getInvitationGuildNames(player), false);
for (String msg : messages.joinInvitationList) {
player.sendMessage(msg.replace("{GUILDS}", guildNames));
}
return;
}
String tag = args[0];
Guild guild = GuildUtils.getByTag(tag);
if (guild == null) {
player.sendMessage(messages.joinTagExists);
return;
}
if (!InvitationList.hasInvitationFrom(player, GuildUtils.getByTag(tag))) {
player.sendMessage(messages.joinHasNotInvitationTo);
return;
}
List<ItemStack> requiredItems = Settings.getConfig().joinItems;
for (ItemStack requiredItem : requiredItems) {
if (player.getInventory().containsAtLeast(requiredItem, requiredItem.getAmount())) {
continue;
}
String msg = ItemUtils.translatePlaceholder(messages.joinItems, requiredItems, requiredItem);
player.sendMessage(msg);
return;
}
if (!SimpleEventHandler.handle(new GuildMemberAcceptInviteEvent(EventCause.USER, user, guild, user))) {
return;
}
InvitationList.expireInvitation(guild, player);
if (!SimpleEventHandler.handle(new GuildMemberJoinEvent(EventCause.USER, user, guild, user))) {
return;
}
guild.addMember(user);
user.setGuild(guild);
player.getInventory().removeItem(ItemUtils.toArray(requiredItems));
// 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}", player.getName());
player.sendMessage(translator.translate(messages.joinToMember));
Bukkit.broadcastMessage(translator.translate(messages.broadcastJoin));
Player owner = guild.getOwner().getPlayer();
if (owner != null) {
owner.sendMessage(translator.translate(messages.joinToOwner));
}
}
use of net.dzikoysk.funnyguilds.basic.User in project FunnyGuilds by FunnyGuilds.
the class ExcKick 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() && !user.isDeputy()) {
player.sendMessage(messages.generalIsNotOwner);
return;
}
if (args.length < 1) {
player.sendMessage(messages.generalNoNickGiven);
return;
}
User formerUser = User.get(args[0]);
if (!formerUser.hasGuild()) {
player.sendMessage(messages.generalPlayerHasNoGuild);
return;
}
if (!user.getGuild().equals(formerUser.getGuild())) {
player.sendMessage(messages.kickOtherGuild);
return;
}
if (formerUser.isOwner()) {
player.sendMessage(messages.kickOwner);
return;
}
Guild guild = user.getGuild();
if (!SimpleEventHandler.handle(new GuildMemberKickEvent(EventCause.USER, user, guild, formerUser))) {
return;
}
// IndependentThread.action(ActionType.PREFIX_GLOBAL_REMOVE_PLAYER, formerUser.getName());
ConcurrencyManager concurrencyManager = FunnyGuilds.getInstance().getConcurrencyManager();
concurrencyManager.postRequests(new PrefixGlobalRemovePlayerRequest(formerUser.getName()));
guild.removeMember(formerUser);
formerUser.removeGuild();
if (formerUser.isOnline()) {
// IndependentThread.action(ActionType.PREFIX_GLOBAL_UPDATE_PLAYER, player);
concurrencyManager.postRequests(new PrefixGlobalUpdatePlayer(player));
}
MessageTranslator translator = new MessageTranslator().register("{PLAYER}", formerUser.getName()).register("{GUILD}", guild.getName()).register("{TAG}", guild.getTag());
player.sendMessage(translator.translate(messages.kickToOwner));
Bukkit.broadcastMessage(translator.translate(messages.broadcastKick));
Player formerPlayer = formerUser.getPlayer();
if (formerPlayer != null) {
formerPlayer.sendMessage(translator.translate(messages.kickToPlayer));
}
}
Aggregations