2
2
3
3
import java .util .HashMap ;
4
4
import java .util .Map ;
5
+ import java .util .Set ;
5
6
6
7
import io .github .a5h73y .Carz ;
7
8
import io .github .a5h73y .enums .Permissions ;
8
9
import io .github .a5h73y .model .Car ;
9
- import io .github .a5h73y .model .StandardCar ;
10
+ import io .github .a5h73y .model .CarDetails ;
10
11
import io .github .a5h73y .other .Utils ;
11
12
import io .github .a5h73y .utility .EffectUtils ;
12
13
import io .github .a5h73y .utility .PermissionUtils ;
21
22
*/
22
23
public class CarController {
23
24
25
+ public static final String DEFAULT_CAR = "Default" ;
26
+
24
27
private final Carz carz ;
25
28
26
29
// Vehicle ID with it's associated Car
@@ -29,8 +32,24 @@ public class CarController {
29
32
// Players currently inside a Carz vehicle, with the value being Vehicle ID
30
33
private final Map <String , Integer > playersDriving = new HashMap <>();
31
34
35
+ private final Map <String , CarDetails > carTypes = new HashMap <>();
36
+
32
37
public CarController (Carz carz ) {
33
38
this .carz = carz ;
39
+ populateCarTypes ();
40
+ }
41
+
42
+ private void populateCarTypes () {
43
+ Set <String > allCarTypes = carz .getConfig ().getConfigurationSection ("CarTypes" ).getKeys (false );
44
+
45
+ for (String carType : allCarTypes ) {
46
+ double startSpeed = carz .getConfig ().getDouble ("CarTypes." + carType + ".StartMaxSpeed" );
47
+ double maxSpeed = carz .getConfig ().getDouble ("CarTypes." + carType + ".MaxUpgradeSpeed" );
48
+ double acceleration = carz .getConfig ().getDouble ("CarTypes." + carType + ".Acceleration" );
49
+ double fuelUsage = carz .getConfig ().getDouble ("CarTypes." + carType + ".FuelUsage" );
50
+ String fillMaterial = carz .getConfig ().getString ("CarTypes." + carType + ".FillMaterial" );
51
+ carTypes .put (carType , new CarDetails (startSpeed , maxSpeed , acceleration , fuelUsage , fillMaterial ));
52
+ }
34
53
}
35
54
36
55
/**
@@ -40,7 +59,7 @@ public CarController(Carz carz) {
40
59
* @param owner is the player the registered owner?
41
60
*/
42
61
public void startDriving (String playerName , Integer carId , boolean owner ) {
43
- Car car = getOrCreateCar (carId , new StandardCar ( carId ) );
62
+ Car car = getOrCreateCar (carId , DEFAULT_CAR );
44
63
if (owner ) {
45
64
car .setOwner (playerName );
46
65
}
@@ -58,8 +77,8 @@ public void startDriving(String playerName, Integer carId) {
58
77
* @param carType
59
78
* @return matching or new Car
60
79
*/
61
- public Car getOrCreateCar (Integer entityId , Car carType ) {
62
- return entityIdToCar .computeIfAbsent (entityId , k -> carType );
80
+ public Car getOrCreateCar (Integer entityId , String carType ) {
81
+ return entityIdToCar .computeIfAbsent (entityId , k -> new Car ( entityId , carType ) );
63
82
}
64
83
65
84
/**
@@ -68,7 +87,7 @@ public Car getOrCreateCar(Integer entityId, Car carType) {
68
87
* @param entityId
69
88
*/
70
89
public Car getOrCreateCar (Integer entityId ) {
71
- return getOrCreateCar (entityId , new StandardCar ( entityId ) );
90
+ return getOrCreateCar (entityId , DEFAULT_CAR );
72
91
}
73
92
74
93
/**
@@ -168,7 +187,7 @@ public void upgradeCarSpeed(Player player) {
168
187
upgradeCarSpeed (car );
169
188
EffectUtils .playEffect (player , Effect .ZOMBIE_CHEW_WOODEN_DOOR );
170
189
player .sendMessage (TranslationUtils .getTranslation ("Car.UpgradeSpeed" )
171
- .replace ("%SPEED%" , car .getMaxSpeed (). toString ( )));
190
+ .replace ("%SPEED%" , String . valueOf ( car .getMaxSpeed ())));
172
191
173
192
EffectUtils .createUpgradeEffect ((Vehicle ) player .getVehicle ());
174
193
}
@@ -180,14 +199,18 @@ public void upgradeCarSpeed(Player player) {
180
199
* @param car
181
200
*/
182
201
private void upgradeCarSpeed (Car car ) {
183
- Double currentSpeed = car .getMaxSpeed ();
184
- Double upgradeBy = carz . getSettings ().getUpgradeSpeed ();
185
- Double maxSpeed = carz .getSettings ().getUpgradeMaxSpeed ();
202
+ double currentMax = car .getCarDetails (). getStartMaxSpeed ();
203
+ double maxSpeed = car . getCarDetails ().getMaxUpgradeSpeed ();
204
+ double upgradeBy = carz .getSettings ().getUpgradeIncrement ();
186
205
187
- if ((currentSpeed + upgradeBy ) > maxSpeed ) {//&& !event.getPlayer().hasPermission("Carz.Admin"))
206
+ if ((currentMax + upgradeBy ) > maxSpeed ) {//&& !event.getPlayer().hasPermission("Carz.Admin"))
188
207
return ;
189
208
}
190
209
191
- car .setMaxSpeed (currentSpeed + upgradeBy );
210
+ car .setMaxSpeed (currentMax + upgradeBy );
211
+ }
212
+
213
+ public Map <String , CarDetails > getCarTypes () {
214
+ return carTypes ;
192
215
}
193
216
}
0 commit comments