use of net.dzikoysk.funnyguilds.concurrency.ConcurrencyManager 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.concurrency.ConcurrencyManager 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.concurrency.ConcurrencyManager 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));
}
}
use of net.dzikoysk.funnyguilds.concurrency.ConcurrencyManager in project FunnyGuilds by FunnyGuilds.
the class FunnyGuilds method onLoad.
@Override
public void onLoad() {
if (!this.getDataFolder().exists()) {
this.getDataFolder().mkdir();
}
DescriptionManager descriptionManager = new DescriptionManager(super.getDescription());
version = descriptionManager.extractVersion();
PluginConfig settings = Settings.getConfig();
descriptionManager.rename(settings.pluginName);
this.concurrencyManager = new ConcurrencyManager(settings.concurrencyThreads);
this.concurrencyManager.printStatus();
this.reloadHandler = new ReloadHandler();
this.reloadHandler.init();
Commands commands = new Commands();
commands.register();
this.eventManager = new EventManager();
this.eventManager.load();
}
use of net.dzikoysk.funnyguilds.concurrency.ConcurrencyManager in project FunnyGuilds by FunnyGuilds.
the class PacketExtension method registerPlayer.
public static void registerPlayer(Player player) {
try {
ConcurrencyManager concurrencyManager = FunnyGuilds.getInstance().getConcurrencyManager();
Channel channel = getChannel(player);
ChannelHandler handler = new ChannelDuplexHandler() {
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
if (msg == null) {
return;
}
super.write(ctx, msg, promise);
}
@Override
public void channelRead(ChannelHandlerContext ctx, Object packet) throws Exception {
try {
if (packet == null) {
return;
}
// IndependentThread.action(ActionType.PACKET_PLAY_IN_USE_ENTITY, p, msg);
concurrencyManager.postRequests(new WarUseRequest(player, packet));
super.channelRead(ctx, packet);
} catch (Exception e) {
super.channelRead(ctx, packet);
}
}
};
if (channel == null) {
return;
}
ChannelPipeline pipeline = channel.pipeline();
if (pipeline.names().contains("packet_handler")) {
if (pipeline.names().contains("FunnyGuilds")) {
pipeline.replace("FunnyGuilds", "FunnyGuilds", handler);
} else {
pipeline.addBefore("packet_handler", "FunnyGuilds", handler);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations