Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New fares #66

Open
wants to merge 13 commits into
base: alpha
Choose a base branch
from
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,3 @@ out/production/resources/lang.yml
out/production/resources/owners.yml
out/production/resources/plugin.yml
out/production/resources/records.yml
.idea/workspace.xml
.idea/workspace.xml
23 changes: 4 additions & 19 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/main/java/mikeshafter/iciwi/CardSql.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

public class CardSql {

private final Plugin plugin = Iciwi.getPlugin(Iciwi.class);
private final Owners owners = new Owners();
private final Iciwi plugin = Iciwi.getPlugin(Iciwi.class);
private final Owners owners = plugin.owners;

private Connection connect () {
// SQLite connection string
Expand Down
120 changes: 92 additions & 28 deletions src/main/java/mikeshafter/iciwi/Commands.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mikeshafter.iciwi;

import com.bergerkiller.bukkit.common.cloud.CloudSimpleHandler;
import org.bukkit.entity.Player;
import org.incendo.cloud.annotation.specifier.Quoted;
import org.incendo.cloud.annotations.Argument;
import org.incendo.cloud.annotations.CommandDescription;
Expand Down Expand Up @@ -48,14 +49,22 @@ private String formatString(String message, String... items) {
return owners.getAllCompanies().stream().toList();
}

@Suggestions("station_list")
public List<String> suggestStationList(
@Suggestions("start_list")
public List<String> suggestStartList (
final @NonNull CommandContext<CommandSender> ctx,
final @NonNull String input
) {
return fares.getAllStations().stream().toList();
return fares.getAllStarts().stream().toList();
}

@Suggestions("fareclass_list")
public List<String> suggestClassList(
final @NonNull CommandContext<CommandSender> ctx,
final @NonNull String input
) {
return fares.getAllClasses().stream().toList();
}

@Suggestions("railpass_list")
public List<String> suggestRailPassList(
final @NonNull CommandContext<CommandSender> ctx,
Expand All @@ -64,6 +73,14 @@ public List<String> suggestRailPassList(
return owners.getAllRailPasses().stream().toList();
}

@Suggestions("player_list")
public List<String> suggestPlayerList(
final @NonNull CommandContext<CommandSender> ctx,
final @NonNull String input
) {
return plugin.getServer().getOnlinePlayers().stream().map(Player::getName).toList();
}

@Command("iciwi reload")
@CommandDescription("Reloads all configuration files")
@Permission("iciwi.reload")
Expand Down Expand Up @@ -184,7 +201,7 @@ public void closeafterpass(
public void default_fare_class(
final @NonNull CommandSender sender,
final Iciwi plugin,
final @NonNull @Argument(value = "fareclass") String c
final @NonNull @Argument(value = "fareclass", suggestions = "fareclass_list") String c
) {
plugin.getConfig().set("default-fare-class", c);
plugin.saveConfig();
Expand All @@ -198,7 +215,7 @@ public void owners_alias_set(
final @NonNull CommandSender sender,
final Iciwi plugin,
final @NonNull @Argument(value = "company", suggestions = "company_list") String company,
final @NonNull @Argument(value = "username") String username
final @NonNull @Argument(value = "username", suggestions = "player_list") String username
) {
owners.set("Aliases." + company, username);
owners.save();
Expand All @@ -224,7 +241,7 @@ public void owners_alias_unset(
public void owners_operator_add(
final @NonNull CommandSender sender,
final Iciwi plugin,
final @NonNull @Argument(value = "station", suggestions = "station_list") String station,
final @NonNull @Argument(value = "station", suggestions = "start_list") String station,
final @NonNull @Argument(value = "company", suggestions = "company_list") String company
) {
owners.addOwner(station, company);
Expand All @@ -238,7 +255,7 @@ public void owners_operator_add(
public void owners_operator_remove(
final @NonNull CommandSender sender,
final Iciwi plugin,
final @NonNull @Argument(value = "station", suggestions = "station_list") String station,
final @NonNull @Argument(value = "station", suggestions = "start_list") String station,
final @NonNull @Argument(value = "company", suggestions = "company_list") String company
) {
owners.removeOwner(station, company);
Expand All @@ -252,7 +269,7 @@ public void owners_operator_remove(
public void owners_operator_set(
final @NonNull CommandSender sender,
final Iciwi plugin,
final @NonNull @Argument(value = "station", suggestions = "station_list") String station,
final @NonNull @Argument(value = "station", suggestions = "start_list") String station,
final @NonNull @Argument(value = "company", suggestions = "company_list") String company
) {
owners.setOwners(station, Collections.singletonList(company));
Expand All @@ -266,14 +283,31 @@ public void owners_operator_set(
public void owners_operator_delete(
final @NonNull CommandSender sender,
final Iciwi plugin,
final @NonNull @Argument(value = "station", suggestions = "station_list") String station
final @NonNull @Argument(value = "station", suggestions = "start_list") String station
) {
owners.set("Operators." + station, null);
owners.save();
sender.sendMessage(formatString("No company is now operating %s.", station));
}

@Command("iciwi owners railpass <name> operator <company>")
@Command("iciwi railpass set <name> <company> <duration> <amount> <paidpercentage>")
@CommandDescription("Sets the rail company that owns the given railpass.")
@Permission("iciwi.owners.railpass")
public void owners_railpass_set(
final @NonNull CommandSender sender,
final Iciwi plugin,
final @NonNull @Argument(value = "name") String name,
final @NonNull @Argument(value = "company", suggestions = "company_list") String company,
final @NonNull @Argument(value = "duration") String duration,
final @NonNull @Argument(value = "amount") Double price,
final @NonNull @Argument(value = "paidpercentage") Double pp
) {
owners.setRailPassInfo(name, company, duration, price, pp);
owners.save();
sender.sendMessage(formatString("New rail pass created!"));
}

@Command("iciwi railpass edit <name> operator <company>")
@CommandDescription("Sets the rail company that owns the given railpass.")
@Permission("iciwi.owners.railpass")
public void owners_railpass_operator(
Expand All @@ -287,21 +321,21 @@ public void owners_railpass_operator(
sender.sendMessage(formatString("The railpass %s is now owned by %s", name, company));
}

@Command("iciwi owners railpass <name> duration <duration>")
@Command("iciwi railpass edit <name> duration <duration>")
@CommandDescription("Sets the duration that the given railpass is active.")
@Permission("iciwi.owners.railpass")
public void owners_railpass_duration(
final @NonNull CommandSender sender,
final Iciwi plugin,
final @NonNull @Argument(value = "name", suggestions = "railpass_list") String name,
final @NonNull @Argument(value = "duration") Long duration
final @NonNull @Argument(value = "duration") String duration
) {
owners.set("RailPasses." + name + ".duration", duration);
owners.save();
sender.sendMessage(formatString("The duration of railpass %s is now %s", name, String.valueOf(duration)));
sender.sendMessage(formatString("The duration of railpass %s is now %s", name, duration));
}

@Command("iciwi owners railpass <name> price <amount>")
@Command("iciwi railpass edit <name> price <amount>")
@CommandDescription("Sets the price of the given railpass.")
@Permission("iciwi.owners.railpass")
public void owners_railpass_price(
Expand All @@ -315,7 +349,7 @@ public void owners_railpass_price(
sender.sendMessage(formatString("The price of railpass %s is now %s", name, String.valueOf(price)));
}

@Command("iciwi owners railpass <name> percentage <paidpercentage>")
@Command("iciwi railpass edit <name> percentage <paidpercentage>")
@CommandDescription("Sets the percentage paid by the card holder when they use the railpass.")
@Permission("iciwi.owners.railpass")
public void owners_railpass_percentage(
Expand All @@ -329,7 +363,7 @@ public void owners_railpass_percentage(
sender.sendMessage(formatString("The payment percentage of railpass %s is now %s", name, String.valueOf(pp)));
}

@Command("iciwi owners railpass <name> delete")
@Command("iciwi railpass delete <name>")
@CommandDescription("Deletes a railpass.")
@Permission("iciwi.owners.railpass")
public void owners_railpass_delete(
Expand All @@ -342,15 +376,45 @@ public void owners_railpass_delete(
sender.sendMessage(formatString("Railpass %s has been deleted", name));
}

@Command("iciwi operatorticket <company> <price>")
@CommandDescription("Creates/deletes an operator ticket. Set <amount> to 0 for deletion.")
@Permission("iciwi.owners.railpass")
public void owners_operatorticket(
final @NonNull CommandSender sender,
final Iciwi plugin,
final @NonNull @Argument(value = "company", suggestions = "company_list") String company,
final @NonNull @Argument(value = "price") Double price
) {
owners.setOperatorTicket(company, price);
owners.save();
sender.sendMessage(formatString("Single journey tickets for %s has been set to %s.", company, String.valueOf(price)));
}

@Command("iciwi farecap <company> <amount> <duration>")
@CommandDescription("Creates/deletes a fare cap. Set <amount> to 0 for deletion.")
@Permission("iciwi.owners.railpass")
public void owners_operatorticket(
final @NonNull CommandSender sender,
final Iciwi plugin,
final @NonNull @Argument(value = "company", suggestions = "company_list") String company,
final @NonNull @Argument(value = "amount") Double amount,
final @NonNull @Argument(value = "duration") String duration
) {
owners.setFareCapAmt(company, amount);
owners.setFareCapDuration(company, duration);
owners.save();
sender.sendMessage(formatString("The fare cap for %s has been set to %s, valid for %s.", company, String.valueOf(amount), duration));
}

@Command("iciwi fares set <start> <end> <fareClass> <price>")
@CommandDescription("Creates a new fare.")
@Permission("iciwi.fares.set")
public void fares_set(
final @NonNull CommandSender sender,
final Iciwi plugin,
final @NonNull @Argument(value = "start", suggestions = "station_list") String start,
final @NonNull @Argument(value = "end", suggestions = "station_list") String end,
final @NonNull @Argument(value = "fareClass") String fareClass,
final @NonNull @Argument(value = "start", suggestions = "start_list") String start,
final @NonNull @Argument(value = "end", suggestions = "start_list") String end,
final @NonNull @Argument(value = "fareClass", suggestions = "fareclass_list") String fareClass,
final @NonNull @Argument(value = "price") Double price
) {
// Run getOwners to register station owners
Expand All @@ -365,9 +429,9 @@ public void fares_set(
public void fares_check(
final @NonNull CommandSender sender,
final Iciwi plugin,
final @NonNull @Argument(value = "start", suggestions = "station_list") String start,
final @Argument(value = "end", suggestions = "station_list") String end,
final @Argument(value = "fareClass") @Quoted String fareClass
final @NonNull @Argument(value = "start", suggestions = "start_list") String start,
final @Argument(value = "end", suggestions = "start_list") String end,
final @Argument(value = "fareClass", suggestions = "fareclass_list") String fareClass
) {
Set<String> s;
if (end == null) s = fares.getDestinations(start);
Expand All @@ -383,9 +447,9 @@ public void fares_check(
public void fares_unset(
final @NonNull CommandSender sender,
final Iciwi plugin,
final @NonNull @Argument(value = "start", suggestions = "station_list") String start,
final @NonNull @Argument(value = "end", suggestions = "station_list") String end,
final @NonNull @Argument(value = "fareClass") String fareClass
final @NonNull @Argument(value = "start", suggestions = "start_list") String start,
final @NonNull @Argument(value = "end", suggestions = "start_list") String end,
final @NonNull @Argument(value = "fareClass", suggestions = "fareclass_list") String fareClass
) {
fares.unsetFare(start, end, fareClass);
sender.sendMessage(formatString("The fare from %s to %s using the class %s has been deleted.", start, end, fareClass));
Expand All @@ -397,8 +461,8 @@ public void fares_unset(
public void delete_journey (
final @NonNull CommandSender sender,
final Iciwi plugin,
final @NonNull @Argument(value = "start", suggestions = "station_list") String start,
final @NonNull @Argument(value = "end", suggestions = "station_list") String end
final @NonNull @Argument(value = "start", suggestions = "start_list") String start,
final @NonNull @Argument(value = "end", suggestions = "start_list") String end
) {
fares.deleteJourney(start, end);
sender.sendMessage(formatString("All fares from %s to %s has been deleted.", start, end));
Expand All @@ -410,7 +474,7 @@ public void delete_journey (
public void delete_station(
final @NonNull CommandSender sender,
final Iciwi plugin,
final @NonNull @Argument(value = "start", suggestions = "station_list") String start
final @NonNull @Argument(value = "start", suggestions = "start_list") String start
) {
fares.deleteStation(start);
sender.sendMessage(formatString("All fares to all stations from %s has been deleted.", start));
Expand Down
Loading
Loading