Skip to content

Commit

Permalink
Update to 1.4.0
Browse files Browse the repository at this point in the history
- Fully implemented Ally system
  • Loading branch information
bramhaag committed Feb 1, 2017
1 parent 1453c9e commit b6df9cf
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 15 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/me/bramhaag/guilds/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ public class Main extends JavaPlugin {

public static String PREFIX;

String[] rip;

@Override
public void onEnable() {
this.saveDefaultConfig();
Expand Down Expand Up @@ -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());
Expand Down
40 changes: 29 additions & 11 deletions src/main/java/me/bramhaag/guilds/commands/CommandAlly.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -27,14 +25,15 @@ 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;
}

GuildRole role = GuildRole.getRole(guild.getMember(player.getUniqueId()).getRole());

if(args[0].equals("accept")) {
if(!role.canAddAlly()) {
Message.sendMessage(player, Message.COMMAND_ERROR_ROLE_NO_PERMISSION);
return;
}

Expand All @@ -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;
}

Expand All @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/me/bramhaag/guilds/guild/Guild.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
15 changes: 14 additions & 1 deletion src/main/java/me/bramhaag/guilds/message/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -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))));
Expand Down
23 changes: 23 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,43 +27,55 @@ 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
1:
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
2:
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
3:
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
Expand Down Expand Up @@ -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}"

0 comments on commit b6df9cf

Please sign in to comment.