From feec8e6628d5833197c72298c9185a3ded62f714 Mon Sep 17 00:00:00 2001 From: SBDeveloper Date: Thu, 10 Nov 2022 21:02:03 +0100 Subject: [PATCH] :recycle: Cleanup --- .../{ => api}/ConversionException.java | 2 +- .../{ => api}/InvalidConversionException.java | 2 +- .../cmd/ConverterCMD.java | 2 +- .../{ => handlers}/Converter.java | 49 ++------------- .../vehiclesplusconverter/utils/MainUtil.java | 48 +++++++++++++++ .../vehiclesplusconverter/utils/YamlFile.java | 60 ------------------- 6 files changed, 56 insertions(+), 107 deletions(-) rename src/main/java/tech/sbdevelopment/vehiclesplusconverter/{ => api}/ConversionException.java (79%) rename src/main/java/tech/sbdevelopment/vehiclesplusconverter/{ => api}/InvalidConversionException.java (80%) rename src/main/java/tech/sbdevelopment/vehiclesplusconverter/{ => handlers}/Converter.java (89%) delete mode 100644 src/main/java/tech/sbdevelopment/vehiclesplusconverter/utils/YamlFile.java diff --git a/src/main/java/tech/sbdevelopment/vehiclesplusconverter/ConversionException.java b/src/main/java/tech/sbdevelopment/vehiclesplusconverter/api/ConversionException.java similarity index 79% rename from src/main/java/tech/sbdevelopment/vehiclesplusconverter/ConversionException.java rename to src/main/java/tech/sbdevelopment/vehiclesplusconverter/api/ConversionException.java index ad69383..92a46c7 100644 --- a/src/main/java/tech/sbdevelopment/vehiclesplusconverter/ConversionException.java +++ b/src/main/java/tech/sbdevelopment/vehiclesplusconverter/api/ConversionException.java @@ -1,4 +1,4 @@ -package tech.sbdevelopment.vehiclesplusconverter; +package tech.sbdevelopment.vehiclesplusconverter.api; import java.io.IOException; diff --git a/src/main/java/tech/sbdevelopment/vehiclesplusconverter/InvalidConversionException.java b/src/main/java/tech/sbdevelopment/vehiclesplusconverter/api/InvalidConversionException.java similarity index 80% rename from src/main/java/tech/sbdevelopment/vehiclesplusconverter/InvalidConversionException.java rename to src/main/java/tech/sbdevelopment/vehiclesplusconverter/api/InvalidConversionException.java index 9f679d4..03f81be 100644 --- a/src/main/java/tech/sbdevelopment/vehiclesplusconverter/InvalidConversionException.java +++ b/src/main/java/tech/sbdevelopment/vehiclesplusconverter/api/InvalidConversionException.java @@ -1,4 +1,4 @@ -package tech.sbdevelopment.vehiclesplusconverter; +package tech.sbdevelopment.vehiclesplusconverter.api; public class InvalidConversionException extends ConversionException { public InvalidConversionException(String message, String filename) { diff --git a/src/main/java/tech/sbdevelopment/vehiclesplusconverter/cmd/ConverterCMD.java b/src/main/java/tech/sbdevelopment/vehiclesplusconverter/cmd/ConverterCMD.java index 2c3fea9..ec42e3b 100644 --- a/src/main/java/tech/sbdevelopment/vehiclesplusconverter/cmd/ConverterCMD.java +++ b/src/main/java/tech/sbdevelopment/vehiclesplusconverter/cmd/ConverterCMD.java @@ -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.__; diff --git a/src/main/java/tech/sbdevelopment/vehiclesplusconverter/Converter.java b/src/main/java/tech/sbdevelopment/vehiclesplusconverter/handlers/Converter.java similarity index 89% rename from src/main/java/tech/sbdevelopment/vehiclesplusconverter/Converter.java rename to src/main/java/tech/sbdevelopment/vehiclesplusconverter/handlers/Converter.java index e3ef13a..1a596f0 100644 --- a/src/main/java/tech/sbdevelopment/vehiclesplusconverter/Converter.java +++ b/src/main/java/tech/sbdevelopment/vehiclesplusconverter/handlers/Converter.java @@ -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); - } - } } diff --git a/src/main/java/tech/sbdevelopment/vehiclesplusconverter/utils/MainUtil.java b/src/main/java/tech/sbdevelopment/vehiclesplusconverter/utils/MainUtil.java index 668bf87..6bf2a44 100644 --- a/src/main/java/tech/sbdevelopment/vehiclesplusconverter/utils/MainUtil.java +++ b/src/main/java/tech/sbdevelopment/vehiclesplusconverter/utils/MainUtil.java @@ -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); + } + } } diff --git a/src/main/java/tech/sbdevelopment/vehiclesplusconverter/utils/YamlFile.java b/src/main/java/tech/sbdevelopment/vehiclesplusconverter/utils/YamlFile.java deleted file mode 100644 index 56516c3..0000000 --- a/src/main/java/tech/sbdevelopment/vehiclesplusconverter/utils/YamlFile.java +++ /dev/null @@ -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 . - */ - -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); - } - } -} \ No newline at end of file