Bumped to v3.03; fixes rim design conversion + trunk
This commit is contained in:
parent
2bbb5a0fc3
commit
a232097745
4 changed files with 112 additions and 13 deletions
6
pom.xml
6
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.4</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>VehiclesPlusConverter</name>
|
<name>VehiclesPlusConverter</name>
|
||||||
|
@ -80,9 +80,9 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>nl.sbdeveloper</groupId>
|
<groupId>nl.sbdeveloper</groupId>
|
||||||
<artifactId>VehiclesPlus-v3</artifactId>
|
<artifactId>VehiclesPlus-v3</artifactId>
|
||||||
<version>3.0.1</version>
|
<version>3.0.3</version>
|
||||||
<scope>system</scope>
|
<scope>system</scope>
|
||||||
<systemPath>${project.basedir}/src/libs/VehiclesPlus-3.0.1.jar</systemPath>
|
<systemPath>${project.basedir}/src/libs/VehiclesPlus-3.0.3.jar</systemPath>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -30,8 +30,8 @@ public final class VehiclesPlusConverter extends JavaPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
Version versionNew = Version.of(Bukkit.getPluginManager().getPlugin("VehiclesPlus").getDescription().getVersion());
|
Version versionNew = Version.of(Bukkit.getPluginManager().getPlugin("VehiclesPlus").getDescription().getVersion());
|
||||||
if (versionNew.isOlderThan(Version.of("3.0.2"))) {
|
if (versionNew.isOlderThan(Version.of("3.0.3"))) {
|
||||||
Bukkit.getLogger().severe("Your VehiclesPlus v3 plugin is too old! Please update to at least v3.0.2!");
|
Bukkit.getLogger().severe("Your VehiclesPlus v3 plugin is too old! Please update to at least v3.0.3!");
|
||||||
Bukkit.getPluginManager().disablePlugin(this);
|
Bukkit.getPluginManager().disablePlugin(this);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,12 +25,15 @@ import nl.sbdeveloper.vehiclesplus.utils.jackson.ColorList;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
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.io.File;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
@ -93,6 +96,7 @@ public class Converter {
|
||||||
);
|
);
|
||||||
|
|
||||||
nl.sbdeveloper.vehiclesplus.api.VehiclesPlusAPI.getRimDesigns().put(entry.getKey(), rd);
|
nl.sbdeveloper.vehiclesplus.api.VehiclesPlusAPI.getRimDesigns().put(entry.getKey(), rd);
|
||||||
|
rd.save();
|
||||||
|
|
||||||
VehiclesPlusConverter.getInstance().getLogger().info("Converted rim design: " + rd.getName());
|
VehiclesPlusConverter.getInstance().getLogger().info("Converted rim design: " + rd.getName());
|
||||||
}
|
}
|
||||||
|
@ -107,6 +111,7 @@ public class Converter {
|
||||||
);
|
);
|
||||||
|
|
||||||
nl.sbdeveloper.vehiclesplus.api.VehiclesPlusAPI.getFuelTypes().put(entry.getKey(), ft);
|
nl.sbdeveloper.vehiclesplus.api.VehiclesPlusAPI.getFuelTypes().put(entry.getKey(), ft);
|
||||||
|
ft.save();
|
||||||
|
|
||||||
VehiclesPlusConverter.getInstance().getLogger().info("Converted fuel type: " + ft.getName());
|
VehiclesPlusConverter.getInstance().getLogger().info("Converted fuel type: " + ft.getName());
|
||||||
}
|
}
|
||||||
|
@ -198,20 +203,52 @@ public class Converter {
|
||||||
));
|
));
|
||||||
} else if (part instanceof Wheel) {
|
} else if (part instanceof Wheel) {
|
||||||
Wheel wheel = (Wheel) part;
|
Wheel wheel = (Wheel) part;
|
||||||
|
ItemStack wheelSkin = wheel.getSkinColored();
|
||||||
|
|
||||||
|
// Try to find an existing rim design with this skin
|
||||||
|
Optional<nl.sbdeveloper.vehiclesplus.api.vehicles.rims.RimDesign> matchingRimDesign = nl.sbdeveloper.vehiclesplus.api.VehiclesPlusAPI.getRimDesigns()
|
||||||
|
.values()
|
||||||
|
.stream()
|
||||||
|
.filter(rd -> compareItems(rd.getSkin(), wheelSkin))
|
||||||
|
.findFirst();
|
||||||
|
|
||||||
|
if (matchingRimDesign.isEmpty()) {
|
||||||
|
// Create a new rim design since no matching one exists
|
||||||
|
String newRimDesignName = generateRimName();
|
||||||
|
nl.sbdeveloper.vehiclesplus.api.vehicles.rims.RimDesign newRimDesign = new nl.sbdeveloper.vehiclesplus.api.vehicles.rims.RimDesign(
|
||||||
|
newRimDesignName,
|
||||||
|
wheelSkin,
|
||||||
|
HolderItemPosition.HEAD,
|
||||||
|
1000
|
||||||
|
);
|
||||||
|
|
||||||
|
// Add the new rim design to the rim designs map
|
||||||
|
nl.sbdeveloper.vehiclesplus.api.VehiclesPlusAPI.getRimDesigns().put(newRimDesignName, newRimDesign);
|
||||||
|
newRimDesign.save();
|
||||||
|
VehiclesPlusConverter.getInstance().getLogger().info("Created new rim design '" + newRimDesignName + "' for wheel skin!");
|
||||||
|
|
||||||
|
// Create the wheel part with the new rim design
|
||||||
vehicleModelBuilder = vehicleModelBuilder.part(new nl.sbdeveloper.vehiclesplus.api.vehicles.parts.impl.Wheel(
|
vehicleModelBuilder = vehicleModelBuilder.part(new nl.sbdeveloper.vehiclesplus.api.vehicles.parts.impl.Wheel(
|
||||||
wheel.getXOffset(),
|
wheel.getXOffset(),
|
||||||
wheel.getYOffset(),
|
wheel.getYOffset(),
|
||||||
wheel.getZOffset(),
|
wheel.getZOffset(),
|
||||||
nl.sbdeveloper.vehiclesplus.api.VehiclesPlusAPI.getRimDesign(VehiclesPlus.getVehicleManager().getRimDesignHashMap().values()
|
newRimDesign,
|
||||||
.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()
|
||||||
));
|
));
|
||||||
|
} else {
|
||||||
|
// Use the existing rim design that matches the skin
|
||||||
|
vehicleModelBuilder = vehicleModelBuilder.part(new nl.sbdeveloper.vehiclesplus.api.vehicles.parts.impl.Wheel(
|
||||||
|
wheel.getXOffset(),
|
||||||
|
wheel.getYOffset(),
|
||||||
|
wheel.getZOffset(),
|
||||||
|
matchingRimDesign.get(),
|
||||||
|
wheel.getColor(),
|
||||||
|
wheel.getSteering(),
|
||||||
|
wheel.getRotationOffset()
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -349,6 +386,9 @@ public class Converter {
|
||||||
newVehicle.getStatics().setBroken(vehicle.getVehicleStats().getBroken());
|
newVehicle.getStatics().setBroken(vehicle.getVehicleStats().getBroken());
|
||||||
newVehicle.getStatics().setCurrentHealth(vehicle.getVehicleStats().getHealth());
|
newVehicle.getStatics().setCurrentHealth(vehicle.getVehicleStats().getHealth());
|
||||||
|
|
||||||
|
// Set the trunk
|
||||||
|
newVehicle.getTrunkItems().addAll(Arrays.asList(vehicle.getVehicleTrunk().getContents()));
|
||||||
|
|
||||||
newVehicle.forceSave();
|
newVehicle.forceSave();
|
||||||
garage.addVehicle(newVehicle.getUuid());
|
garage.addVehicle(newVehicle.getUuid());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package tech.sbdevelopment.vehiclesplusconverter.utils;
|
||||||
import com.google.common.io.Files;
|
import com.google.common.io.Files;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import nl.sbdeveloper.vehiclesplus.storage.file.HJSONFile;
|
import nl.sbdeveloper.vehiclesplus.storage.file.HJSONFile;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import tech.sbdevelopment.vehiclesplusconverter.VehiclesPlusConverter;
|
import tech.sbdevelopment.vehiclesplusconverter.VehiclesPlusConverter;
|
||||||
import tech.sbdevelopment.vehiclesplusconverter.api.ConversionException;
|
import tech.sbdevelopment.vehiclesplusconverter.api.ConversionException;
|
||||||
|
@ -86,4 +87,62 @@ public class MainUtil {
|
||||||
VehiclesPlusConverter.getInstance().getLogger().log(Level.SEVERE, "Couldn't save to the file " + fileName, e);
|
VehiclesPlusConverter.getInstance().getLogger().log(Level.SEVERE, "Couldn't save to the file " + fileName, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compare two ItemStacks for equality based on material type and metadata
|
||||||
|
*
|
||||||
|
* @param item1 First ItemStack
|
||||||
|
* @param item2 Second ItemStack
|
||||||
|
* @return true if the items are considered equal
|
||||||
|
*/
|
||||||
|
public static boolean compareItems(ItemStack item1, ItemStack item2) {
|
||||||
|
if (item1 == null || item2 == null) return false;
|
||||||
|
if (!item1.getType().equals(item2.getType())) return false;
|
||||||
|
|
||||||
|
org.bukkit.inventory.meta.ItemMeta meta1 = item1.getItemMeta();
|
||||||
|
org.bukkit.inventory.meta.ItemMeta meta2 = item2.getItemMeta();
|
||||||
|
|
||||||
|
if (meta1 == null || meta2 == null) return meta1 == meta2;
|
||||||
|
|
||||||
|
// Check CustomModelData if available (1.14+)
|
||||||
|
try {
|
||||||
|
return meta1.hasCustomModelData() && meta2.hasCustomModelData()
|
||||||
|
&& meta1.getCustomModelData() == meta2.getCustomModelData();
|
||||||
|
} catch (NoSuchMethodError ignored) {
|
||||||
|
// Pre 1.14, check Durability/Damage value instead
|
||||||
|
return item1.getDurability() == item2.getDurability();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final String[] RIM_PREFIXES = {
|
||||||
|
"sport", "racing", "luxury", "classic", "vintage", "modern", "elite", "premium", "pro", "ultra"
|
||||||
|
};
|
||||||
|
|
||||||
|
private static final String[] RIM_TYPES = {
|
||||||
|
"star", "spoke", "mesh", "alloy", "chrome", "forged", "cast", "split", "blade", "wave"
|
||||||
|
};
|
||||||
|
|
||||||
|
private static final String[] RIM_SUFFIXES = {
|
||||||
|
"design", "series", "line", "edition", "collection", "style", "plus", "max", "elite", "pro"
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a realistic rim design name
|
||||||
|
*
|
||||||
|
* @return A random rim design name
|
||||||
|
*/
|
||||||
|
public static String generateRimName() {
|
||||||
|
String prefix = RIM_PREFIXES[(int) (Math.random() * RIM_PREFIXES.length)];
|
||||||
|
String type = RIM_TYPES[(int) (Math.random() * RIM_TYPES.length)];
|
||||||
|
String suffix = RIM_SUFFIXES[(int) (Math.random() * RIM_SUFFIXES.length)];
|
||||||
|
|
||||||
|
// Add a random number between 100 and 999
|
||||||
|
int number = 100 + (int) (Math.random() * 900);
|
||||||
|
|
||||||
|
// Convert to PascalCase
|
||||||
|
return prefix.substring(0, 1).toUpperCase() + prefix.substring(1) +
|
||||||
|
type.substring(0, 1).toUpperCase() + type.substring(1) +
|
||||||
|
suffix.substring(0, 1).toUpperCase() + suffix.substring(1) +
|
||||||
|
number;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue