🎉 First commit!
This commit is contained in:
commit
602fc2e91d
|
@ -0,0 +1,113 @@
|
||||||
|
# User-specific stuff
|
||||||
|
.idea/
|
||||||
|
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
*.iws
|
||||||
|
|
||||||
|
# IntelliJ
|
||||||
|
out/
|
||||||
|
|
||||||
|
# Compiled class file
|
||||||
|
*.class
|
||||||
|
|
||||||
|
# Log file
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# BlueJ files
|
||||||
|
*.ctxt
|
||||||
|
|
||||||
|
# Package Files #
|
||||||
|
*.jar
|
||||||
|
*.war
|
||||||
|
*.nar
|
||||||
|
*.ear
|
||||||
|
*.zip
|
||||||
|
*.tar.gz
|
||||||
|
*.rar
|
||||||
|
|
||||||
|
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||||
|
hs_err_pid*
|
||||||
|
|
||||||
|
*~
|
||||||
|
|
||||||
|
# temporary files which can be created if a process still has a handle open of a deleted file
|
||||||
|
.fuse_hidden*
|
||||||
|
|
||||||
|
# KDE directory preferences
|
||||||
|
.directory
|
||||||
|
|
||||||
|
# Linux trash folder which might appear on any partition or disk
|
||||||
|
.Trash-*
|
||||||
|
|
||||||
|
# .nfs files are created when an open file is removed but is still being accessed
|
||||||
|
.nfs*
|
||||||
|
|
||||||
|
# General
|
||||||
|
.DS_Store
|
||||||
|
.AppleDouble
|
||||||
|
.LSOverride
|
||||||
|
|
||||||
|
# Icon must end with two \r
|
||||||
|
Icon
|
||||||
|
|
||||||
|
# Thumbnails
|
||||||
|
._*
|
||||||
|
|
||||||
|
# Files that might appear in the root of a volume
|
||||||
|
.DocumentRevisions-V100
|
||||||
|
.fseventsd
|
||||||
|
.Spotlight-V100
|
||||||
|
.TemporaryItems
|
||||||
|
.Trashes
|
||||||
|
.VolumeIcon.icns
|
||||||
|
.com.apple.timemachine.donotpresent
|
||||||
|
|
||||||
|
# Directories potentially created on remote AFP share
|
||||||
|
.AppleDB
|
||||||
|
.AppleDesktop
|
||||||
|
Network Trash Folder
|
||||||
|
Temporary Items
|
||||||
|
.apdisk
|
||||||
|
|
||||||
|
# Windows thumbnail cache files
|
||||||
|
Thumbs.db
|
||||||
|
Thumbs.db:encryptable
|
||||||
|
ehthumbs.db
|
||||||
|
ehthumbs_vista.db
|
||||||
|
|
||||||
|
# Dump file
|
||||||
|
*.stackdump
|
||||||
|
|
||||||
|
# Folder config file
|
||||||
|
[Dd]esktop.ini
|
||||||
|
|
||||||
|
# Recycle Bin used on file shares
|
||||||
|
$RECYCLE.BIN/
|
||||||
|
|
||||||
|
# Windows Installer files
|
||||||
|
*.cab
|
||||||
|
*.msi
|
||||||
|
*.msix
|
||||||
|
*.msm
|
||||||
|
*.msp
|
||||||
|
|
||||||
|
# Windows shortcuts
|
||||||
|
*.lnk
|
||||||
|
|
||||||
|
target/
|
||||||
|
|
||||||
|
pom.xml.tag
|
||||||
|
pom.xml.releaseBackup
|
||||||
|
pom.xml.versionsBackup
|
||||||
|
pom.xml.next
|
||||||
|
|
||||||
|
release.properties
|
||||||
|
dependency-reduced-pom.xml
|
||||||
|
buildNumber.properties
|
||||||
|
.mvn/timing.properties
|
||||||
|
.mvn/wrapper/maven-wrapper.jar
|
||||||
|
.flattened-pom.xml
|
||||||
|
|
||||||
|
# Common working directory
|
||||||
|
run/
|
|
@ -0,0 +1,90 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>tech.sbdevelopment</groupId>
|
||||||
|
<artifactId>VehiclesPlusConverter</artifactId>
|
||||||
|
<version>1.0</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>VehiclesPlusConverter</name>
|
||||||
|
|
||||||
|
<description>Conversion plugin for v2 to v3.</description>
|
||||||
|
<properties>
|
||||||
|
<java.version>1.8</java.version>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
<url>sbdevelopment.tech</url>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.8.1</version>
|
||||||
|
<configuration>
|
||||||
|
<source>10</source>
|
||||||
|
<target>10</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>3.2.4</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>spigotmc-repo</id>
|
||||||
|
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>sonatype</id>
|
||||||
|
<url>https://oss.sonatype.org/content/groups/public/</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.spigotmc</groupId>
|
||||||
|
<artifactId>spigot-api</artifactId>
|
||||||
|
<version>1.19.2-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>nl.sbdeveloper</groupId>
|
||||||
|
<artifactId>VehiclesPlus-v2</artifactId>
|
||||||
|
<version>2.3.5</version>
|
||||||
|
<scope>system</scope>
|
||||||
|
<systemPath>${project.basedir}/src/libs/VehiclesPlus-2.3.5.jar</systemPath>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>nl.sbdeveloper</groupId>
|
||||||
|
<artifactId>VehiclesPlus-v3</artifactId>
|
||||||
|
<version>3.0.0</version>
|
||||||
|
<scope>system</scope>
|
||||||
|
<systemPath>${project.basedir}/src/libs/VehiclesPlus-3.0.0.jar</systemPath>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
|
@ -0,0 +1,9 @@
|
||||||
|
package tech.sbdevelopment.vehiclesplusconverter;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class ConversionException extends IOException {
|
||||||
|
public ConversionException(String before, String filename) {
|
||||||
|
super(before + " " + filename + ".yml");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,303 @@
|
||||||
|
package tech.sbdevelopment.vehiclesplusconverter;
|
||||||
|
|
||||||
|
import me.legofreak107.vehiclesplus.VehiclesPlus;
|
||||||
|
import me.legofreak107.vehiclesplus.vehicles.api.VehiclesPlusAPI;
|
||||||
|
import me.legofreak107.vehiclesplus.vehicles.fuel.FuelType;
|
||||||
|
import me.legofreak107.vehiclesplus.vehicles.rims.RimDesign;
|
||||||
|
import me.legofreak107.vehiclesplus.vehicles.vehicles.objects.BaseVehicle;
|
||||||
|
import me.legofreak107.vehiclesplus.vehicles.vehicles.objects.StorageVehicle;
|
||||||
|
import me.legofreak107.vehiclesplus.vehicles.vehicles.objects.addons.Part;
|
||||||
|
import me.legofreak107.vehiclesplus.vehicles.vehicles.objects.addons.Wheel;
|
||||||
|
import me.legofreak107.vehiclesplus.vehicles.vehicles.objects.addons.seats.BikeSeat;
|
||||||
|
import me.legofreak107.vehiclesplus.vehicles.vehicles.objects.addons.seats.Seat;
|
||||||
|
import me.legofreak107.vehiclesplus.vehicles.vehicles.objects.addons.seats.TurretSeat;
|
||||||
|
import me.legofreak107.vehiclesplus.vehicles.vehicles.objects.addons.skins.BikeSkin;
|
||||||
|
import me.legofreak107.vehiclesplus.vehicles.vehicles.objects.addons.skins.Rotor;
|
||||||
|
import me.legofreak107.vehiclesplus.vehicles.vehicles.objects.addons.skins.Skin;
|
||||||
|
import me.legofreak107.vehiclesplus.vehicles.vehicles.objects.addons.skins.Turret;
|
||||||
|
import nl.sbdeveloper.vehiclesplus.api.vehicles.VehicleModel;
|
||||||
|
import nl.sbdeveloper.vehiclesplus.api.vehicles.settings.UpgradableSetting;
|
||||||
|
import nl.sbdeveloper.vehiclesplus.api.vehicles.settings.impl.*;
|
||||||
|
import nl.sbdeveloper.vehiclesplus.storage.file.JSONFile;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Particle;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
import static tech.sbdevelopment.vehiclesplusconverter.utils.MainUtil.__;
|
||||||
|
|
||||||
|
public class Converter {
|
||||||
|
private Converter() {
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Sounds defaultSounds = Sounds.builder()
|
||||||
|
.idle(new Sounds.Sound("car.idle", 6))
|
||||||
|
.start(new Sounds.Sound("car.start", 2))
|
||||||
|
.accelerate(new Sounds.Sound("car.accelerate", 2))
|
||||||
|
.driving(new Sounds.Sound("car.driving", 2))
|
||||||
|
.slowingDown(new Sounds.Sound("car.slowingdown", 2))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
public static void convert(CommandSender sender) {
|
||||||
|
sender.sendMessage(__("&7[&3&lVehiclesPlusConverter&7] &fStarting v2 to v3 conversion..."));
|
||||||
|
|
||||||
|
sender.sendMessage(__("&7[&3&lVehiclesPlusConverter&7] &fConverting rim designs..."));
|
||||||
|
convertRims();
|
||||||
|
|
||||||
|
sender.sendMessage(__("&7[&3&lVehiclesPlusConverter&7] &fConverting fuel types..."));
|
||||||
|
convertFuels();
|
||||||
|
|
||||||
|
sender.sendMessage(__("&7[&3&lVehiclesPlusConverter&7] &fConverting vehicle models..."));
|
||||||
|
convertVehicleModels();
|
||||||
|
|
||||||
|
sender.sendMessage(__("&7[&3&lVehiclesPlusConverter&7] &fConverting vehicles..."));
|
||||||
|
convertVehicles();
|
||||||
|
|
||||||
|
Bukkit.getScheduler().runTaskLater(VehiclesPlusConverter.getInstance(), () -> Bukkit.getServer().shutdown(), 20L * 15);
|
||||||
|
new BukkitRunnable() {
|
||||||
|
int counter = 15;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
sender.sendMessage(__("&7[&3&lVehiclesPlusConverter&7] &f" + (counter == 15 ? "Conversion finished! " : "") + "&bRebooting in &3" + counter + " &bseconds..."));
|
||||||
|
counter--;
|
||||||
|
}
|
||||||
|
}.runTaskTimer(VehiclesPlusConverter.getInstance(), 20L, 20L);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void convertRims() {
|
||||||
|
for (Map.Entry<String, RimDesign> entry : VehiclesPlus.getVehicleManager().getRimDesignHashMap().entrySet()) {
|
||||||
|
nl.sbdeveloper.vehiclesplus.api.vehicles.rims.RimDesign rd = nl.sbdeveloper.vehiclesplus.api.vehicles.rims.RimDesign.builder()
|
||||||
|
.name(entry.getValue().getName())
|
||||||
|
.price(entry.getValue().getPrice())
|
||||||
|
.skin(entry.getValue().getSkin())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
nl.sbdeveloper.vehiclesplus.api.VehiclesPlusAPI.getRimDesigns().put(entry.getKey(), rd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void convertFuels() {
|
||||||
|
for (Map.Entry<String, FuelType> entry : VehiclesPlus.getVehicleManager().getFuelTypeHashMap().entrySet()) {
|
||||||
|
nl.sbdeveloper.vehiclesplus.api.vehicles.fuel.FuelType ft = nl.sbdeveloper.vehiclesplus.api.vehicles.fuel.FuelType.builder()
|
||||||
|
.name(entry.getValue().getName())
|
||||||
|
.item(entry.getValue().getFuelItem())
|
||||||
|
.pricePerLiter(entry.getValue().getPricePerLiter())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
nl.sbdeveloper.vehiclesplus.api.VehiclesPlusAPI.getFuelTypes().put(entry.getKey(), ft);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void convertVehicleModels() {
|
||||||
|
for (BaseVehicle baseVehicle : VehiclesPlusAPI.getVehicleManager().getBaseVehicleMap().values()) {
|
||||||
|
try {
|
||||||
|
VehicleModel.VehicleModelBuilder vehicleModelBuilder = VehicleModel.builder()
|
||||||
|
.id(baseVehicle.getName())
|
||||||
|
.displayName(baseVehicle.getName())
|
||||||
|
.typeId(getTypeIdByClass(baseVehicle.getName(), getClassByFullName(baseVehicle.getVehicleType())))
|
||||||
|
.availableColors(baseVehicle.getBaseColorList());
|
||||||
|
|
||||||
|
for (Part part : baseVehicle.getPartList()) {
|
||||||
|
if (part instanceof BikeSeat) {
|
||||||
|
BikeSeat bikeSeat = (BikeSeat) part;
|
||||||
|
vehicleModelBuilder = vehicleModelBuilder.part(new nl.sbdeveloper.vehiclesplus.api.vehicles.parts.impl.seat.BikeSeat(
|
||||||
|
bikeSeat.getXOffset(),
|
||||||
|
bikeSeat.getYOffset(),
|
||||||
|
bikeSeat.getZOffset(),
|
||||||
|
bikeSeat.getSteer()
|
||||||
|
));
|
||||||
|
} else if (part instanceof TurretSeat) {
|
||||||
|
TurretSeat turretSeat = (TurretSeat) part;
|
||||||
|
vehicleModelBuilder = vehicleModelBuilder.part(new nl.sbdeveloper.vehiclesplus.api.vehicles.parts.impl.seat.TurretSeat(
|
||||||
|
turretSeat.getXOffset(),
|
||||||
|
turretSeat.getYOffset(),
|
||||||
|
turretSeat.getZOffset(),
|
||||||
|
baseVehicle.getPartList().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) {
|
||||||
|
Seat seat = (Seat) part;
|
||||||
|
vehicleModelBuilder = vehicleModelBuilder.part(new nl.sbdeveloper.vehiclesplus.api.vehicles.parts.impl.seat.Seat(
|
||||||
|
seat.getXOffset(),
|
||||||
|
seat.getYOffset(),
|
||||||
|
seat.getZOffset(),
|
||||||
|
seat.getSteer()
|
||||||
|
));
|
||||||
|
} else if (part instanceof BikeSkin) {
|
||||||
|
BikeSkin bikeSkin = (BikeSkin) part;
|
||||||
|
vehicleModelBuilder = vehicleModelBuilder.part(new nl.sbdeveloper.vehiclesplus.api.vehicles.parts.impl.skin.BikeSkin(
|
||||||
|
bikeSkin.getXOffset(),
|
||||||
|
bikeSkin.getYOffset(),
|
||||||
|
bikeSkin.getZOffset(),
|
||||||
|
bikeSkin.getSkinColored()
|
||||||
|
));
|
||||||
|
} else if (part instanceof Rotor) {
|
||||||
|
Rotor rotor = (Rotor) part;
|
||||||
|
vehicleModelBuilder = vehicleModelBuilder.part(new nl.sbdeveloper.vehiclesplus.api.vehicles.parts.impl.skin.Rotor(
|
||||||
|
rotor.getXOffset(),
|
||||||
|
rotor.getYOffset(),
|
||||||
|
rotor.getZOffset(),
|
||||||
|
rotor.getSkinColored()
|
||||||
|
));
|
||||||
|
} else if (part instanceof Turret) {
|
||||||
|
Turret turret = (Turret) part;
|
||||||
|
vehicleModelBuilder = vehicleModelBuilder.part(new nl.sbdeveloper.vehiclesplus.api.vehicles.parts.impl.skin.Turret(
|
||||||
|
turret.getXOffset(),
|
||||||
|
turret.getYOffset(),
|
||||||
|
turret.getZOffset(),
|
||||||
|
turret.getSkin(),
|
||||||
|
turret.getExplosionSize(),
|
||||||
|
turret.getAmmo()
|
||||||
|
));
|
||||||
|
} else if (part instanceof Skin) {
|
||||||
|
Skin skin = (Skin) part;
|
||||||
|
vehicleModelBuilder = vehicleModelBuilder.part(new nl.sbdeveloper.vehiclesplus.api.vehicles.parts.impl.skin.Skin(
|
||||||
|
skin.getXOffset(),
|
||||||
|
skin.getYOffset(),
|
||||||
|
skin.getZOffset(),
|
||||||
|
skin.getSkinColored()
|
||||||
|
));
|
||||||
|
} else if (part instanceof Wheel) {
|
||||||
|
Wheel wheel = (Wheel) part;
|
||||||
|
vehicleModelBuilder = vehicleModelBuilder.part(new nl.sbdeveloper.vehiclesplus.api.vehicles.parts.impl.Wheel(
|
||||||
|
wheel.getXOffset(),
|
||||||
|
wheel.getYOffset(),
|
||||||
|
wheel.getZOffset(),
|
||||||
|
VehiclesPlus.getVehicleManager().getRimDesignHashMap().values().stream().findFirst().orElseThrow(() -> new ConversionException("No RimDesign found while loading Wheel in file", baseVehicle.getName())).getName(),
|
||||||
|
wheel.getColor(),
|
||||||
|
wheel.getSteering(),
|
||||||
|
wheel.getRotationOffset()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
VehicleModel model = vehicleModelBuilder
|
||||||
|
.maxSpeed(new UpgradableSetting(
|
||||||
|
baseVehicle.getSpeedSettings().getBase(),
|
||||||
|
baseVehicle.getSpeedSettings().getMax(),
|
||||||
|
baseVehicle.getSpeedSettings().getStep(),
|
||||||
|
baseVehicle.getSpeedSettings().getUpgradeCost()
|
||||||
|
))
|
||||||
|
.fuelTank(new UpgradableSetting(
|
||||||
|
baseVehicle.getFuelTankSettings().getBase(),
|
||||||
|
baseVehicle.getFuelTankSettings().getMax(),
|
||||||
|
baseVehicle.getFuelTankSettings().getStep(),
|
||||||
|
baseVehicle.getFuelTankSettings().getUpgradeCost()
|
||||||
|
))
|
||||||
|
.turningRadius(new UpgradableSetting(
|
||||||
|
baseVehicle.getTurningRadiusSettings().getBase(),
|
||||||
|
baseVehicle.getTurningRadiusSettings().getMax(),
|
||||||
|
baseVehicle.getTurningRadiusSettings().getStep(),
|
||||||
|
baseVehicle.getTurningRadiusSettings().getUpgradeCost()
|
||||||
|
))
|
||||||
|
.acceleration(new UpgradableSetting(
|
||||||
|
baseVehicle.getAccelerationSettings().getBase(),
|
||||||
|
baseVehicle.getAccelerationSettings().getMax(),
|
||||||
|
baseVehicle.getAccelerationSettings().getStep(),
|
||||||
|
baseVehicle.getAccelerationSettings().getUpgradeCost()
|
||||||
|
))
|
||||||
|
.horn(new Horn(
|
||||||
|
baseVehicle.getHornSettings().getEnabled(),
|
||||||
|
baseVehicle.getHornSettings().getSound().name()
|
||||||
|
))
|
||||||
|
.drift(baseVehicle.getDrift())
|
||||||
|
.exhaust(new Exhaust(
|
||||||
|
baseVehicle.getExhaustSettings().getEnabled(),
|
||||||
|
baseVehicle.getExhaustSettings().getXOffset(),
|
||||||
|
baseVehicle.getExhaustSettings().getYOffset(),
|
||||||
|
baseVehicle.getExhaustSettings().getZOffset(),
|
||||||
|
Particle.valueOf(baseVehicle.getExhaustSettings().getParticleName())
|
||||||
|
))
|
||||||
|
.exitWhileMoving(baseVehicle.getCanExitWhileMoving())
|
||||||
|
.price(baseVehicle.getPrice())
|
||||||
|
.fuel(new Fuel(
|
||||||
|
baseVehicle.getFuelSettings().getType(),
|
||||||
|
baseVehicle.getFuelSettings().getUsage()
|
||||||
|
))
|
||||||
|
.health(baseVehicle.getHealth())
|
||||||
|
.trunkSize(baseVehicle.getTrunkSize())
|
||||||
|
.hitbox(new Hitbox(
|
||||||
|
baseVehicle.getHitbox().getLength(),
|
||||||
|
baseVehicle.getHitbox().getWidth(),
|
||||||
|
baseVehicle.getHitbox().getHeight()
|
||||||
|
))
|
||||||
|
.realisticSteering(baseVehicle.getSteeringType())
|
||||||
|
.permissions(Permissions.builder()
|
||||||
|
.buy(baseVehicle.getPermissions().getBuyPermission())
|
||||||
|
.ride(baseVehicle.getPermissions().getRidePermission())
|
||||||
|
.sitWithoutRidePermission(baseVehicle.getPermissions().getEnterWithoutRidePermission())
|
||||||
|
.adjust("vp.adjust." + baseVehicle.getName())
|
||||||
|
.spawn("vp.spawn." + baseVehicle.getName())
|
||||||
|
.build())
|
||||||
|
.sounds(defaultSounds)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
save(model, "vehicles/" + model.getTypeId(), model.getId());
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void convertVehicles() {
|
||||||
|
for (Map.Entry<UUID, List<StorageVehicle>> set : VehiclesPlusAPI.getVehicleManager().getPlayerVehicleHashMap().entrySet()) {
|
||||||
|
UUID ownerUUID = set.getKey();
|
||||||
|
for (StorageVehicle vehicle : set.getValue()) {
|
||||||
|
try {
|
||||||
|
nl.sbdeveloper.vehiclesplus.api.vehicles.impl.StorageVehicle newVehicle = new nl.sbdeveloper.vehiclesplus.api.vehicles.impl.StorageVehicle(
|
||||||
|
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())),
|
||||||
|
ownerUUID
|
||||||
|
);
|
||||||
|
|
||||||
|
newVehicle.save();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getClassByFullName(String name) {
|
||||||
|
String[] split = name.split("\\.");
|
||||||
|
if (split.length == 0) return name;
|
||||||
|
return split[split.length - 1]; //Last position
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getTypeIdByClass(String baseVehicle, String type) throws ConversionException {
|
||||||
|
switch (type) {
|
||||||
|
case "BikeType":
|
||||||
|
return "bike";
|
||||||
|
case "BoatType":
|
||||||
|
return "boat";
|
||||||
|
case "CarType":
|
||||||
|
return "car";
|
||||||
|
case "HelicopterType":
|
||||||
|
return "helicopter";
|
||||||
|
case "HovercraftType":
|
||||||
|
return "hovercraft";
|
||||||
|
case "PlaneType":
|
||||||
|
return "plane";
|
||||||
|
default:
|
||||||
|
throw new InvalidConversionException("vehicleType", baseVehicle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void save(Object data, String subFolder, String fileName) {
|
||||||
|
File parentFolders = new File(nl.sbdeveloper.vehiclesplus.VehiclesPlus.getInstance().getDataFolder(), subFolder);
|
||||||
|
if (!parentFolders.exists() && !parentFolders.mkdirs()) return;
|
||||||
|
|
||||||
|
JSONFile jsonFile = new JSONFile(nl.sbdeveloper.vehiclesplus.VehiclesPlus.getInstance(), subFolder + "/" + fileName);
|
||||||
|
try {
|
||||||
|
jsonFile.write(data);
|
||||||
|
} catch (IOException e) {
|
||||||
|
VehiclesPlusConverter.getInstance().getLogger().log(Level.SEVERE, "Couldn't save to the file " + fileName, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
package tech.sbdevelopment.vehiclesplusconverter;
|
||||||
|
|
||||||
|
public class InvalidConversionException extends ConversionException {
|
||||||
|
public InvalidConversionException(String message, String filename) {
|
||||||
|
super("Invalid " + message + " found in file", filename);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
package tech.sbdevelopment.vehiclesplusconverter;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import tech.sbdevelopment.vehiclesplusconverter.cmd.ConverterCMD;
|
||||||
|
|
||||||
|
public final class VehiclesPlusConverter extends JavaPlugin {
|
||||||
|
private static VehiclesPlusConverter instance;
|
||||||
|
|
||||||
|
public static VehiclesPlusConverter getInstance() {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
instance = this;
|
||||||
|
|
||||||
|
if (!Bukkit.getPluginManager().isPluginEnabled("VehiclesPlusPro") || !Bukkit.getPluginManager().isPluginEnabled("VehiclesPlus")) {
|
||||||
|
Bukkit.getLogger().severe("Make sure both the v2 and v3 fully load without any errors! Disabling the converter...");
|
||||||
|
Bukkit.getPluginManager().disablePlugin(this);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
getCommand("vpconvert").setExecutor(new ConverterCMD());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisable() {
|
||||||
|
instance = null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
package tech.sbdevelopment.vehiclesplusconverter.cmd;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import tech.sbdevelopment.vehiclesplusconverter.Converter;
|
||||||
|
|
||||||
|
import static tech.sbdevelopment.vehiclesplusconverter.utils.MainUtil.__;
|
||||||
|
|
||||||
|
public class ConverterCMD implements CommandExecutor {
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||||
|
if (label.equalsIgnoreCase("vpconvert")) {
|
||||||
|
if (!sender.hasPermission("vpconvert.convert")) {
|
||||||
|
sender.sendMessage(__("&7[&3&lVehiclesPlusConverter&7] &fYou do not have the right permissions to use this command."));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.length >= 1 && args[0].equalsIgnoreCase("confirm")) {
|
||||||
|
Converter.convert(sender);
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(__("&7[&3&lVehiclesPlusConverter&7] &fPlease use &b/vpconvert confirm &fto start the conversion!"));
|
||||||
|
sender.sendMessage(__("&7[&3&lVehiclesPlusConverter&7] &4&lPLEASE NOTE: &cExisting v3 vehicles may be overwritten! &c&lCreate a backup before confirming."));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
package tech.sbdevelopment.vehiclesplusconverter.utils;
|
||||||
|
|
||||||
|
import net.md_5.bungee.api.ChatColor;
|
||||||
|
|
||||||
|
public class MainUtil {
|
||||||
|
public static String __(String in) {
|
||||||
|
return ChatColor.translateAlternateColorCodes('&', in);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,60 @@
|
||||||
|
/*
|
||||||
|
* This file is part of MapReflectionAPI.
|
||||||
|
* Copyright (c) 2022 inventivetalent / SBDevelopment - All Rights Reserved
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package tech.sbdevelopment.vehiclesplusconverter.utils;
|
||||||
|
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
public class YamlFile {
|
||||||
|
private final JavaPlugin plugin;
|
||||||
|
private final File file;
|
||||||
|
private FileConfiguration fileConfiguration;
|
||||||
|
|
||||||
|
public YamlFile(JavaPlugin plugin, File file) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.file = file;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reload() {
|
||||||
|
this.fileConfiguration = YamlConfiguration.loadConfiguration(this.file);
|
||||||
|
}
|
||||||
|
|
||||||
|
public FileConfiguration getFile() {
|
||||||
|
if (this.fileConfiguration == null)
|
||||||
|
reload();
|
||||||
|
|
||||||
|
return this.fileConfiguration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void save() {
|
||||||
|
if (this.fileConfiguration == null || this.file == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
this.fileConfiguration.save(this.file);
|
||||||
|
} catch (IOException e) {
|
||||||
|
plugin.getLogger().log(Level.SEVERE, "Couldn't save the file " + file.getName() + ".", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
name: VehiclesPlusConverter
|
||||||
|
version: '${project.version}'
|
||||||
|
main: tech.sbdevelopment.vehiclesplusconverter.VehiclesPlusConverter
|
||||||
|
api-version: 1.19
|
||||||
|
authors: [ SBDeveloper ]
|
||||||
|
description: Conversion plugin for v2 to v3.
|
||||||
|
website: sbdevelopment.tech
|
||||||
|
softdepend: [ VehiclesPlusPro, VehiclesPlus ]
|
||||||
|
commands:
|
||||||
|
vpconvert:
|
||||||
|
description: Convert the v2 to v3 data.
|
||||||
|
permission: vpconvert.convert
|
||||||
|
permissions:
|
||||||
|
vpconvert.convert:
|
||||||
|
description: Use the /vpconvert command
|
||||||
|
default: op
|
Loading…
Reference in New Issue