Skip to content

Commit

Permalink
Merge pull request #108 from Kingdom-Programmers/showing-other-info
Browse files Browse the repository at this point in the history
Showing other info
  • Loading branch information
dmccoystephenson authored Jun 4, 2020
2 parents 6dd8854 + 9eb4f21 commit 668e46a
Showing 1 changed file with 65 additions and 29 deletions.
94 changes: 65 additions & 29 deletions src/plugin/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
if (!factionExists) {

// creating name from arguments 1 to the last one
String name = "";
for (int i = 1; i < args.length; i++) {
name = name + args[i];
if (!(i == args.length - 1)) {
name = name + " ";
}
}
String name = createStringFromFirstArgOnwards(args);

// actual faction creation
Faction temp = new Faction(name, player.getName());
Expand Down Expand Up @@ -234,14 +228,21 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
if (args[0].equalsIgnoreCase("members")) {
if (sender instanceof Player) {
Player player = (Player) sender;
for (Faction faction : factions) {
if (faction.isMember(player.getName())) {
ArrayList<String> members = faction.getMemberList();
sender.sendMessage(ChatColor.BOLD + "" + ChatColor.AQUA + "Members of " + faction.getName() + "\n----------\n");
for (String member : members) {
player.sendMessage(ChatColor.AQUA + member + "\n");
if (args.length == 1) {
for (Faction faction : factions) {
if (faction.isMember(player.getName())) {
sendFactionMembers(player, faction);
}
}
}
else {
// creating name from arguments 1 to the last one
String name = createStringFromFirstArgOnwards(args);

for (Faction faction : factions) {
if (faction.getName().equalsIgnoreCase(name)) {
sendFactionMembers(player, faction);
}
sender.sendMessage(ChatColor.AQUA + "----------\n");
}
}
}
Expand All @@ -251,14 +252,26 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
if (args[0].equalsIgnoreCase("info")) {
if (sender instanceof Player) {
Player player = (Player) sender;
for (Faction faction : factions) {
if (faction.isMember(player.getName())) {
sender.sendMessage(ChatColor.BOLD + "" + ChatColor.AQUA + faction.getName() + " Faction Info" + "\n----------\n");
player.sendMessage(ChatColor.AQUA + "Name: " + faction.getName() + "\n");
player.sendMessage(ChatColor.AQUA + "Owner: " + faction.getOwner() + "\n");
player.sendMessage(ChatColor.AQUA + "Description: " + faction.getDescription() + "\n");
player.sendMessage(ChatColor.AQUA + "Population: " + faction.getMemberList().size() + "\n");
player.sendMessage(ChatColor.AQUA + "----------\n");
if (args.length == 1) {
for (Faction faction : factions) {
if (faction.isMember(player.getName())) {
sendFactionInfo(player, faction);
}
}
}
else {
// creating name from arguments 1 to the last one
String name = createStringFromFirstArgOnwards(args);

boolean exists = false;
for (Faction faction : factions) {
if (faction.getName().equals(name)) {
exists = true;
sendFactionInfo(player, faction);
}
}
if (!exists) {
player.sendMessage(ChatColor.RED + "That faction wasn't found!");
}
}
}
Expand Down Expand Up @@ -342,13 +355,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
if (args.length > 1) {

// creating name from arguments 1 to the last one
String factionName = "";
for (int i = 1; i < args.length; i++) {
factionName = factionName + args[i];
if (!(i == args.length - 1)) {
factionName = factionName + " ";
}
}
String factionName = createStringFromFirstArgOnwards(args);

for (Faction faction : factions) {
if (faction.getName().equalsIgnoreCase(factionName)) {
Expand Down Expand Up @@ -523,4 +530,33 @@ boolean isInFaction(String playerName) {
return isAlreadyInFaction;
}

void sendFactionInfo(Player player, Faction faction) {
player.sendMessage(ChatColor.BOLD + "" + ChatColor.AQUA + faction.getName() + " Faction Info" + "\n----------\n");
player.sendMessage(ChatColor.AQUA + "Name: " + faction.getName() + "\n");
player.sendMessage(ChatColor.AQUA + "Owner: " + faction.getOwner() + "\n");
player.sendMessage(ChatColor.AQUA + "Description: " + faction.getDescription() + "\n");
player.sendMessage(ChatColor.AQUA + "Population: " + faction.getMemberList().size() + "\n");
player.sendMessage(ChatColor.AQUA + "----------\n");
}

void sendFactionMembers(Player player, Faction faction) {
ArrayList<String> members = faction.getMemberList();
player.sendMessage(ChatColor.BOLD + "" + ChatColor.AQUA + "Members of " + faction.getName() + "\n----------\n");
for (String member : members) {
player.sendMessage(ChatColor.AQUA + member + "\n");
}
player.sendMessage(ChatColor.AQUA + "----------\n");
}

String createStringFromFirstArgOnwards(String[] args) {
String name = "";
for (int i = 1; i < args.length; i++) {
name = name + args[i];
if (!(i == args.length - 1)) {
name = name + " ";
}
}
return name;
}

}

0 comments on commit 668e46a

Please sign in to comment.