diff --git a/.gitignore b/.gitignore
index 7492675..b772820 100644
--- a/.gitignore
+++ b/.gitignore
@@ -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
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index a9efa54..b421ef3 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,26 +4,10 @@
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
@@ -388,7 +372,8 @@
-
+
+
diff --git a/src/main/java/mikeshafter/iciwi/CardSql.java b/src/main/java/mikeshafter/iciwi/CardSql.java
index bfbf885..b0c4bd8 100644
--- a/src/main/java/mikeshafter/iciwi/CardSql.java
+++ b/src/main/java/mikeshafter/iciwi/CardSql.java
@@ -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
diff --git a/src/main/java/mikeshafter/iciwi/Commands.java b/src/main/java/mikeshafter/iciwi/Commands.java
index d1b489f..4b87057 100644
--- a/src/main/java/mikeshafter/iciwi/Commands.java
+++ b/src/main/java/mikeshafter/iciwi/Commands.java
@@ -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;
@@ -48,14 +49,22 @@ private String formatString(String message, String... items) {
return owners.getAllCompanies().stream().toList();
}
- @Suggestions("station_list")
- public List suggestStationList(
+ @Suggestions("start_list")
+ public List suggestStartList (
final @NonNull CommandContext ctx,
final @NonNull String input
) {
- return fares.getAllStations().stream().toList();
+ return fares.getAllStarts().stream().toList();
}
+@Suggestions("fareclass_list")
+public List suggestClassList(
+ final @NonNull CommandContext ctx,
+ final @NonNull String input
+) {
+ return fares.getAllClasses().stream().toList();
+}
+
@Suggestions("railpass_list")
public List suggestRailPassList(
final @NonNull CommandContext ctx,
@@ -64,6 +73,14 @@ public List suggestRailPassList(
return owners.getAllRailPasses().stream().toList();
}
+@Suggestions("player_list")
+public List suggestPlayerList(
+ final @NonNull CommandContext 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")
@@ -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();
@@ -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();
@@ -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);
@@ -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);
@@ -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));
@@ -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 operator ")
+@Command("iciwi railpass set ")
+@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 operator ")
@CommandDescription("Sets the rail company that owns the given railpass.")
@Permission("iciwi.owners.railpass")
public void owners_railpass_operator(
@@ -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 duration ")
+ @Command("iciwi railpass edit 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 price ")
+ @Command("iciwi railpass edit price ")
@CommandDescription("Sets the price of the given railpass.")
@Permission("iciwi.owners.railpass")
public void owners_railpass_price(
@@ -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 percentage ")
+ @Command("iciwi railpass edit percentage ")
@CommandDescription("Sets the percentage paid by the card holder when they use the railpass.")
@Permission("iciwi.owners.railpass")
public void owners_railpass_percentage(
@@ -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 delete")
+ @Command("iciwi railpass delete ")
@CommandDescription("Deletes a railpass.")
@Permission("iciwi.owners.railpass")
public void owners_railpass_delete(
@@ -342,15 +376,45 @@ public void owners_railpass_delete(
sender.sendMessage(formatString("Railpass %s has been deleted", name));
}
+@Command("iciwi operatorticket ")
+@CommandDescription("Creates/deletes an operator ticket. Set 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 ")
+@CommandDescription("Creates/deletes a fare cap. Set 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 ")
@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
@@ -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 s;
if (end == null) s = fares.getDestinations(start);
@@ -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));
@@ -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));
@@ -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));
diff --git a/src/main/java/mikeshafter/iciwi/Iciwi.java b/src/main/java/mikeshafter/iciwi/Iciwi.java
index 2581109..9cb8c18 100644
--- a/src/main/java/mikeshafter/iciwi/Iciwi.java
+++ b/src/main/java/mikeshafter/iciwi/Iciwi.java
@@ -21,19 +21,25 @@
public final class Iciwi extends JavaPlugin implements IciwiPlugin {
public static Economy economy = null;
-public Lang lang = new Lang();
-public Owners owners = new Owners();
-public Records records = new Records();
-public Fares fares = new Fares();
+public Lang lang;
+public Owners owners;
+public Records records;
+public Fares fares;
public void sendAll (String message) {getServer().getOnlinePlayers().forEach(p -> p.sendMessage(message));}
private void loadAllConfig () {
+ lang = new Lang();
+ owners = new Owners();
+ records = new Records();
+ fares = new Fares();
+
+ this.saveDefaultConfig();
this.getConfig().options().copyDefaults(true);
- this.lang.get().options().copyDefaults(true);
- this.owners.get().options().copyDefaults(true);
- this.records.get().options().copyDefaults(true);
- this.fares.get().options().copyDefaults(true);
+ lang.get().options().copyDefaults(true);
+ owners.get().options().copyDefaults(true);
+ records.get().options().copyDefaults(true);
+ fares.get().options().copyDefaults(true);
}
public void reloadAllConfig () {
@@ -67,7 +73,7 @@ private void registerEvents () {
}
private void registerStations () {
- Set stations = fares.getAllStations();
+ Set stations = fares.getAllStarts();
if (stations != null) stations.forEach(station -> owners.getOwners(station));
}
@@ -84,7 +90,7 @@ private boolean canStart () {
for (byte i = 0; i < 32; i++) {
if (h[i] != b[i]) {
this.getLogger().warning("YOU ARE USING A PIRATED VERSION OF ICIWI. SHUTTING DOWN... ");
- s.dispatchCommand(getServer().getConsoleSender(), "discord bcast \u210d\ud835\udd56\ud835\udd6a \ud835\udd65\ud835\udd59\ud835\udd56\ud835\udd63\ud835\udd56! \ud835\udd4b\ud835\udd59\ud835\udd56 \ud835\udd64\ud835\udd56\ud835\udd63\ud835\udd67\ud835\udd56\ud835\udd63 \ud835\udd60\ud835\udd68\ud835\udd5f\ud835\udd56\ud835\udd63 \ud835\udd5a\ud835\udd64 \ud835\udd52 \ud835\udd61\ud835\udd5a\ud835\udd63\ud835\udd52\ud835\udd65\ud835\udd56! \ud835\udc03\ud835\udc04\ud835\udc0b\ud835\udc04\ud835\udc13\ud835\udc04 \ud835\udc08\ud835\udc02\ud835\udc08\ud835\udc16\ud835\udc08 \ud835\udc08\ud835\udc0c\ud835\udc0c\ud835\udc04\ud835\udc03\ud835\udc08\ud835\udc00\ud835\udc13\ud835\udc04\ud835\udc0b\ud835\udc18 \ud835\udc0e\ud835\udc11 \ud835\udc05\ud835\udc00\ud835\udc02\ud835\udc04 \ud835\udc02\ud835\udc0e\ud835\udc0d\ud835\udc12\ud835\udc04\ud835\udc10\ud835\udc14\ud835\udc04\ud835\udc0d\ud835\udc02\ud835\udc04\ud835\udc12!");
+ s.dispatchCommand(getServer().getConsoleSender(), "discord bcast ℍ\ud835\udd56\ud835\udd6a \ud835\udd65\ud835\udd59\ud835\udd56\ud835\udd63\ud835\udd56! \ud835\udd4b\ud835\udd59\ud835\udd56 \ud835\udd64\ud835\udd56\ud835\udd63\ud835\udd67\ud835\udd56\ud835\udd63 \ud835\udd60\ud835\udd68\ud835\udd5f\ud835\udd56\ud835\udd63 \ud835\udd5a\ud835\udd64 \ud835\udd52 \ud835\udd61\ud835\udd5a\ud835\udd63\ud835\udd52\ud835\udd65\ud835\udd56! \ud835\udc03\ud835\udc04\ud835\udc0b\ud835\udc04\ud835\udc13\ud835\udc04 \ud835\udc08\ud835\udc02\ud835\udc08\ud835\udc16\ud835\udc08 \ud835\udc08\ud835\udc0c\ud835\udc0c\ud835\udc04\ud835\udc03\ud835\udc08\ud835\udc00\ud835\udc13\ud835\udc04\ud835\udc0b\ud835\udc18 \ud835\udc0e\ud835\udc11 \ud835\udc05\ud835\udc00\ud835\udc02\ud835\udc04 \ud835\udc02\ud835\udc0e\ud835\udc0d\ud835\udc12\ud835\udc04\ud835\udc10\ud835\udc14\ud835\udc04\ud835\udc0d\ud835\udc02\ud835\udc04\ud835\udc12!");
s.shutdown();
return false;
}
diff --git a/src/main/java/mikeshafter/iciwi/config/CustomConfig.java b/src/main/java/mikeshafter/iciwi/config/CustomConfig.java
index 78ea1e4..198eebf 100644
--- a/src/main/java/mikeshafter/iciwi/config/CustomConfig.java
+++ b/src/main/java/mikeshafter/iciwi/config/CustomConfig.java
@@ -51,6 +51,7 @@ public YamlConfiguration get () {
return config;
}
+
/**
* @see YamlConfiguration#get(String)
*/
diff --git a/src/main/java/mikeshafter/iciwi/config/Fares.java b/src/main/java/mikeshafter/iciwi/config/Fares.java
index 26370eb..83396c1 100644
--- a/src/main/java/mikeshafter/iciwi/config/Fares.java
+++ b/src/main/java/mikeshafter/iciwi/config/Fares.java
@@ -1,111 +1,114 @@
package mikeshafter.iciwi.config;
-import mikeshafter.iciwi.Iciwi;
import org.bukkit.configuration.ConfigurationSection;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeMap;
-
+import java.util.*;
+// New fares: ..
public class Fares extends CustomConfig {
public Fares () {super("fares.yml");}
-public Set getAllStations () {return this.get().getKeys(false);}
+public Set getAllClasses () {return this.get().getKeys(false);}
/**
Remove a fare from fares.yml
- @param from Starting station
- @param to Ending station
- @param fareClass Fare class
+ @param f Starting station
+ @param e Ending station
+ @param c Fare class
*/
-public void unsetFare (String from, String to, String fareClass) {
- super.set(from + "." + to + "." + fareClass, null);
+public void unsetFare (String f, String e, String c) {
+ super.set(toPath(c, f, e), null);
super.save();
}
/**
- Remove all fares between two stations from fares.yml
- @param from Starting station
- @param to Ending station
+ Remove all fares from a station given a fare class
+ @param c fare class
+ @param f starting station
*/
-public void deleteJourney (String from, String to) {
- super.set(from + "." + to, null);
+public void deleteStationFromClass (String c, String f) {
+ super.set(toPath(c, f), null);
super.save();
}
/**
- Remove all fares starting from a specified station from fares.yml
- @param station Station
+ Remove all fares belonging to a fare class.
+ @param c fare class
*/
-public void deleteStation (String station) {
- super.set(station, null);
+public void deleteClass (String c) {
+ super.set(c, null);
super.save();
}
/**
- Set a fare to fares.yml
- @param from Starting station
- @param to Ending station
- @param fareClass Fare class
- @param price Price to set
+ Remove all fares between two stations from fares.yml
+ @param f Starting station
+ @param e Ending station
*/
-public void setFare (String from, String to, String fareClass, double price) {
- super.set(from + "." + to + "." + fareClass, price);
+public void deleteJourney (String f, String e) {
+ for (var c : getAllClasses())
+ super.set(toPath(c, f, e), null);
super.save();
}
/**
- Get the corresponding fare if the player pays by card
- @param from Starting station
- @param to Ending station
- @param fareClassNoUnderscore Fare class, without the starting underscore
- @return Fare
+ Remove all fares starting from a specified station from fares.yml
+ @param f Station
*/
-public double getCardFare (String from, String to, String fareClassNoUnderscore) {
- if (fareClassNoUnderscore.indexOf("_") == 0) fareClassNoUnderscore = fareClassNoUnderscore.substring(1);
- final double fare = this.getDouble(from + "." + to + "._" + fareClassNoUnderscore);
- if (fare == 0d) return this.getDouble(from + "." + to + "." + fareClassNoUnderscore);
- else return fare;
+public void deleteStation (String f) {
+ for (var c : getAllClasses())
+ super.set(toPath(c, f), null);
+ super.save();
}
/**
- Get the corresponding fare if the player pays by cash
- @param from Starting station
- @param to Ending station
- @param fareClass Fare class
- @return Fare
+ Set a fare to fares.yml
+ @param f Starting station
+ @param e Ending station
+ @param c Fare class
+ @param price Price to set
*/
-public double getFare (String from, String to, String fareClass) {return this.getDouble(from + "." + to + "." + fareClass);}
+public void setFare (String f, String e, String c, double price) {
+ super.set(toPath(c, f, e), price);
+ super.save();
+}
/**
- Get the corresponding fare using the default train class
- @param from Starting station
- @param to Ending station
+ Get the corresponding fare if the player pays by card
+ @param f Starting station
+ @param e Ending station
+ @param cSans_ Fare class, without the starting underscore
@return Fare
*/
-@Deprecated public double getFare (String from, String to) {return getFare(from, to, Iciwi.getPlugin(Iciwi.class).getConfig().getString("default-class"));}
+public double getCardFare (String f, String e, String cSans_) {
+ if (cSans_.indexOf("_") == 0) cSans_ = cSans_.substring(1);
+ final double fare = this.getDouble(toPath("_" + cSans_, f, e));
+ if (fare == 0d) return this.getDouble(toPath(cSans_, f, e));
+ else return fare;
+}
/**
- Get all fares starting from a certain station
- @param station Starting station
+ Get the corresponding fare if the player pays by cash
+ @param f Starting station
+ @param e Ending station
+ @param c Fare class
@return Fare
*/
-@Deprecated public Map getFares (String station) {return getFares(station, Iciwi.getPlugin(Iciwi.class).getConfig().getString("default-class"));}
+public double getFare (String f, String e, String c) {return this.getDouble(toPath(c, f, e));}
/**
Get all fares starting from a certain station, with the specified class
- @param from Starting station
- @param fareClass Fare class
- @return Fare
+ @param f Starting station
+ @param c Fare class
+ @return A treemap in the format ENDPOINT, PRICE
*/
-public Map getFares (String from, String fareClass) {
- ConfigurationSection section = this.get().getConfigurationSection(from);
+public TreeMap getFares (String f, String c) {
+ ConfigurationSection section = this.getConfigurationSection(toPath(c, f));
if (section != null) {
- var fareMap = new HashMap();
- section.getKeys(false).forEach(to -> fareMap.put(to, this.getDouble(from + "." + to + "." + fareClass)));
+ var fareMap = new TreeMap();
+
+ section.getKeys(false).forEach(e -> fareMap.put(e, section.getDouble(e, 0d)));
return fareMap;
}
else return null;
@@ -113,39 +116,56 @@ public Map getFares (String from, String fareClass) {
/**
Get all fares starting from a certain station and ending at another station.
- @param from Starting station
- @param to Ending station
+ @param f Starting station
+ @param e Ending station
@return Fare
*/
-public TreeMap getFaresFromDestinations (String from, String to) {
- ConfigurationSection section = this.get().getConfigurationSection(from + "." + to);
- if (section != null) {
- var fareMap = new TreeMap();
-
- section.getKeys(false).forEach(fareClass -> fareMap.put(fareClass, this.getDouble(from + "." + to + "." + fareClass)));
- return fareMap;
+public TreeMap getFaresFromDestinations (String f, String e) {
+ var fareMap = new TreeMap();
+ for (var c : getAllClasses()) {
+ if (getFare(f, e, c) > 0d)
+ fareMap.put(c, getFare(f, e, c));
}
- else return null;
+ return fareMap;
}
/**
Get all fare classes starting from a certain station and ending at another station.
- @param from Starting station
- @param to Ending station
+ @param f Starting station
+ @param e Ending station
@return Fare classes
*/
-public Set getClasses (String from, String to) {
- ConfigurationSection section = this.get().getConfigurationSection(from + "." + to);
- return section == null ? null : section.getKeys(false);
+public TreeSet getClasses (String f, String e) {
+ var set = new TreeSet();
+ for (var c : getAllClasses()) {
+ if (getFare(f, e, c) > 0d)
+ set.add(c);
+ }
+ return set;
}
/**
Get all end stations starting from a certain station.
- @param from Starting station
+ @param f Starting station
@return Fare classes
*/
-public Set getDestinations (String from) {
- ConfigurationSection section = this.get().getConfigurationSection(from);
- return section == null ? null : section.getKeys(false);
+public TreeSet getDestinations (String f) {
+ var set = new TreeSet();
+ for (var c : getAllClasses()) {
+ set.addAll(super.getConfigurationSection(toPath(c, f)).getKeys(false));
+ }
+ return set;
+}
+
+/**
+ Get all starting stations starting from a certain station.
+ @return All starting stations
+ */
+public Set getAllStarts () {
+ var set = new TreeSet();
+ for (var c : getAllClasses()) {
+ set.addAll(super.getConfigurationSection(c).getKeys(false));
+ }
+ return set;
}
}
diff --git a/src/main/java/mikeshafter/iciwi/config/Lang.java b/src/main/java/mikeshafter/iciwi/config/Lang.java
index 8e71b9b..e007c9a 100644
--- a/src/main/java/mikeshafter/iciwi/config/Lang.java
+++ b/src/main/java/mikeshafter/iciwi/config/Lang.java
@@ -1,5 +1,6 @@
package mikeshafter.iciwi.config;
import net.kyori.adventure.text.Component;
+import org.jetbrains.annotations.NotNull;
public class Lang extends CustomConfig {
public Lang () {super("lang.yml");}
@@ -7,7 +8,7 @@ public Component getComponent (String path) {
var s = super.getString(path);
return s.isEmpty() ? Component.text("Error: No text input for path: " + path) : Component.text(s);
}
-@Override public String getString (String path) {
+@Override public String getString (@NotNull String path) {
var s = super.getString(path);
return s.isEmpty() ? "Error: No text input for path: " + path : s;
}
diff --git a/src/main/java/mikeshafter/iciwi/config/Owners.java b/src/main/java/mikeshafter/iciwi/config/Owners.java
index 6b69be6..203d80d 100644
--- a/src/main/java/mikeshafter/iciwi/config/Owners.java
+++ b/src/main/java/mikeshafter/iciwi/config/Owners.java
@@ -223,4 +223,44 @@ public List getOwnedCompanies (String player) {
@param price The price of a company-wide ticket
*/
public void setOperatorTicket (String operator, double price) { super.set("TicketType."+operator, price); }
+
+/**
+ * Gets the fare cap of a company
+ *
+ * @param operator Name of the company
+ * @return the maximum amount in which a card can pay for a given duration
+ */
+public double getFareCapAmt (String operator) {return super.getDouble("Caps." + operator + "amount");}
+
+/**
+ * Gets the duration of the fare cap of a company
+ *
+ * @param operator Name of the company
+ * @return the duration in which the fare cap is active
+ */
+public String getFareCapDuration (String operator) {return super.getString("Caps." + operator + "duration");}
+
+/**
+ * Gets whether a company has a fare cap
+ *
+ * @param operator Name of the company
+ * @return true if a fare cap exists
+ */
+public boolean hasFareCap (String operator) {return super.getDouble("Caps." + operator + "amount") > 0;}
+
+/**
+ * Sets the amount capped for a company
+ *
+ * @param operator Name of the company
+ * @param amt the maximum amount in which a card can pay for a given duration
+ */
+public void setFareCapAmt (String operator, double amt) {super.set("Caps." + operator + "amount", amt);}
+
+/**
+ * Sets the duration of the fare cap of a company
+ *
+ * @param operator Name of the company
+ * @param duration the duration in which the fare cap is active
+ */
+public void setFareCapDuration (String operator, String duration) {super.set("Caps." + operator + "duration", duration);}
}
diff --git a/src/main/java/mikeshafter/iciwi/config/Records.java b/src/main/java/mikeshafter/iciwi/config/Records.java
index 06417b9..1e4457d 100644
--- a/src/main/java/mikeshafter/iciwi/config/Records.java
+++ b/src/main/java/mikeshafter/iciwi/config/Records.java
@@ -2,124 +2,154 @@
public class Records extends CustomConfig {
-public Records () { super("records.yml"); }
+public Records () {super("records.yml");}
/**
- Get the station at which the card entered the transit system.
- This is used on both entry and exit.
-
- @param serial Serial number of card
- @return The station at which the card entered the transit system. */
-public String getStation (String serial) { return super.getString(serial + ".station"); }
+ * Get the station at which the card entered the transit system.
+ * This is used on both entry and exit.
+ *
+ * @param serial Serial number of card
+ * @return The station at which the card entered the transit system.
+ */
+public String getStation (String serial) {return super.getString(serial + ".station");}
/**
- Set the station at which the card entered the transit system.
- This is used on both entry and exit.
- This should only be set to a non-null value when the card is in the transit system. Otherwise, set it to null.
-
- @param serial Serial number of card
- @param station Station to set */
+ * Set the station at which the card entered the transit system.
+ * This is used on both entry and exit.
+ * This should only be set to a non-null value when the card is in the transit system. Otherwise, set it to null.
+ *
+ * @param serial Serial number of card
+ * @param station Station to set
+ */
public void setStation (String serial, String station) {
super.set(serial + ".station", station);
super.save();
}
/**
- Get the fare class of the journey taken by the card
- This is used on exit
-
- @param serial Serial number of card
- @return the fare class of the journey taken by the card */
+ * Get the fare class of the journey taken by the card
+ * This is used on exit
+ *
+ * @param serial Serial number of card
+ * @return the fare class of the journey taken by the card
+ */
public String getClass (String serial) {
String c = super.getString(serial + ".fareclass");
- if (c.isEmpty()) return plugin.getConfig().getString("default-class");
- else return c;
+ if (c.isEmpty()) {return plugin.getConfig().getString("default-class");}
+ else {return c;}
}
/**
- Set the fare class of the journey taken by the card
- This is used on entry
-
- @param serial Serial number of card
- @param fareClass the fare class of the journey taken by the card */
+ * Set the fare class of the journey taken by the card
+ * This is used on entry
+ *
+ * @param serial Serial number of card
+ * @param fareClass the fare class of the journey taken by the card
+ */
public void setClass (String serial, String fareClass) {
super.set(serial + ".fareclass", fareClass);
super.save();
}
/**
- Get the entry station of the previous journey
- This is used on exit
-
- @param serial Serial number of card
- @return the station at which the card entered the transit system on the previous journey */
-public String getPreviousStation (String serial) { return super.getString(serial + ".previous-station"); }
+ * Get the entry station of the previous journey
+ * This is used on exit
+ *
+ * @param serial Serial number of card
+ * @return the station at which the card entered the transit system on the previous journey
+ */
+public String getPreviousStation (String serial) {return super.getString(serial + ".previous-station");}
/**
- Set the entry station of the previous journey
- This is used on exit
-
- @param serial Serial number of card
- @param station the station at which the card entered the transit system on the previous journey */
+ * Set the entry station of the previous journey
+ * This is used on exit
+ *
+ * @param serial Serial number of card
+ * @param station the station at which the card entered the transit system on the previous journey
+ */
public void setPreviousStation (String serial, String station) {
super.set(serial + ".previous-station", station);
super.save();
}
/**
- Gets whether the card is eligible for a transfer discount on exit
- This is used on entry
-
- @param serial Serial number of card
- @return true if the card is eligible for a transfer discount at the end of the journey */
-public boolean getTransfer (String serial) { return super.getBoolean(serial + ".has-transfer"); }
+ * Gets whether the card is eligible for a transfer discount on exit
+ * This is used on entry
+ *
+ * @param serial Serial number of card
+ * @return true if the card is eligible for a transfer discount at the end of the journey
+ */
+public boolean getTransfer (String serial) {return super.getBoolean(serial + ".has-transfer");}
/**
- Sets whether the card is eligible for a transfer discount on exit.
- This is used on entry
-
- @param serial Serial number of card
- @param hasTransfer true if the card is eligible for a transfer discount at the end of the journey */
+ * Sets whether the card is eligible for a transfer discount on exit.
+ * This is used on entry
+ *
+ * @param serial Serial number of card
+ * @param hasTransfer true if the card is eligible for a transfer discount at the end of the journey
+ */
public void setTransfer (String serial, boolean hasTransfer) {
super.set(serial + ".has-transfer", hasTransfer);
super.save();
}
/**
- Gets the exit timestamp of the previous journey.
- This is used on entry
-
- @param serial Serial number of card
- @return The timestamp of the previous time the card was used to exit the transit system. */
-public long getTimestamp (String serial) { return super.getLong(serial + ".timestamp"); }
+ * Gets the exit timestamp of the previous journey.
+ * This is used on entry
+ *
+ * @param serial Serial number of card
+ * @return The timestamp of the previous time the card was used to exit the transit system.
+ */
+public long getTimestamp (String serial) {return super.getLong(serial + ".timestamp");}
/**
- Writes the last exit time to the records file.
- This is used on exit
-
- @param serial Serial number of card
- @param timestamp The timestamp at which the card was used to exit the transit system. */
+ * Writes the last exit time to the records file.
+ * This is used on exit
+ *
+ * @param serial Serial number of card
+ * @param timestamp The timestamp at which the card was used to exit the transit system.
+ */
public void setTimestamp (String serial, long timestamp) {
super.set(serial + ".timestamp", timestamp);
super.save();
}
/**
- Gets the price of the previous journey.
- This is used on exit
-
- @param serial Serial number of card
- @return the final price of the previous journey */
+ * Gets the price of the previous journey.
+ * This is used on exit
+ *
+ * @param serial Serial number of card
+ * @return the final price of the previous journey
+ */
public double getCurrentFare (String serial) {return super.getDouble(serial + ".current-fare");}
/**
- Writes the price of the journey to the records file
- This is used on exit
-
- @param serial Serial number of card
- @param fare The final fare of the journey */
+ * Writes the price of the journey to the records file
+ * This is used on exit
+ *
+ * @param serial Serial number of card
+ * @param fare The final fare of the journey
+ */
public void setCurrentFare (String serial, double fare) {
super.set(serial + ".current-fare", fare);
super.save();
}
+
+public long getCapExpiry (String serial, String operator) {
+ return super.getLong(toPath(serial, operator, "expiry"));
+}
+
+public double getCapRemAmt (String serial, String operator) {
+ return super.getDouble(toPath(serial, operator, "rem-amt"));
+}
+
+public void setCapExpiry (String serial, String operator, long exp) {
+ super.set(toPath(serial, operator, "expiry"), exp);
+ super.save();
+}
+
+public void setCapRemAmt (String serial, String operator, double amt) {
+ super.set(toPath(serial, operator, "rem-amt"), amt);
+ super.save();
+}
}
diff --git a/src/main/java/mikeshafter/iciwi/faregate/CardUtil.java b/src/main/java/mikeshafter/iciwi/faregate/CardUtil.java
index e1cce69..07328b9 100644
--- a/src/main/java/mikeshafter/iciwi/faregate/CardUtil.java
+++ b/src/main/java/mikeshafter/iciwi/faregate/CardUtil.java
@@ -21,12 +21,12 @@
import org.bukkit.util.Vector;
public class CardUtil {
-static final Iciwi plugin = Iciwi.getPlugin(Iciwi.class);
-static final Records records = new Records();
-static final Lang lang = new Lang();
-static final Owners owners = new Owners();
-static final CardSql cardSql = new CardSql();
-static final LinkedHashSet clickBuffer = new LinkedHashSet<>();
+private static final Iciwi plugin = Iciwi.getPlugin(Iciwi.class);
+private static final Records records = plugin.records;
+private static final Lang lang = plugin.lang;
+private static final Owners owners = plugin.owners;
+private static final CardSql cardSql = new CardSql();
+private static final LinkedHashSet clickBuffer = new LinkedHashSet<>();
/**
Prevent code from registering multiple accidental clicks
@@ -105,7 +105,7 @@ protected static boolean entry (Player player, IcCard icCard, String entryStatio
protected static boolean exit (Player player, IcCard icCard, String exitStation, Location signLocation) {
if (onClick(player)) return false;
- Fares fares = new Fares();
+ Fares fares = plugin.fares;
String serial = icCard.getSerial();
// don't parse if there is no serial
@@ -162,8 +162,17 @@ protected static boolean exit (Player player, IcCard icCard, String exitStation,
return false;
}
+ // Check for fare caps
+
+ //TODO: check each owner for their respective fare caps
+ // if an owner has a fare cap, and records.yml says that the fare cap has not been reached, deposit into the TOC's coffer
+ // if the fare cap has been reached, do not deposit into the TOC's coffer, and remove that amount of money from the final fare.
+
// withdraw fare from card
- icCard.withdraw(fare);
+ if (!icCard.withdraw(fare)) {
+ player.sendMessage("Error tapping out");
+ return false;
+ }
// set details for future transfer
records.setTimestamp(serial, System.currentTimeMillis());
@@ -238,9 +247,12 @@ protected static boolean member (Player player, IcCard icCard, String station, L
protected static boolean transfer (Player player, IcCard icCard, String station, Location signLocation) {
if (onClick(player)) return false;
- Fares fares = new Fares();
+ Fares fares = plugin.fares;
String serial = icCard.getSerial();
+ // don't parse if there is no serial
+ if (serial == null || serial.isEmpty() || serial.isBlank()) return false;
+
// If an OSI was detected, cancel OSI capability
if (records.getTransfer(serial)) {
records.setTransfer(serial, false);
@@ -254,14 +266,16 @@ protected static boolean transfer (Player player, IcCard icCard, String station,
double value = icCard.getValue();
double fare = fares.getCardFare(entryStation, station, records.getClass(serial));
- // is the card already in the network?
+ // is the card not in the network?
if (records.getStation(serial).isEmpty()) {
- player.sendMessage(lang.getString("cannot-pass"));
if (plugin.getConfig().getBoolean("open-on-penalty")) {
Iciwi.economy.withdrawPlayer(player, plugin.getConfig().getDouble("penalty"));
player.sendMessage(lang.getString("fare-evade"));
}
- else return false;
+ else {
+ player.sendMessage(lang.getString("cannot-pass"));
+ return false;
+ }
}
// Get the owners of stations and rail passes
@@ -286,7 +300,11 @@ protected static boolean transfer (Player player, IcCard icCard, String station,
player.sendMessage(lang.getString("value-low"));
return false;
}
- icCard.withdraw(fare);
+
+ if (!icCard.withdraw(fare)) {
+ player.sendMessage("Error tapping out");
+ return false;
+ }
// set details for future transfer
records.setTimestamp(serial, System.currentTimeMillis());
@@ -374,7 +392,6 @@ protected static Object[] openGate (String signAction, String[] signText, Sign s
openable.setOpen(false);
currentBlock.setBlockData(openable);
};
-
}
// If powerable, power it!
@@ -409,6 +426,7 @@ else if (currentBlock.getBlockData() instanceof Fence || currentBlock.getBlockDa
}
return closeGate;
}
+
private static int getFlags (String signAction, String signLine0) {
String args;
if (signAction.length() == signLine0.length()) args = "";
diff --git a/src/main/java/mikeshafter/iciwi/faregate/ClassChange.java b/src/main/java/mikeshafter/iciwi/faregate/ClassChange.java
index 63a50f1..2cc81a4 100644
--- a/src/main/java/mikeshafter/iciwi/faregate/ClassChange.java
+++ b/src/main/java/mikeshafter/iciwi/faregate/ClassChange.java
@@ -15,7 +15,7 @@
public class ClassChange extends FareGate {
private final Iciwi plugin = Iciwi.getPlugin(Iciwi.class);
-private final Lang lang = new Lang();
+private final Lang lang = plugin.lang;
public ClassChange() {
super();
@@ -37,7 +37,7 @@ public void onInteract(Player player, ItemStack item, String[] signText, Sign si
IcCard icCard = IciwiUtil.IcCardFromItem(item);
if (icCard != null) {
String serial = icCard.getSerial();
- final Records records = new Records();
+ final Records records = plugin.records;
records.setClass(serial, newClass);
player.sendMessage(String.format(lang.getString("class-changed"), newClass));
player.playSound(player, plugin.getConfig().getString("classchange-noise", "minecraft:entity.allay.item_thrown"), SoundCategory.MASTER, 1f, 1f);
diff --git a/src/main/java/mikeshafter/iciwi/faregate/Entry.java b/src/main/java/mikeshafter/iciwi/faregate/Entry.java
index 8613f9d..cc817b8 100644
--- a/src/main/java/mikeshafter/iciwi/faregate/Entry.java
+++ b/src/main/java/mikeshafter/iciwi/faregate/Entry.java
@@ -18,8 +18,8 @@
public class Entry extends ClosableFareGate {
private final Iciwi plugin = Iciwi.getPlugin(Iciwi.class);
-private final Lang lang = new Lang();
-private final Owners owners = new Owners();
+private final Lang lang = plugin.lang;
+private final Owners owners = plugin.owners;
private static final CardSql cardSql = new CardSql();
public Entry() {
diff --git a/src/main/java/mikeshafter/iciwi/faregate/Exit.java b/src/main/java/mikeshafter/iciwi/faregate/Exit.java
index 3f9dd41..9e2ab1e 100644
--- a/src/main/java/mikeshafter/iciwi/faregate/Exit.java
+++ b/src/main/java/mikeshafter/iciwi/faregate/Exit.java
@@ -18,8 +18,8 @@
public class Exit extends ClosableFareGate {
private final Iciwi plugin = Iciwi.getPlugin(Iciwi.class);
-private final Lang lang = new Lang();
-private final Owners owners = new Owners();
+private final Lang lang = plugin.lang;
+private final Owners owners = plugin.owners;
private static final CardSql cardSql = new CardSql();
public Exit() {
@@ -57,7 +57,7 @@ else if ((entryPunched || !entryPunchRequired) && (lore.get(1).equals(station) |
// Log exit
String entryStation = lore.get(0).replace(" •", "");
String fareClass = lore.get(2);
- Fares fares = new Fares();
+ Fares fares = plugin.fares;
cardSql.logMaster(player.getUniqueId().toString());
cardSql.logExit(sign.getLocation().getBlockX(), sign.getLocation().getBlockY(), sign.getLocation().getBlockZ(), entryStation, station);
diff --git a/src/main/java/mikeshafter/iciwi/faregate/Member.java b/src/main/java/mikeshafter/iciwi/faregate/Member.java
index 49de0d5..2713834 100644
--- a/src/main/java/mikeshafter/iciwi/faregate/Member.java
+++ b/src/main/java/mikeshafter/iciwi/faregate/Member.java
@@ -17,8 +17,8 @@
public class Member extends ClosableFareGate {
private final Iciwi plugin = Iciwi.getPlugin(Iciwi.class);
-private final Lang lang = new Lang();
-private final Owners owners = new Owners();
+private final Lang lang = plugin.lang;
+private final Owners owners = plugin.owners;
private final CardSql cardSql = new CardSql();
public Member() {
diff --git a/src/main/java/mikeshafter/iciwi/faregate/Payment.java b/src/main/java/mikeshafter/iciwi/faregate/Payment.java
index f60d039..14f2d3d 100644
--- a/src/main/java/mikeshafter/iciwi/faregate/Payment.java
+++ b/src/main/java/mikeshafter/iciwi/faregate/Payment.java
@@ -14,7 +14,7 @@
public class Payment extends FareGate {
private final Iciwi plugin = Iciwi.getPlugin(Iciwi.class);
- private final Lang lang = new Lang();
+ private final Lang lang = plugin.lang;
public Payment() {
super();
@@ -39,10 +39,16 @@ public void onInteract(Player player, ItemStack item, String[] signText, Sign si
// Try paying with card
IcCard icCard = IciwiUtil.IcCardFromItem(item);
- if (icCard != null) payCard(icCard, player, price);
+ if (icCard != null && icCard.withdraw(price)) {
+ player.sendMessage(String.format(lang.getString("pay-success-card"), price, icCard.getValue()));
+ }
// If there is no card, pay with cash
- else payCash(player, price);
+ else {
+ Iciwi.economy.withdrawPlayer(player, price);
+ player.sendMessage(lang.getString("cash-divert"));
+ player.sendMessage(String.format(lang.getString("pay-success"), price));
+ }
player.playSound(player, plugin.getConfig().getString("payment-noise", "minecraft:block.amethyst_block.step"), SoundCategory.MASTER, 1f, 1f);
}
@@ -51,17 +57,4 @@ public void onInteract(Player player, ItemStack item, String[] signText, Sign si
for (int i = 0; i < stationOwners.size(); i++) plugin.owners.deposit(stationOwners.get(i), price / stationOwners.size());
}
- public void payCard(IcCard card, Player player, double price) {
- if (card.getValue() < price) payCash(player, price);
- card.withdraw(price);
- double value = card.getValue();
- player.sendMessage(String.format(lang.getString("pay-success-card"), price, value));
- }
-
- public void payCash(Player player, double price) {
- Iciwi.economy.withdrawPlayer(player, price);
- player.sendMessage(lang.getString("cash-divert"));
- player.sendMessage(String.format(lang.getString("pay-success"), price));
- }
-
}
diff --git a/src/main/java/mikeshafter/iciwi/faregate/Transfer.java b/src/main/java/mikeshafter/iciwi/faregate/Transfer.java
index 8a9fe59..7726fa7 100644
--- a/src/main/java/mikeshafter/iciwi/faregate/Transfer.java
+++ b/src/main/java/mikeshafter/iciwi/faregate/Transfer.java
@@ -17,10 +17,10 @@
public class Transfer extends ClosableFareGate {
-private final Lang lang = new Lang();
-private final Owners owners = new Owners();
-private static final CardSql cardSql = new CardSql();
private final Iciwi plugin = Iciwi.getPlugin(Iciwi.class);
+private static final CardSql cardSql = new CardSql();
+private final Owners owners = plugin.owners;
+private final Lang lang = plugin.lang;
public Transfer() {
super();
diff --git a/src/main/java/mikeshafter/iciwi/faregate/Trapdoor.java b/src/main/java/mikeshafter/iciwi/faregate/Trapdoor.java
index 66584a0..c5b36d4 100644
--- a/src/main/java/mikeshafter/iciwi/faregate/Trapdoor.java
+++ b/src/main/java/mikeshafter/iciwi/faregate/Trapdoor.java
@@ -18,9 +18,9 @@
public class Trapdoor extends ClosableFareGate {
private final Iciwi plugin = Iciwi.getPlugin(Iciwi.class);
-private final Lang lang = new Lang();
-private final Owners owners = new Owners();
private static final CardSql cardSql = new CardSql();
+private final Lang lang = plugin.lang;
+private final Owners owners = plugin.owners;
public Trapdoor() {
super(new Vector(0, -2, 0));
@@ -58,7 +58,7 @@ else if ((entryPunched || !entryPunchRequired) && (lore.get(1).equals(station) |
// Log exit
String entryStation = lore.get(0).replace(" •", "");
String fareClass = lore.get(2);
- Fares fares = new Fares();
+ Fares fares = plugin.fares;
cardSql.logMaster(player.getUniqueId().toString());
cardSql.logExit(sign.getLocation().getBlockX(), sign.getLocation().getBlockY(), sign.getLocation().getBlockZ(), entryStation, station);
@@ -93,7 +93,7 @@ else if (lore.get(0).equals(station) || owners.getOwners(station).contains(lore.
// Vital information
String serial = icCard.getSerial();
- Records records = new Records();
+ Records records = plugin.records;
// Determine entry or exit
if (records.getStation(serial).isEmpty()) CardUtil.entry(player, icCard, station, sign.getLocation());
diff --git a/src/main/java/mikeshafter/iciwi/faregate/Validator.java b/src/main/java/mikeshafter/iciwi/faregate/Validator.java
index 6e62371..1fb12b5 100644
--- a/src/main/java/mikeshafter/iciwi/faregate/Validator.java
+++ b/src/main/java/mikeshafter/iciwi/faregate/Validator.java
@@ -19,8 +19,8 @@
public class Validator extends FareGate {
private final Iciwi plugin = Iciwi.getPlugin(Iciwi.class);
-private final Lang lang = new Lang();
-private final Owners owners = new Owners();
+private final Lang lang = plugin.lang;
+private final Owners owners = plugin.owners;
private static final CardSql cardSql = new CardSql();
public Validator() {
@@ -57,7 +57,7 @@ else if ((entryPunched || !entryPunchRequired) && (lore.get(1).equals(station) |
// Log exit
String entryStation = lore.get(0).replace(" •", "");
String fareClass = lore.get(2);
- Fares fares = new Fares();
+ Fares fares = plugin.fares;
cardSql.logMaster(player.getUniqueId().toString());
cardSql.logExit(sign.getLocation().getBlockX(), sign.getLocation().getBlockY(), sign.getLocation().getBlockZ(), entryStation, station);
@@ -90,7 +90,7 @@ else if (lore.get(0).equals(station) || owners.getOwners(station).contains(lore.
// Vital information
String serial = icCard.getSerial();
- Records records = new Records();
+ Records records = plugin.records;
// Determine entry or exit
if (records.getStation(serial).isEmpty()) CardUtil.entry(player, icCard, station, sign.getLocation());
diff --git a/src/main/java/mikeshafter/iciwi/tickets/CardMachine.java b/src/main/java/mikeshafter/iciwi/tickets/CardMachine.java
index f05bb3f..a9e6ca0 100644
--- a/src/main/java/mikeshafter/iciwi/tickets/CardMachine.java
+++ b/src/main/java/mikeshafter/iciwi/tickets/CardMachine.java
@@ -14,7 +14,6 @@
import java.lang.Runnable;
import java.security.SecureRandom;
import java.util.*;
-
import static mikeshafter.iciwi.util.IciwiUtil.*;
public class CardMachine implements Machine {
@@ -101,12 +100,12 @@ public void cardMenu () {
// Create buttons
this.clickables[2] = Clickable.of(makeItem(Material.PURPLE_WOOL, 0, lang.getComponent("menu-new-card")), (event) -> newCard());
- this.clickables[3] = Clickable.of(makeItem(Material.LIGHT_BLUE_WOOL, 0, lang.getComponent("menu-top-up-card")), (event) -> topUpCard(this.selectedItem));
+ this.clickables[3] = Clickable.of(makeItem(Material.LIGHT_BLUE_WOOL, 0, lang.getComponent("menu-top-up-card")), (event) -> topUpCard(icCard));
this.clickables[4] = Clickable.of(makeItem(Material.LIME_WOOL, 0, lang.getComponent("menu-rail-pass")), (event) -> {
- SignInteractListener.machineHashMap.put(player, new RailPassMachine(player, this.operators));
- ((RailPassMachine) SignInteractListener.machineHashMap.get(player)).railPass(this.selectedItem);
+ SignInteractListener.putMachine(player, new RailPassMachine(player, this.operators));
+ ((RailPassMachine) SignInteractListener.getMachine(player)).railPass(this.selectedItem);
});
- this.clickables[5] = Clickable.of(makeItem(Material.ORANGE_WOOL, 0, lang.getComponent("menu-refund-card")), (event) -> refundCard(this.selectedItem));
+ this.clickables[5] = Clickable.of(makeItem(Material.ORANGE_WOOL, 0, lang.getComponent("menu-refund-card")), (event) -> refundCard(icCard));
this.clickables[6] = Clickable.of(makeItem(Material.PURPLE_WOOL, 0, lang.getComponent("menu-select-other-card")), (event) -> selectCard());
// Set items
@@ -170,7 +169,7 @@ public void newCard () {
}
// top up menu
-public void topUpCard (ItemStack item) {
+public void topUpCard (IcCard icCard) {
// Setup listener
// setup inventory
List priceArray = plugin.getConfig().getDoubleList("price-array");
@@ -179,7 +178,7 @@ public void topUpCard (ItemStack item) {
clickables = new Clickable[invSize];
// get serial number
- String serial = parseComponent(Objects.requireNonNull(item.getItemMeta().lore()).get(1));
+ String serial = icCard.getSerial();
for (int i = 0; i < priceArray.size(); i++) {
clickables[i] = Clickable.of(makeItem(Material.LIME_STAINED_GLASS_PANE, 0, Component.text(String.format(lang.getString("currency") + "%.2f", priceArray.get(i)))), (event) -> {
@@ -187,10 +186,10 @@ public void topUpCard (ItemStack item) {
if (Iciwi.economy.getBalance(player) >= value) {
// Get old value for later
- double old = cardSql.getCardValue(serial);
+ double old = icCard.getValue();
// Update value in SQL
- cardSql.addValueToCard(serial, value);
+ icCard.deposit(value);
player.closeInventory();
// Log card
@@ -217,15 +216,15 @@ public void topUpCard (ItemStack item) {
}
// refunds the card
-public void refundCard (ItemStack item) {
+public void refundCard (IcCard icCard) {
// get serial number
- String serial = parseComponent(Objects.requireNonNull(item.getItemMeta().lore()).get(1));
+ String serial = icCard.getSerial();
for (ItemStack itemStack : player.getInventory().getContents()) {
// check if the lore matches
if (loreCheck(itemStack, 2) && Objects.requireNonNull(itemStack.getItemMeta().lore()).get(1).equals(Component.text(serial))) {
// get remaining value
- double remainingValue = this.cardSql.getCardValue(serial);
+ double remainingValue = icCard.getValue();
// get deposit
double deposit = this.plugin.getConfig().getDouble("deposit");
diff --git a/src/main/java/mikeshafter/iciwi/tickets/SignInteractListener.java b/src/main/java/mikeshafter/iciwi/tickets/SignInteractListener.java
index 457aaec..ee77498 100644
--- a/src/main/java/mikeshafter/iciwi/tickets/SignInteractListener.java
+++ b/src/main/java/mikeshafter/iciwi/tickets/SignInteractListener.java
@@ -1,5 +1,6 @@
package mikeshafter.iciwi.tickets;
+import mikeshafter.iciwi.Iciwi;
import mikeshafter.iciwi.config.Lang;
import mikeshafter.iciwi.util.Clickable;
import mikeshafter.iciwi.util.IciwiUtil;
@@ -14,20 +15,23 @@
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
-
import java.util.HashMap;
public class SignInteractListener implements Listener {
-private final Lang lang = new Lang();
-protected static final HashMap machineHashMap = new HashMap<>();
+private final Iciwi plugin = Iciwi.getPlugin(Iciwi.class);
+private final Lang lang = plugin.lang;
+private static final HashMap machineHashMap = new HashMap<>();
+
+protected static Machine getMachine (Player player) { return machineHashMap.get(player); }
+protected static void putMachine (Player player, Machine machine) { machineHashMap.put(player, machine); }
@EventHandler (priority = EventPriority.LOWEST) public void TicketMachineListener (final InventoryClickEvent event) {
final Player player = (Player) event.getWhoClicked();
if (machineHashMap.containsKey(player)) {
final Inventory clickedInventory = event.getClickedInventory();
- Machine machine = machineHashMap.get(player);
+ final Machine machine = getMachine(player);
if (clickedInventory == player.getOpenInventory().getBottomInventory()) {
// player inventory item selection code
@@ -75,7 +79,7 @@ public class SignInteractListener implements Listener {
sign.update(true);
final TicketMachine machine = new TicketMachine(player);
machine.init(station);
- machineHashMap.put(player, machine);
+ putMachine(player, machine);
}
// === Card vending machine ===
@@ -84,7 +88,7 @@ public class SignInteractListener implements Listener {
sign.update(true);
final CardMachine machine = new CardMachine(player);
machine.init(station);
- machineHashMap.put(player, machine);
+ putMachine(player, machine);
}
// === Rail pass machine ===
@@ -93,7 +97,7 @@ else if (signLine0.equalsIgnoreCase("[" + lang.getString("passes") + "]")) {
sign.update(true);
final RailPassMachine machine = new RailPassMachine(player);
machine.init(station);
- machineHashMap.put(player, machine);
+ putMachine(player, machine);
}
// === Custom machine ===
@@ -101,7 +105,7 @@ else if (signLine0.equalsIgnoreCase("[" + lang.getString("custom-tickets") + "]"
sign.setWaxed(true);
sign.update(true);
CustomMachine machine = new CustomMachine(player, station);
- machineHashMap.put(player, machine);
+ putMachine(player, machine);
}
}
}
diff --git a/src/main/java/mikeshafter/iciwi/tickets/TicketMachine.java b/src/main/java/mikeshafter/iciwi/tickets/TicketMachine.java
index 1086dda..462698e 100644
--- a/src/main/java/mikeshafter/iciwi/tickets/TicketMachine.java
+++ b/src/main/java/mikeshafter/iciwi/tickets/TicketMachine.java
@@ -55,7 +55,7 @@ public void init (String station) {
else if (addCustomTickets) {
clickList.add(Clickable.of(
makeItem(Material.PAPER, 0, lang.getComponent("menu-new-ticket"), Component.text("Tickets are non-refundable")),
- (event) -> SignInteractListener.machineHashMap.put(this.player, new CustomMachine(player, station))
+ (event) -> SignInteractListener.putMachine(this.player, new CustomMachine(player, station))
));
addCustomTickets = false;
}
@@ -64,16 +64,16 @@ else if (addCustomTickets) {
// New card
clickList.add(
Clickable.of(makeItem(Material.PURPLE_WOOL, 0, lang.getComponent("menu-new-card")), (event) -> {
- SignInteractListener.machineHashMap.put(player, new CardMachine(player, station));
- ((CardMachine) SignInteractListener.machineHashMap.get(player)).newCard();
+ SignInteractListener.putMachine(player, new CardMachine(player, station));
+ ((CardMachine) SignInteractListener.getMachine(player)).newCard();
})
);
// Select card
clickList.add(
Clickable.of(makeItem(Material.NAME_TAG, 0, lang.getComponent("menu-insert-card")), (event) -> {
- SignInteractListener.machineHashMap.put(player, new CardMachine(player, station));
- ((CardMachine) SignInteractListener.machineHashMap.get(player)).selectCard();
+ SignInteractListener.putMachine(player, new CardMachine(player, station));
+ ((CardMachine) SignInteractListener.getMachine(player)).selectCard();
})
);
@@ -122,14 +122,14 @@ protected void generateOperatorTicket (String owner) {
// // Create buttons
// var btnArray = new Clickable[]{
// Clickable.of(makeItem(Material.PAPER, 0, lang.getComponent("menu-new-ticket"), Component.text("Tickets are non-refundable")), (event) ->
-// SignInteractListener.machineHashMap.put(this.player, new CustomMachine(player, station))),
+// SignInteractListener.putMachine(this.player, new CustomMachine(player, station))),
// Clickable.of(makeItem(Material.PURPLE_WOOL, 0, lang.getComponent("menu-new-card")), (event) -> {
-// SignInteractListener.machineHashMap.put(player, new CardMachine(player));
-// ((CardMachine) SignInteractListener.machineHashMap.get(player)).newCard();
+// SignInteractListener.putMachine(player, new CardMachine(player));
+// ((CardMachine) SignInteractListener.getMachine(player)).newCard();
// }),
// Clickable.of(makeItem(Material.NAME_TAG, 0, lang.getComponent("menu-insert-card")), (event) -> {
-// SignInteractListener.machineHashMap.put(player, new CardMachine(player));
-// ((CardMachine) SignInteractListener.machineHashMap.get(player)).selectCard();
+// SignInteractListener.putMachine(player, new CardMachine(player));
+// ((CardMachine) SignInteractListener.getMachine(player)).selectCard();
// })
// };
// this.clickables = (Clickable[]) IciwiUtil.justify(9, btnArray);
diff --git a/src/main/java/mikeshafter/iciwi/util/GateCreateListener.java b/src/main/java/mikeshafter/iciwi/util/GateCreateListener.java
index d2cbb8e..6c7d1e3 100644
--- a/src/main/java/mikeshafter/iciwi/util/GateCreateListener.java
+++ b/src/main/java/mikeshafter/iciwi/util/GateCreateListener.java
@@ -8,25 +8,22 @@
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.SignChangeEvent;
-import static mikeshafter.iciwi.util.IciwiUtil.parseComponent;
-import static mikeshafter.iciwi.util.IciwiUtil.containsMany;
public class GateCreateListener implements Listener {
@EventHandler(priority = EventPriority.LOWEST)
public void onGateCreate(SignChangeEvent event) {
Lang lang = Iciwi.getPlugin(Iciwi.class).lang;
- final String line = parseComponent(event.line(0));
+ final String line = IciwiUtil.parseComponent(event.line(0));
final Player player = event.getPlayer();
- int createdSign = containsMany(line, lang.getString("entry"), lang.getString("exit"), lang.getString("member"), lang.getString("payment"), lang.getString("faregate"), lang.getString("validator"), lang.getString("tickets"), lang.getString("cards"), lang.getString("passes"), lang.getString("custom-tickets"));
+ int createdSign = IciwiUtil.containsMany(line, lang.getString("entry"), lang.getString("exit"), lang.getString("member"), lang.getString("payment"), lang.getString("faregate"), lang.getString("validator"), lang.getString("tickets"), lang.getString("cards"), lang.getString("passes"), lang.getString("custom-tickets"));
if (createdSign != -1 && !player.hasPermission("iciwi.create")) {
event.setCancelled(true);
return;
}
-
switch (createdSign) {
case 0 -> player.sendMessage(lang.getString("create-entry-sign"));
case 1 -> player.sendMessage(lang.getString("create-exit-sign"));
diff --git a/src/main/resources/owners.yml b/src/main/resources/owners.yml
index e6e599e..25e4c00 100644
--- a/src/main/resources/owners.yml
+++ b/src/main/resources/owners.yml
@@ -52,3 +52,13 @@ Operators:
TicketType:
ExampleOperator: 20
ExampleOperator1: 0
+
+# This section lets you change fare caps for each company.
+# Set the value to 0 if the operator doesn't use this feature
+Caps:
+ ExampleOperator:
+ amount: 15
+ duration: '1:00:00:00'
+ ExampleOperator1:
+ amount: 0
+ duration: ''
\ No newline at end of file