Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from starsector-forks/master
Enable AddSubmarket and add RemoveSubmarket commands
- Loading branch information
Showing
3 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/main/java/org/lazywizard/console/commands/RemoveSubmarket.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package org.lazywizard.console.commands; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import com.fs.starfarer.api.campaign.econ.MarketAPI; | ||
import com.fs.starfarer.api.campaign.econ.SubmarketAPI; | ||
|
||
import org.lazywizard.console.BaseCommand; | ||
import org.lazywizard.console.CommonStrings; | ||
import org.lazywizard.console.Console; | ||
import org.lazywizard.lazylib.CollectionUtils; | ||
|
||
public class RemoveSubmarket implements BaseCommand { | ||
@Override | ||
public CommandResult runCommand(String args, CommandContext context) { | ||
if (!context.isInMarket()) { | ||
Console.showMessage(CommonStrings.ERROR_MARKET_ONLY); | ||
return CommandResult.WRONG_CONTEXT; | ||
} | ||
|
||
final MarketAPI market = context.getMarket(); | ||
if (args.isEmpty()) { | ||
final List<String> submarkets = new ArrayList<>(); | ||
for (SubmarketAPI submarket : market.getSubmarketsCopy()) { | ||
submarkets.add(submarket.getSpecId()); | ||
} | ||
|
||
Collections.sort(submarkets, String.CASE_INSENSITIVE_ORDER); | ||
Console.showMessage("Existing submarkets of current market: " + CollectionUtils.implode(submarkets) + "."); | ||
return CommandResult.SUCCESS; | ||
} | ||
|
||
final String id = args; | ||
if (!market.hasSubmarket(id)) { | ||
Console.showMessage("Market '" + market.getName() + "' does not have submarket '" + id + "'!"); | ||
return CommandResult.ERROR; | ||
} | ||
|
||
market.removeSubmarket(id); | ||
Console.showMessage("Removed submarket '" + id + "' from market '" + market.getName() + "'."); | ||
return CommandResult.SUCCESS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters