Compare commits
No commits in common. "2bbb5a0fc3390aca19a2db2885458bef310b9682" and "07d27adce111d6104ac44823b3c7201357185cda" have entirely different histories.
2bbb5a0fc3
...
07d27adce1
3 changed files with 38 additions and 94 deletions
2
pom.xml
2
pom.xml
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
<groupId>tech.sbdevelopment</groupId>
|
<groupId>tech.sbdevelopment</groupId>
|
||||||
<artifactId>VehiclesPlusConverter</artifactId>
|
<artifactId>VehiclesPlusConverter</artifactId>
|
||||||
<version>0.2.3</version>
|
<version>0.2.2</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>VehiclesPlusConverter</name>
|
<name>VehiclesPlusConverter</name>
|
||||||
|
|
|
@ -1,14 +1,9 @@
|
||||||
package tech.sbdevelopment.vehiclesplusconverter.api;
|
package tech.sbdevelopment.vehiclesplusconverter.api;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class ConversionException extends IOException {
|
public class ConversionException extends IOException {
|
||||||
public ConversionException(String explanation, String filename) {
|
public ConversionException(String before, String filename) {
|
||||||
super(explanation + " " + filename + ".yml!");
|
super(before + " " + filename + ".yml");
|
||||||
}
|
|
||||||
|
|
||||||
public ConversionException(String explanation, String filename, String expected, Set<String> available) {
|
|
||||||
super(explanation + " " + filename + ".yml! Expected " + expected + ", available: " + String.join(", ", available));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,16 +23,14 @@ import nl.sbdeveloper.vehiclesplus.api.vehicles.settings.impl.*;
|
||||||
import nl.sbdeveloper.vehiclesplus.storage.db.exceptions.DataStorageException;
|
import nl.sbdeveloper.vehiclesplus.storage.db.exceptions.DataStorageException;
|
||||||
import nl.sbdeveloper.vehiclesplus.utils.jackson.ColorList;
|
import nl.sbdeveloper.vehiclesplus.utils.jackson.ColorList;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.OfflinePlayer;
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
import tech.sbdevelopment.vehiclesplusconverter.VehiclesPlusConverter;
|
import tech.sbdevelopment.vehiclesplusconverter.VehiclesPlusConverter;
|
||||||
import tech.sbdevelopment.vehiclesplusconverter.api.ConversionException;
|
import tech.sbdevelopment.vehiclesplusconverter.api.ConversionException;
|
||||||
|
|
||||||
import java.io.File;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
import static tech.sbdevelopment.vehiclesplusconverter.utils.MainUtil.*;
|
import static tech.sbdevelopment.vehiclesplusconverter.utils.MainUtil.*;
|
||||||
|
|
||||||
|
@ -75,7 +73,8 @@ public class Converter {
|
||||||
try {
|
try {
|
||||||
disablePlugin(VehiclesPlus.getInstance());
|
disablePlugin(VehiclesPlus.getInstance());
|
||||||
disablePlugin(VehiclesPlusConverter.getInstance());
|
disablePlugin(VehiclesPlusConverter.getInstance());
|
||||||
} catch (Exception ignored) {
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
counter--;
|
counter--;
|
||||||
|
@ -86,7 +85,7 @@ public class Converter {
|
||||||
private static void convertRims() {
|
private static void convertRims() {
|
||||||
for (Map.Entry<String, RimDesign> entry : VehiclesPlus.getVehicleManager().getRimDesignHashMap().entrySet()) {
|
for (Map.Entry<String, RimDesign> entry : VehiclesPlus.getVehicleManager().getRimDesignHashMap().entrySet()) {
|
||||||
nl.sbdeveloper.vehiclesplus.api.vehicles.rims.RimDesign rd = new nl.sbdeveloper.vehiclesplus.api.vehicles.rims.RimDesign(
|
nl.sbdeveloper.vehiclesplus.api.vehicles.rims.RimDesign rd = new nl.sbdeveloper.vehiclesplus.api.vehicles.rims.RimDesign(
|
||||||
entry.getValue().getName().toLowerCase(),
|
entry.getValue().getName(),
|
||||||
entry.getValue().getSkin(),
|
entry.getValue().getSkin(),
|
||||||
HolderItemPosition.HEAD,
|
HolderItemPosition.HEAD,
|
||||||
entry.getValue().getPrice()
|
entry.getValue().getPrice()
|
||||||
|
@ -116,11 +115,6 @@ public class Converter {
|
||||||
VehiclesPlusConverter.getInstance().getLogger().info("Converting vehicle models: " + VehiclesPlusAPI.getVehicleManager().getBaseVehicleMap().values().stream().map(BaseVehicle::getName).reduce((s1, s2) -> s1 + ", " + s2).orElse(""));
|
VehiclesPlusConverter.getInstance().getLogger().info("Converting vehicle models: " + VehiclesPlusAPI.getVehicleManager().getBaseVehicleMap().values().stream().map(BaseVehicle::getName).reduce((s1, s2) -> s1 + ", " + s2).orElse(""));
|
||||||
|
|
||||||
for (BaseVehicle baseVehicle : VehiclesPlusAPI.getVehicleManager().getBaseVehicleMap().values()) {
|
for (BaseVehicle baseVehicle : VehiclesPlusAPI.getVehicleManager().getBaseVehicleMap().values()) {
|
||||||
if (baseVehicle.getName().startsWith("Example")) {
|
|
||||||
VehiclesPlusConverter.getInstance().getLogger().info("Skipping example vehicle model: " + baseVehicle.getName());
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
VehicleModel.Builder vehicleModelBuilder = VehicleModel.builder()
|
VehicleModel.Builder vehicleModelBuilder = VehicleModel.builder()
|
||||||
.id(baseVehicle.getName())
|
.id(baseVehicle.getName())
|
||||||
|
@ -143,12 +137,7 @@ public class Converter {
|
||||||
turretSeat.getXOffset(),
|
turretSeat.getXOffset(),
|
||||||
turretSeat.getYOffset(),
|
turretSeat.getYOffset(),
|
||||||
turretSeat.getZOffset(),
|
turretSeat.getZOffset(),
|
||||||
baseVehicle.getPartList()
|
baseVehicle.getPartList().stream().filter(Turret.class::isInstance).findFirst().orElseThrow(() -> new ConversionException("No Turret found while loading TurretSeat in file", baseVehicle.getName())).getUID()
|
||||||
.stream()
|
|
||||||
.filter(Turret.class::isInstance)
|
|
||||||
.findFirst()
|
|
||||||
.orElseThrow(() -> new ConversionException("No Turret found while loading TurretSeat in file", baseVehicle.getName()))
|
|
||||||
.getUID()
|
|
||||||
));
|
));
|
||||||
} else if (part instanceof Seat) {
|
} else if (part instanceof Seat) {
|
||||||
Seat seat = (Seat) part;
|
Seat seat = (Seat) part;
|
||||||
|
@ -202,12 +191,7 @@ public class Converter {
|
||||||
wheel.getXOffset(),
|
wheel.getXOffset(),
|
||||||
wheel.getYOffset(),
|
wheel.getYOffset(),
|
||||||
wheel.getZOffset(),
|
wheel.getZOffset(),
|
||||||
nl.sbdeveloper.vehiclesplus.api.VehiclesPlusAPI.getRimDesign(VehiclesPlus.getVehicleManager().getRimDesignHashMap().values()
|
nl.sbdeveloper.vehiclesplus.api.VehiclesPlusAPI.getRimDesign(VehiclesPlus.getVehicleManager().getRimDesignHashMap().values().stream().findFirst().orElseThrow(() -> new ConversionException("No RimDesign found while loading Wheel in file", baseVehicle.getName())).getName()).orElseThrow(() -> new ConversionException("No matching RimDesign found while loading Wheel in file", baseVehicle.getName())),
|
||||||
.stream()
|
|
||||||
.map(str -> str.getName().toLowerCase())
|
|
||||||
.findFirst()
|
|
||||||
.orElseThrow(() -> new ConversionException("No RimDesign found while loading Wheel in file", baseVehicle.getName(), "N/A", VehiclesPlus.getVehicleManager().getRimDesignHashMap().keySet())))
|
|
||||||
.orElseThrow(() -> new ConversionException("No matching RimDesign found while loading Wheel in file", baseVehicle.getName(), "N/A", VehiclesPlus.getVehicleManager().getRimDesignHashMap().keySet())),
|
|
||||||
wheel.getColor(),
|
wheel.getColor(),
|
||||||
wheel.getSteering(),
|
wheel.getSteering(),
|
||||||
wheel.getRotationOffset()
|
wheel.getRotationOffset()
|
||||||
|
@ -291,7 +275,6 @@ public class Converter {
|
||||||
VehiclesPlusConverter.getInstance().getLogger().info("Converted vehicle model: " + model.getId());
|
VehiclesPlusConverter.getInstance().getLogger().info("Converted vehicle model: " + model.getId());
|
||||||
|
|
||||||
saveToVehiclesPlus(model, "vehicles/" + model.getTypeId(), model.getId());
|
saveToVehiclesPlus(model, "vehicles/" + model.getTypeId(), model.getId());
|
||||||
nl.sbdeveloper.vehiclesplus.api.VehiclesPlusAPI.getVehicleModels().put(model.getId(), model);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
VehiclesPlusConverter.getInstance().getLogger().log(java.util.logging.Level.SEVERE, "Could not convert vehicle model: " + baseVehicle.getName(), e);
|
VehiclesPlusConverter.getInstance().getLogger().log(java.util.logging.Level.SEVERE, "Could not convert vehicle model: " + baseVehicle.getName(), e);
|
||||||
}
|
}
|
||||||
|
@ -299,74 +282,40 @@ public class Converter {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void convertVehicles() {
|
private static void convertVehicles() {
|
||||||
File baseDir = new File("plugins/VehiclesPlusPro/data");
|
for (Map.Entry<UUID, List<StorageVehicle>> set : VehiclesPlusAPI.getVehicleManager().getPlayerVehicleHashMap().entrySet()) {
|
||||||
if (!baseDir.exists()) {
|
UUID ownerUUID = set.getKey();
|
||||||
VehiclesPlusConverter.getInstance().getLogger().severe("Could not find the VehiclesPlusPro data folder!");
|
String ownerName = Bukkit.getOfflinePlayer(ownerUUID).getName();
|
||||||
return;
|
if (ownerName == null) {
|
||||||
}
|
VehiclesPlusConverter.getInstance().getLogger().severe("Could not convert vehicles for player with UUID " + ownerUUID + ", the player name is unknown!");
|
||||||
|
|
||||||
for (File playerDir : baseDir.listFiles()) {
|
|
||||||
if (playerDir.isDirectory()) {
|
|
||||||
String ownerUUID = playerDir.getName();
|
|
||||||
|
|
||||||
OfflinePlayer player = Bukkit.getOfflinePlayer(UUID.fromString(ownerUUID));
|
|
||||||
if (player.getName() == null) {
|
|
||||||
VehiclesPlusConverter.getInstance().getLogger().severe("Could not find player with UUID: " + ownerUUID + ", skipping...");
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
VehiclesPlusConverter.getInstance().getLogger().info("Converting vehicles for player with UUID " + ownerUUID + "...");
|
final Garage garage = nl.sbdeveloper.vehiclesplus.api.VehiclesPlusAPI.getGarage(ownerName).orElseGet(() -> new Garage(ownerName, ownerUUID));
|
||||||
final Garage garage = nl.sbdeveloper.vehiclesplus.api.VehiclesPlusAPI.getPersonalGarage(player);
|
VehiclesPlusConverter.getInstance().getLogger().info("Converting vehicles for player with UUID " + ownerUUID + " (" + ownerName + ")...");
|
||||||
|
|
||||||
int i = 0;
|
|
||||||
for (File vehicleFile : playerDir.listFiles()) {
|
|
||||||
if (vehicleFile.getName().contains(".yml")) {
|
|
||||||
StorageVehicle vehicle;
|
|
||||||
try {
|
|
||||||
vehicle = StorageVehicle.loadFromStorage(vehicleFile.getAbsolutePath());
|
|
||||||
} catch (Exception e) {
|
|
||||||
Bukkit.getLogger().log(Level.SEVERE, "Could not convert vehicles for player with UUID " + ownerUUID + ", could not load the vehicle!", e);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (vehicle == null) {
|
|
||||||
Bukkit.getLogger().warning("Failed to load vehicle for player with UUID " + ownerUUID + " from file: " + vehicleFile.getName() + ", skipping...");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
for (StorageVehicle vehicle : set.getValue()) {
|
||||||
try {
|
try {
|
||||||
nl.sbdeveloper.vehiclesplus.api.vehicles.impl.StorageVehicle newVehicle = new nl.sbdeveloper.vehiclesplus.api.vehicles.impl.StorageVehicle(
|
nl.sbdeveloper.vehiclesplus.api.vehicles.impl.StorageVehicle newVehicle = new nl.sbdeveloper.vehiclesplus.api.vehicles.impl.StorageVehicle(
|
||||||
UUID.randomUUID(),
|
UUID.randomUUID(),
|
||||||
nl.sbdeveloper.vehiclesplus.api.VehiclesPlusAPI.getVehicleModels().values().stream().filter(v -> v.getId().equalsIgnoreCase(vehicle.getBaseVehicle())).findFirst().orElseThrow(() -> new ConversionException("No VehicleModel found for", vehicle.getUuid(), vehicle.getBaseVehicle(), nl.sbdeveloper.vehiclesplus.api.VehiclesPlusAPI.getVehicleModels().keySet())),
|
nl.sbdeveloper.vehiclesplus.api.VehiclesPlusAPI.getVehicleModels().values().stream().filter(v -> v.getId().equalsIgnoreCase(vehicle.getBaseVehicle())).findFirst().orElseThrow(() -> new ConversionException("No VehicleModel found for", vehicle.getUuid())),
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
// Set the vehicle's stats
|
|
||||||
newVehicle.getStatics().forceSetMaxSpeed(vehicle.getVehicleStats().getSpeed());
|
|
||||||
newVehicle.getStatics().forceSetTurningRadius(vehicle.getVehicleStats().getSteering());
|
|
||||||
newVehicle.getStatics().forceSetFuelTank(vehicle.getVehicleStats().getFuelTank());
|
|
||||||
newVehicle.getStatics().setCurrentFuel(vehicle.getVehicleStats().getCurrentFuel());
|
|
||||||
newVehicle.getStatics().forceSetAcceleration(vehicle.getVehicleStats().getAcceleration());
|
|
||||||
newVehicle.getStatics().setBroken(vehicle.getVehicleStats().getBroken());
|
|
||||||
newVehicle.getStatics().setCurrentHealth(vehicle.getVehicleStats().getHealth());
|
|
||||||
|
|
||||||
newVehicle.forceSave();
|
newVehicle.forceSave();
|
||||||
garage.addVehicle(newVehicle.getUuid());
|
garage.addVehicle(newVehicle.getUuid());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Bukkit.getLogger().log(Level.SEVERE, "Could not convert vehicles for player with UUID " + ownerUUID + ", could not save the vehicle!", e);
|
e.printStackTrace();
|
||||||
|
Bukkit.getLogger().severe("Could not convert vehicles for player with UUID " + ownerUUID + ", could not save the vehicle!");
|
||||||
}
|
}
|
||||||
|
|
||||||
VehiclesPlusConverter.getInstance().getLogger().info("Converted vehicle: " + vehicle.getUuid());
|
VehiclesPlusConverter.getInstance().getLogger().info("Converted vehicle: " + vehicle.getUuid());
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
garage.forceSave();
|
garage.forceSave();
|
||||||
} catch (DataStorageException e) {
|
} catch (DataStorageException e) {
|
||||||
Bukkit.getLogger().log(Level.SEVERE, "Could not convert vehicles for player with UUID " + ownerUUID + ", could not save the garage!", e);
|
e.printStackTrace();
|
||||||
}
|
Bukkit.getLogger().severe("Could not convert vehicles for player with UUID " + ownerUUID + ", could not save the garage!");
|
||||||
|
|
||||||
VehiclesPlusConverter.getInstance().getLogger().info("Converted " + i + " vehicles for player with UUID " + ownerUUID);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue