diff --git a/build.gradle b/build.gradle index 3add4da..6bd5538 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ apply plugin: 'com.github.johnrengelman.shadow' apply plugin: 'rebel' group = 'me.bramhaag' -version = '1.3.4-RELEASE' +version = '1.4.0-RELEASE' sourceCompatibility = 1.8 targetCompatibility = 1.8 diff --git a/src/main/java/me/bramhaag/guilds/Main.java b/src/main/java/me/bramhaag/guilds/Main.java index 068f6df..3659160 100644 --- a/src/main/java/me/bramhaag/guilds/Main.java +++ b/src/main/java/me/bramhaag/guilds/Main.java @@ -47,8 +47,6 @@ public class Main extends JavaPlugin { public static String PREFIX; - String[] rip; - @Override public void onEnable() { this.saveDefaultConfig(); @@ -82,6 +80,8 @@ public void onEnable() { commandHandler.register(new CommandAccept()); commandHandler.register(new CommandLeave()); + commandHandler.register(new CommandAlly()); + commandHandler.register(new CommandChat()); commandHandler.register(new CommandInfo()); diff --git a/src/main/java/me/bramhaag/guilds/commands/CommandAlly.java b/src/main/java/me/bramhaag/guilds/commands/CommandAlly.java index 7812b45..5d91017 100644 --- a/src/main/java/me/bramhaag/guilds/commands/CommandAlly.java +++ b/src/main/java/me/bramhaag/guilds/commands/CommandAlly.java @@ -1,9 +1,7 @@ package me.bramhaag.guilds.commands; -import me.bramhaag.guilds.Main; import me.bramhaag.guilds.commands.base.CommandBase; import me.bramhaag.guilds.guild.Guild; -import me.bramhaag.guilds.guild.GuildMember; import me.bramhaag.guilds.guild.GuildRole; import me.bramhaag.guilds.message.Message; import org.bukkit.Bukkit; @@ -27,7 +25,7 @@ public void execute(Player player, String[] args) { Guild targetGuild = Guild.getGuild(args[1]); if(targetGuild == null) { - Message.sendMessage(player, Message.COMMAND_ERROR_GUILD_NOT_FOUND); + Message.sendMessage(player, Message.COMMAND_ERROR_GUILD_NOT_FOUND.replace("{input}", args[1])); return; } @@ -35,6 +33,7 @@ public void execute(Player player, String[] args) { if(args[0].equals("accept")) { if(!role.canAddAlly()) { + Message.sendMessage(player, Message.COMMAND_ERROR_ROLE_NO_PERMISSION); return; } @@ -43,14 +42,17 @@ public void execute(Player player, String[] args) { return; } + guild.removePendingAlly(targetGuild); + guild.addAlly(targetGuild); targetGuild.addAlly(guild); - guild.getMembers().forEach(member -> Message.sendMessage(Bukkit.getPlayer(member.getUniqueId()), Message.COMMAND_ALLY_ACCEPTED.replace("guild", targetGuild.getName()))); - guild.getMembers().forEach(member -> Message.sendMessage(Bukkit.getPlayer(member.getUniqueId()), Message.COMMAND_ALLY_ACCEPTED_TARGET.replace("guild", guild.getName()))); + guild.getMembers().forEach(member -> Message.sendMessage(Bukkit.getPlayer(member.getUniqueId()), Message.COMMAND_ALLY_ACCEPTED.replace("{guild}", targetGuild.getName()))); + targetGuild.getMembers().forEach(member -> Message.sendMessage(Bukkit.getPlayer(member.getUniqueId()), Message.COMMAND_ALLY_ACCEPTED_TARGET.replace("{guild}", guild.getName()))); } else if(args[0].equalsIgnoreCase("decline")) { if(!role.canAddAlly()) { + Message.sendMessage(player, Message.COMMAND_ERROR_ROLE_NO_PERMISSION); return; } @@ -59,35 +61,51 @@ else if(args[0].equalsIgnoreCase("decline")) { return; } - guild.getMembers().stream().filter(member -> GuildRole.getRole(member.getRole()).canAddAlly()).forEach(member -> Message.sendMessage(Bukkit.getPlayer(member.getUniqueId()), Message.COMMAND_ALLY_DECLINED.replace("guild", targetGuild.getName()))); - guild.getMembers().stream().filter(member -> GuildRole.getRole(member.getRole()).canAddAlly()).forEach(member -> Message.sendMessage(Bukkit.getPlayer(member.getUniqueId()), Message.COMMAND_ALLY_DECLINED.replace("guild", guild.getName()))); + guild.removePendingAlly(targetGuild); + + guild.getMembers().stream().filter(member -> GuildRole.getRole(member.getRole()).canAddAlly()).forEach(member -> Message.sendMessage(Bukkit.getPlayer(member.getUniqueId()), Message.COMMAND_ALLY_DECLINED.replace("{guild}", targetGuild.getName()))); + targetGuild.getMembers().stream().filter(member -> GuildRole.getRole(member.getRole()).canAddAlly()).forEach(member -> Message.sendMessage(Bukkit.getPlayer(member.getUniqueId()), Message.COMMAND_ALLY_DECLINED.replace("{guild}", targetGuild.getName()))); } if(args[0].equalsIgnoreCase("add")) { if(!role.canAddAlly()) { + Message.sendMessage(player, Message.COMMAND_ERROR_ROLE_NO_PERMISSION); + return; + } + + if(guild.getAllies().contains(targetGuild.getName()) || guild.getName().equals(targetGuild.getName())) { + Message.sendMessage(player, Message.COMMAND_ALLY_ALREADY_ALLIES.replace("{guild}", targetGuild.getName())); return; } - targetGuild.addPendingAlly(guild); Message.sendMessage(player, Message.COMMAND_ALLY_SEND); + targetGuild.getMembers().stream().filter(member -> GuildRole.getRole(member.getRole()).canAddAlly()).forEach(member -> Message.sendMessage(Bukkit.getPlayer(member.getUniqueId()), Message.COMMAND_ALLY_SEND_TARGET.replace("{guild}", guild.getName()))); + targetGuild.addPendingAlly(guild); } else if(args[0].equalsIgnoreCase("remove")) { if(!role.canRemoveAlly()) { + Message.sendMessage(player, Message.COMMAND_ERROR_ROLE_NO_PERMISSION); + return; + } + + if(!guild.getAllies().contains(targetGuild.getName())) { + Message.sendMessage(player, Message.COMMAND_ALLY_NOT_ALLIES.replace("{guild}", targetGuild.getName())); return; } guild.removeAlly(targetGuild); targetGuild.removeAlly(guild); - guild.sendMessage(Message.COMMAND_ALLY_REMOVED.replace("guild", targetGuild.getName())); - targetGuild.sendMessage(Message.COMMAND_ALLY_REMOVED_TARGET.replace("guild", guild.getName())); + guild.sendMessage(Message.COMMAND_ALLY_REMOVED.replace("{guild}", targetGuild.getName())); + targetGuild.sendMessage(Message.COMMAND_ALLY_REMOVED_TARGET.replace("{guild}", guild.getName())); } else if(args[0].equalsIgnoreCase("chat")) { if(!role.useAllyChat()) { + Message.sendMessage(player, Message.COMMAND_ERROR_ROLE_NO_PERMISSION); return; } - String message = String.format("[%s] [%s] %s", guild.getName(), role.getName(), String.join(" ", Arrays.copyOfRange(args, 2, args.length))); + String message = String.format("[%s] [%s] %s: %s", guild.getName(), role.getName(), player.getName(), String.join(" ", Arrays.copyOfRange(args, 2, args.length))); guild.sendMessage(message); targetGuild.sendMessage(message); diff --git a/src/main/java/me/bramhaag/guilds/guild/Guild.java b/src/main/java/me/bramhaag/guilds/guild/Guild.java index 5342ea2..873fb6f 100644 --- a/src/main/java/me/bramhaag/guilds/guild/Guild.java +++ b/src/main/java/me/bramhaag/guilds/guild/Guild.java @@ -46,7 +46,9 @@ public Guild(String name, UUID master) { this.members = new ArrayList<>(); this.members.add(new GuildMember(master, 0)); + this.allies = new ArrayList<>(); this.invitedMembers = new ArrayList<>(); + this.pendingAllies = new ArrayList<>(); } public String getName() { diff --git a/src/main/java/me/bramhaag/guilds/message/Message.java b/src/main/java/me/bramhaag/guilds/message/Message.java index 97bb882..63d5316 100644 --- a/src/main/java/me/bramhaag/guilds/message/Message.java +++ b/src/main/java/me/bramhaag/guilds/message/Message.java @@ -90,11 +90,24 @@ public enum Message { COMMAND_ADMIN_DELETE_ERROR, COMMAND_ADMIN_DELETE_WARNING, COMMAND_ADMIN_DELETE_CANCELLED, + COMMAND_ADMIN_PLAYER_ALREADY_IN_GUILD, + COMMAND_ADMIN_ADDED_PLAYER, + COMMAND_ADMIN_PLAYER_NOT_IN_GUILD, + COMMAND_ADMIN_REMOVED_PLAYER, COMMAND_UPDATE_FOUND, COMMAND_UPDATE_NOT_FOUND, - EVENT_JOIN_PENDING_INVITES, COMMAND_ADMIN_PLAYER_ALREADY_IN_GUILD, COMMAND_ADMIN_ADDED_PLAYER, COMMAND_ADMIN_PLAYER_NOT_IN_GUILD, COMMAND_ADMIN_REMOVED_PLAYER, COMMAND_ALLY_GUILD_NOT_PENDING, COMMAND_ALLY_ACCEPTED, COMMAND_ALLY_ACCEPTED_TARGET, COMMAND_ALLY_DECLINED, COMMAND_ALLY_SEND, COMMAND_ALLY_REMOVED, COMMAND_ALLY_REMOVED_TARGET; + COMMAND_ALLY_GUILD_NOT_PENDING, + COMMAND_ALLY_ACCEPTED, + COMMAND_ALLY_ACCEPTED_TARGET, + COMMAND_ALLY_DECLINED, + COMMAND_ALLY_SEND, + COMMAND_ALLY_SEND_TARGET, + COMMAND_ALLY_REMOVED, + COMMAND_ALLY_REMOVED_TARGET, + + EVENT_JOIN_PENDING_INVITES, COMMAND_ALLY_ALREADY_ALLIES, COMMAND_ALLY_NOT_ALLIES; public static void sendMessage(CommandSender sender, Message message) { sender.sendMessage(ChatColor.translateAlternateColorCodes('&', Main.PREFIX + Main.getInstance().getConfig().getString(getPath(message)))); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 42194b4..8c4f5a1 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -27,10 +27,13 @@ roles: name: "GuildMaster" permissions: chat: true + ally-chat: true invite: true kick: true promote: true demote: true + add-ally: true + remove-ally: true change-prefix: true change-master: true remove-guild: true @@ -38,10 +41,13 @@ roles: name: "Officer" permissions: chat: true + ally-chat: true invite: true kick: true promote: true demote: true + add-ally: true + remove-ally: true change-prefix: false change-master: false remove-guild: false @@ -49,10 +55,13 @@ roles: name: "Veteran" permissions: chat: true + ally-chat: true invite: true kick: false promote: false demote: false + add-ally: false + remove-ally: false change-prefix: false change-master: false remove-guild: false @@ -60,10 +69,13 @@ roles: name: "Member" permissions: chat: true + ally-chat: true invite: false kick: false promote: false demote: false + add-ally: false + remove-ally: false change-prefix: false change-master: false remove-guild: false @@ -193,6 +205,17 @@ messages: added-player: "&aAdded player to guild" player-not-in-guild: "&cPlayer is not in this guild!" removed-player: "&aRemoved player from guild!" + ally: + guild-not-pending: "&cThis guild has not send you an ally request!" + accepted: "&aThis guild is now allied with {guild}!" + accepted-target: "&a{guild} is now allied with us!" + declined: "&c{guild} does not want to be an ally!" + send: "&aSend ally request!" + send-target: "&aRecieved an ally request from {guild}! Type /guilds ally accept {guild} to accept or type /guilds ally decline {guild} to decline" + removed: "&cThis guild is no longer allied with {guild}!" + removed-target: "&c{guild} is no longer allied with us!" + already-allies: "&cYou're already allied with {guild}!" + not-allies: "&cYou aren't allied with {guild}!" event: join: pending-invites: "&aYou have {number} pending invite(s) from the guild(s): &e{guilds}" \ No newline at end of file