use of net.dzikoysk.funnyguilds.concurrency.ConcurrencyManager 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.concurrency.ConcurrencyManager 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.concurrency.ConcurrencyManager in project FunnyGuilds by FunnyGuilds.
the class GuildUtils method deleteGuild.
public static void deleteGuild(final Guild guild) {
PluginConfig config = Settings.getConfig();
if (guild == null) {
return;
}
Manager.getInstance().stop();
if (config.regionsEnabled) {
Region region = RegionUtils.get(guild.getRegion());
if (region != null) {
if (config.createEntityType != null) {
EntityUtil.despawn(guild);
} else if (config.createMaterialData != null && config.createMaterialData.getItemType() != Material.AIR) {
Bukkit.getScheduler().runTask(FunnyGuilds.getInstance(), () -> {
Block block = region.getCenter().getBlock().getRelative(BlockFace.DOWN);
if (block.getLocation().getBlockY() > 1) {
block.setType(Material.AIR);
}
});
}
}
for (String name : guild.getRegions()) {
Region r = RegionUtils.get(name);
if (r != null) {
RegionUtils.delete(r);
}
}
RegionUtils.delete(Region.get(guild.getRegion()));
}
// IndependentThread.action(ActionType.PREFIX_GLOBAL_REMOVE_GUILD, guild);
ConcurrencyManager concurrencyManager = FunnyGuilds.getInstance().getConcurrencyManager();
concurrencyManager.postRequests(new PrefixGlobalRemoveGuildRequest(guild));
UserUtils.removeGuild(guild.getMembers());
RankManager.getInstance().remove(guild);
for (Guild allay : guild.getAllies()) {
allay.removeAlly(guild);
}
for (Guild enemy : guild.getEnemies()) {
enemy.removeEnemy(guild);
}
if (Settings.getConfig().dataType.flat) {
Flat.getGuildFile(guild).delete();
}
if (Settings.getConfig().dataType.mysql) {
new DatabaseGuild(guild).delete();
}
guild.delete();
Manager.getInstance().start();
}
use of net.dzikoysk.funnyguilds.concurrency.ConcurrencyManager in project FunnyGuilds by FunnyGuilds.
the class User method removeGuild.
public void removeGuild() {
this.guild = null;
this.changes();
// IndependentThread.action(ActionType.RANK_UPDATE_USER, this);
ConcurrencyManager concurrencyManager = FunnyGuilds.getInstance().getConcurrencyManager();
concurrencyManager.postRequests(new RankUpdateUserRequest(this));
}
use of net.dzikoysk.funnyguilds.concurrency.ConcurrencyManager in project FunnyGuilds by FunnyGuilds.
the class AxcKick method execute.
@Override
public void execute(CommandSender sender, String[] args) {
MessagesConfig messages = Messages.getInstance();
if (args.length < 1) {
sender.sendMessage(messages.generalNoNickGiven);
return;
}
if (!UserUtils.playedBefore(args[0])) {
sender.sendMessage(messages.generalNotPlayedBefore);
return;
}
User user = User.get(args[0]);
if (!user.hasGuild()) {
sender.sendMessage(messages.generalPlayerHasNoGuild);
return;
}
if (user.isOwner()) {
sender.sendMessage(messages.adminGuildOwner);
return;
}
Guild guild = user.getGuild();
User admin = (sender instanceof Player) ? User.get(sender.getName()) : null;
if (!SimpleEventHandler.handle(new GuildMemberKickEvent(admin == null ? EventCause.CONSOLE : EventCause.ADMIN, admin, guild, user))) {
return;
}
// IndependentThread.action(ActionType.PREFIX_GLOBAL_REMOVE_PLAYER, user.getName());
ConcurrencyManager concurrencyManager = FunnyGuilds.getInstance().getConcurrencyManager();
concurrencyManager.postRequests(new PrefixGlobalRemovePlayerRequest(user.getName()));
Player player = user.getPlayer();
guild.removeMember(user);
user.removeGuild();
MessageTranslator translator = new MessageTranslator().register("{GUILD}", guild.getName()).register("{TAG}", guild.getTag()).register("{PLAYER}", user.getName());
if (player != null) {
// IndependentThread.action(ActionType.PREFIX_GLOBAL_UPDATE_PLAYER, player);
concurrencyManager.postRequests(new PrefixGlobalUpdatePlayer(player));
player.sendMessage(translator.translate(messages.kickToPlayer));
}
sender.sendMessage(translator.translate(messages.kickToOwner));
Bukkit.broadcastMessage(translator.translate(messages.broadcastKick));
}
Aggregations