Skip to content

Commit

Permalink
Added the ability to set amount of missions completed directly using …
Browse files Browse the repository at this point in the history
…the API
  • Loading branch information
OmerBenGera committed Aug 5, 2022
1 parent 86abd7f commit 0139886
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 39 deletions.
Expand Up @@ -40,6 +40,14 @@ public interface IMissionsHolder {
*/
int getAmountMissionCompleted(Mission<?> mission);

/**
* Set the amount of times mission was completed.
*
* @param mission The mission to set.
* @param finishCount The amount of times the mission was completed.
*/
void setAmountMissionCompleted(Mission<?> mission, int finishCount);

/**
* Get the list of the completed missions of the player.
*/
Expand Down
43 changes: 21 additions & 22 deletions src/main/java/com/bgsoftware/superiorskyblock/island/SIsland.java
Expand Up @@ -3415,14 +3415,7 @@ private void warpPlayerWithoutWarmup(SuperiorPlayer superiorPlayer, IslandWarp i
@Override
public void completeMission(Mission<?> mission) {
Preconditions.checkNotNull(mission, "mission parameter cannot be null.");
PluginDebugger.debug("Action: Complete Mission, Island: " + owner.getName() + ", Mission: " + mission.getName());

int finishCount = completedMissions.getOrDefault(mission, 0) + 1;
completedMissions.put(mission, finishCount);

IslandsDatabaseBridge.saveMission(this, mission, finishCount);

plugin.getMenus().refreshMissionsCategory(mission.getMissionCategory());
setAmountMissionCompleted(mission, completedMissions.getOrDefault(mission, 0) + 1);
}

/*
Expand All @@ -3432,20 +3425,7 @@ public void completeMission(Mission<?> mission) {
@Override
public void resetMission(Mission<?> mission) {
Preconditions.checkNotNull(mission, "mission parameter cannot be null.");
PluginDebugger.debug("Action: Reset Mission, Island: " + owner.getName() + ", Mission: " + mission.getName());

int finishCount = completedMissions.getOrDefault(mission, 0) - 1;
if (finishCount > 0) {
completedMissions.put(mission, finishCount);
IslandsDatabaseBridge.saveMission(this, mission, finishCount);
} else {
completedMissions.remove(mission);
IslandsDatabaseBridge.removeMission(this, mission);
}

mission.clearData(getOwner());

plugin.getMenus().refreshMissionsCategory(mission.getMissionCategory());
setAmountMissionCompleted(mission, completedMissions.getOrDefault(mission, 0) - 1);
}

/*
Expand All @@ -3472,6 +3452,25 @@ public int getAmountMissionCompleted(Mission<?> mission) {
return completedMissions.getOrDefault(mission, 0);
}

@Override
public void setAmountMissionCompleted(Mission<?> mission, int finishCount) {
Preconditions.checkNotNull(mission, "mission parameter cannot be null.");
PluginDebugger.debug("Action: Set Amount Mission Completed, Island: " + owner.getName() +
", Mission: " + mission.getName() + ", Amount: " + finishCount);

if (finishCount > 0) {
completedMissions.put(mission, finishCount);
IslandsDatabaseBridge.saveMission(this, mission, finishCount);
} else {
completedMissions.remove(mission);
IslandsDatabaseBridge.removeMission(this, mission);
}

mission.clearData(getOwner());

plugin.getMenus().refreshMissionsCategory(mission.getMissionCategory());
}

/*
* Data related methods
*/
Expand Down
Expand Up @@ -1515,6 +1515,11 @@ public int getAmountMissionCompleted(Mission<?> mission) {
return 0;
}

@Override
public void setAmountMissionCompleted(Mission<?> mission, int finishCount) {
// Do nothing.
}

@Override
public List<Mission<?>> getCompletedMissions() {
return Collections.emptyList();
Expand Down
Expand Up @@ -724,28 +724,13 @@ public PersistentDataContainer getPersistentDataContainer() {
@Override
public void completeMission(Mission<?> mission) {
Preconditions.checkNotNull(mission, "mission parameter cannot be null.");
PluginDebugger.debug("Action: Complete Mission, Player: " + getName() + ", Mission: " + mission.getName());
int finishCount = completedMissions.getOrDefault(mission, 0) + 1;
completedMissions.put(mission, finishCount);
PlayersDatabaseBridge.saveMission(this, mission, finishCount);
this.setAmountMissionCompleted(mission, completedMissions.getOrDefault(mission, 0) + 1);
}

@Override
public void resetMission(Mission<?> mission) {
Preconditions.checkNotNull(mission, "mission parameter cannot be null.");
PluginDebugger.debug("Action: Reset Mission, Player: " + getName() + ", Mission: " + mission.getName());

int finishCount = completedMissions.getOrDefault(mission, 0) - 1;

if (finishCount > 0) {
completedMissions.put(mission, finishCount);
PlayersDatabaseBridge.saveMission(this, mission, finishCount);
} else {
completedMissions.remove(mission);
PlayersDatabaseBridge.removeMission(this, mission);
}

mission.clearData(this);
this.setAmountMissionCompleted(mission, completedMissions.getOrDefault(mission, 0) - 1);
}

@Override
Expand All @@ -768,6 +753,23 @@ public int getAmountMissionCompleted(Mission<?> mission) {
return completedMissions.getOrDefault(mission, 0);
}

@Override
public void setAmountMissionCompleted(Mission<?> mission, int finishCount) {
Preconditions.checkNotNull(mission, "mission parameter cannot be null.");
PluginDebugger.debug("Action: Set Amount Mission Completed, Player: " + getName() +
", Mission: " + mission.getName() + ", Amount: " + finishCount);

if (finishCount > 0) {
completedMissions.put(mission, finishCount);
PlayersDatabaseBridge.saveMission(this, mission, finishCount);
} else {
completedMissions.remove(mission);
PlayersDatabaseBridge.removeMission(this, mission);
}

mission.clearData(this);
}

@Override
public List<Mission<?>> getCompletedMissions() {
return new SequentialListBuilder<Mission<?>>().build(completedMissions.keySet());
Expand Down
Expand Up @@ -437,6 +437,11 @@ public int getAmountMissionCompleted(Mission<?> mission) {
return 0;
}

@Override
public void setAmountMissionCompleted(Mission<?> mission, int finishCount) {
// Do nothing.
}

@Override
public List<Mission<?>> getCompletedMissions() {
return Collections.emptyList();
Expand Down

0 comments on commit 0139886

Please sign in to comment.