Skip to content

Commit

Permalink
Beginning work towards new config structure.
Browse files Browse the repository at this point in the history
  • Loading branch information
joserodpt committed Nov 25, 2024
1 parent 3d9a3a1 commit bfd1733
Show file tree
Hide file tree
Showing 28 changed files with 775 additions and 539 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.bukkit.plugin.java.JavaPlugin;

import java.util.Random;
import java.util.logging.Logger;

public abstract class RealMinesAPI {

Expand Down Expand Up @@ -49,6 +50,8 @@ public static void setInstance(RealMinesAPI instance) {

public abstract JavaPlugin getPlugin();

public abstract Logger getLogger();

public abstract MineManagerAPI getMineManager();

public abstract MineResetTasksManagerAPI getMineResetTasksManager();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,29 @@
import java.io.IOException;
import java.util.logging.Level;

public class RMMinesConfig implements Listener {
public class RMMinesOldConfig implements Listener {

private static final String name = "mines.yml";
private static YamlDocument configFile;
private static boolean fileExists;

public static void setup(final JavaPlugin rm) {
try {
configFile = YamlDocument.create(new File(rm.getDataFolder(), name), rm.getResource(name),
GeneralSettings.DEFAULT,
LoaderSettings.builder().setMaxCollectionAliases(200).setAutoUpdate(true).build(),
DumperSettings.DEFAULT,
UpdaterSettings.builder().setVersioning(new BasicVersioning("Version")).build());
File file = new File(rm.getDataFolder(), name);
fileExists = file.exists();
if (fileExists) {
configFile = YamlDocument.create(file,
GeneralSettings.DEFAULT,
LoaderSettings.builder().setMaxCollectionAliases(200).setAutoUpdate(true).build(),
DumperSettings.DEFAULT,
UpdaterSettings.builder().setVersioning(new BasicVersioning("Version")).build());

//if it doesn't exist, create a minesBACKUP.yml file that is a copy of the mines.yml file
File backupFile = new File(rm.getDataFolder(), "minesBACKUP.yml");
if (!backupFile.exists()) {
configFile.save(backupFile);
}
}
} catch (final IOException e) {
Bukkit.getLogger().log(Level.SEVERE, "Couldn't setup " + name + "!");
}
Expand All @@ -48,19 +59,15 @@ public static YamlDocument file() {
return configFile;
}

public static boolean fileExists() {
return fileExists;
}

public static void save() {
try {
configFile.save();
} catch (final IOException e) {
Bukkit.getLogger().log(Level.SEVERE, "Couldn't save " + name + "!");
}
}

public static void reload() {
try {
configFile.reload();
} catch (final IOException e) {
Bukkit.getLogger().log(Level.SEVERE, "Couldn't reload " + name + "!");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,10 @@
import de.c4t4lysm.catamines.schedulers.MineManager;
import de.c4t4lysm.catamines.utils.mine.mines.CuboidCataMine;
import joserodpt.realmines.api.RealMinesAPI;
import joserodpt.realmines.api.mine.RMine;
import joserodpt.realmines.api.mine.components.MineColor;
import joserodpt.realmines.api.mine.components.items.MineBlockItem;
import joserodpt.realmines.api.mine.types.BlockMine;
import joserodpt.realmines.api.utils.Text;
import joserodpt.realmines.api.utils.WorldEditUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;

import java.util.ArrayList;
import java.util.HashMap;

public class CataMinesConverter implements RMConverterBase {
private final RealMinesAPI rm;

Expand Down Expand Up @@ -62,6 +52,8 @@ public void convert(CommandSender cmd) {

Text.send(cmd, " &f> Mine has &b" + cataMine.getBlocks().size() + "&f blocks.");

//TODO
/*
final BlockMine m = new BlockMine(Bukkit.getWorld(cataMine.getWorld()), ChatColor.stripColor(Text.color(cataMine.getName())), cataMine.getName(), new HashMap<>(), new ArrayList<>(), WorldEditUtils.toLocation(cataMine.getRegion().getMinimumPoint(), Bukkit.getWorld(cataMine.getWorld())), WorldEditUtils.toLocation(cataMine.getRegion().getMaximumPoint(), Bukkit.getWorld(cataMine.getWorld())),
Material.COBBLESTONE, null, false, true, 20, 60, MineColor.WHITE, new HashMap<>(), false, false, rm.getMineManager());
Expand Down Expand Up @@ -90,13 +82,15 @@ public void convert(CommandSender cmd) {
if (cataMine.getTeleportLocation().getY() >= 0) {
Text.send(cmd, " &f> Importing mine teleport position.");
m.setTeleport(cataMine.getTeleportLocation());
m.saveData(RMine.Data.TELEPORT);
m.saveData(RMine.MineData.TELEPORT);
}
m.saveAll();
rm.getMineManager().addMine(m);
Text.send(cmd, "&aSucessfully imported mine " + m.getDisplayName());
*/
}

//end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,14 @@
*/

import dev.dejvokep.boostedyaml.YamlDocument;
import dev.dejvokep.boostedyaml.block.implementation.Section;
import joserodpt.realmines.api.RealMinesAPI;
import joserodpt.realmines.api.mine.RMine;
import joserodpt.realmines.api.mine.components.MineColor;
import joserodpt.realmines.api.mine.components.items.MineBlockItem;
import joserodpt.realmines.api.mine.types.BlockMine;
import joserodpt.realmines.api.utils.Text;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.command.CommandSender;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;

Expand Down Expand Up @@ -90,6 +81,9 @@ public void convert(CommandSender cmd) {

Location max = new Location(w, xMax, yMax, zMax);


//TODO
/*
final BlockMine m = new BlockMine(w, ChatColor.stripColor(Text.color(mineName)), mineName, new HashMap<>(), new ArrayList<>(), min, max,
Material.GOLDEN_PICKAXE, null, false, true, 20, 60, MineColor.WHITE, new HashMap<>(), false, false, rm.getMineManager());
Expand Down Expand Up @@ -153,6 +147,8 @@ public void convert(CommandSender cmd) {
rm.getMineManager().addMine(m);
Text.send(cmd, "&aSucessfully imported mine " + m.getDisplayName());
*/

} catch (IllegalArgumentException e) {
Text.send(cmd, "&cError: This mine has a location that has an unknown world. &fSkipping!");
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,13 @@
*/

import joserodpt.realmines.api.RealMinesAPI;
import joserodpt.realmines.api.mine.RMine;
import joserodpt.realmines.api.mine.components.MineColor;
import joserodpt.realmines.api.mine.components.items.MineBlockItem;
import joserodpt.realmines.api.mine.types.BlockMine;
import joserodpt.realmines.api.utils.Text;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.configuration.serialization.ConfigurationSerialization;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -74,6 +68,8 @@ public void convert(CommandSender cmd) {

Text.send(cmd, " &f> Mine has &b" + blocks.size() + "&f blocks.");

//TODO
/*
final BlockMine m = new BlockMine(MRLmine.getWorld(), ChatColor.stripColor(Text.color(MRLmine.getName())), MRLmine.getName(), new HashMap<>(), new ArrayList<>(), MRLmine.getMin(), MRLmine.getMax(),
Material.COBBLESTONE, null, false, true, 20, 60, MineColor.WHITE, new HashMap<>(), false, false, rm.getMineManager());
Expand All @@ -91,13 +87,15 @@ public void convert(CommandSender cmd) {
if (MRLmine.getTpY() >= 0) {
Text.send(cmd, " &f> Importing mine teleport position.");
m.setTeleport(MRLmine.getTpPos());
m.saveData(RMine.Data.TELEPORT);
m.saveData(RMine.MineData.TELEPORT);
}
m.saveAll();
rm.getMineManager().addMine(m);
Text.send(cmd, "&aSucessfully imported mine " + m.getDisplayName());
*/
}
//end
Text.send(cmd, "&aEnded Mine Import Process from &b" + this.getPlugin().getSourceName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import joserodpt.realmines.api.mine.components.MineIcon;
import joserodpt.realmines.api.mine.components.MineSign;
import joserodpt.realmines.api.mine.components.items.MineItem;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
Expand All @@ -27,8 +26,6 @@
import java.util.Map;

public abstract class MineManagerAPI {
protected abstract Map<Material, MineItem> getBlocks(String mineName, RMine.Type type);

public abstract List<String> getRegisteredMines();

public abstract void loadMines();
Expand All @@ -39,10 +36,6 @@ public abstract class MineManagerAPI {

public abstract void createSchematicMine(Player p, String name);

public abstract void saveAllMineData(RMine mine);

public abstract void saveMine(RMine mine, RMine.Data t);

public abstract List<MineIcon> getMineList();

//permission for teleport: realmines.tp.<name>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package joserodpt.realmines.api.mine;

import joserodpt.realmines.api.mine.components.items.MineItem;
import org.bukkit.Material;

import java.util.Map;

public class RMBlockSet {

String name;
Map<Material, MineItem> items;

public RMBlockSet(String name, Map<Material, MineItem> items) {
this.name = name;
this.items = items;
}

public String getName() {
return name;
}

public Map<Material, MineItem> getItems() {
return items;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package joserodpt.realmines.api.mine;

public class RMFailedToLoadException extends Exception {
private final String mineName;
private final String reason;

public RMFailedToLoadException(String mineName, String reason) {
super("RealMines '" + mineName + "' did not load properly: " + reason);
this.mineName = mineName;
this.reason = reason;
}

public String getMineName() {
return mineName;
}

public String getReason() {
return reason;
}
}
Loading

0 comments on commit bfd1733

Please sign in to comment.