Skip to content

Commit

Permalink
Merge pull request #1374 from Dans-Plugins/fixing-ally-and-enemy-api-…
Browse files Browse the repository at this point in the history
…access

It is now possible to check whether a faction is an ally or enemy through the MF_Faction class
  • Loading branch information
dmccoystephenson authored Mar 5, 2022
2 parents ba22cbd + e6823d2 commit bd0850b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @author Daniel McCoy Stephenson
*/
public class MF_Faction {
Faction faction;
private Faction faction;

public MF_Faction(Faction f) {
faction = f;
Expand Down Expand Up @@ -43,4 +43,21 @@ public boolean isOfficer(Player player) {
public Object getFlag(String flag) {
return faction.getFlags().getFlag(flag);
}
}

public boolean isAlly(String factionName) {
return faction.isAlly(factionName);
}

public boolean isEnemy(String factionName) {
return faction.isEnemy(factionName);
}

/**
* This should only be used when the external API is not sufficient. It should be noted that the underlying implementation is prone to change.
* @return The underlying implementation of the faction class.
*/
@Deprecated
public Faction getUnderlyingImplementation() {
return faction;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
*/
public class MedievalFactionsAPI {
private final String APIVersion = "v1.0.0"; // every time the external API is altered, this should be incremented
private ArrayList<String> allyFactions = new ArrayList<>();
private ArrayList<String> enemyFactions = new ArrayList<>();

public String getAPIVersion() {
return APIVersion;
Expand Down Expand Up @@ -98,42 +96,4 @@ public void decreasePower(Player player, int amount) {
powerRecord.setPower(0);
}
}

/**
* Checks the faction's list of allies for the supplied faction name
* @return boolean
*/
public boolean isAlly(String factionname) {
return containsIgnoreCase(allyFactions, factionname);
}

/**
* @return list of allied factions
*/
public ArrayList<String> getAllies() {
return allyFactions;
}

/**
* @return boolean
*/
public boolean isEnemy(String factionName) {
return containsIgnoreCase(enemyFactions, factionName);
}

/**
* @return list of enemies for the faction
*/
public ArrayList<String> getEnemies() {
return enemyFactions;
}

private boolean containsIgnoreCase(ArrayList<String> list, String str) {
for (String string : list) {
if (string.equalsIgnoreCase(str)) {
return true;
}
}
return false;
}
}

0 comments on commit bd0850b

Please sign in to comment.