♻️ Cleanup

This commit is contained in:
SBDeveloper 2022-11-10 21:02:03 +01:00
parent 758a4613d0
commit feec8e6628
6 changed files with 56 additions and 107 deletions

View File

@ -1,4 +1,4 @@
package tech.sbdevelopment.vehiclesplusconverter;
package tech.sbdevelopment.vehiclesplusconverter.api;
import java.io.IOException;

View File

@ -1,4 +1,4 @@
package tech.sbdevelopment.vehiclesplusconverter;
package tech.sbdevelopment.vehiclesplusconverter.api;
public class InvalidConversionException extends ConversionException {
public InvalidConversionException(String message, String filename) {

View File

@ -4,7 +4,7 @@ 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 tech.sbdevelopment.vehiclesplusconverter.handlers.Converter;
import static tech.sbdevelopment.vehiclesplusconverter.utils.MainUtil.__;

View File

@ -1,4 +1,4 @@
package tech.sbdevelopment.vehiclesplusconverter;
package tech.sbdevelopment.vehiclesplusconverter.handlers;
import me.legofreak107.vehiclesplus.VehiclesPlus;
import me.legofreak107.vehiclesplus.vehicles.api.VehiclesPlusAPI;
@ -18,20 +18,18 @@ import me.legofreak107.vehiclesplus.vehicles.vehicles.objects.addons.skins.Turre
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 tech.sbdevelopment.vehiclesplusconverter.VehiclesPlusConverter;
import tech.sbdevelopment.vehiclesplusconverter.api.ConversionException;
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.__;
import static tech.sbdevelopment.vehiclesplusconverter.utils.MainUtil.*;
public class Converter {
private Converter() {
@ -239,7 +237,7 @@ public class Converter {
.sounds(defaultSounds)
.build();
save(model, "vehicles/" + model.getTypeId(), model.getId());
saveToVehiclesPlus(model, "vehicles/" + model.getTypeId(), model.getId());
} catch (Exception e) {
e.printStackTrace();
}
@ -263,41 +261,4 @@ public class Converter {
}
}
}
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);
}
}
}

View File

@ -1,9 +1,57 @@
package tech.sbdevelopment.vehiclesplusconverter.utils;
import net.md_5.bungee.api.ChatColor;
import nl.sbdeveloper.vehiclesplus.storage.file.JSONFile;
import tech.sbdevelopment.vehiclesplusconverter.VehiclesPlusConverter;
import tech.sbdevelopment.vehiclesplusconverter.api.ConversionException;
import tech.sbdevelopment.vehiclesplusconverter.api.InvalidConversionException;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
public class MainUtil {
private MainUtil() {
}
public static String __(String in) {
return ChatColor.translateAlternateColorCodes('&', in);
}
public static String getClassByFullName(String name) {
String[] split = name.split("\\.");
if (split.length == 0) return name;
return split[split.length - 1]; //Last position
}
public 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);
}
}
public static void saveToVehiclesPlus(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);
}
}
}

View File

@ -1,60 +0,0 @@
/*
* 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);
}
}
}