♻️ Cleanup
This commit is contained in:
parent
758a4613d0
commit
feec8e6628
6 changed files with 56 additions and 107 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue