Added save

master
Alexander B 4 years ago
parent 9d151e84df
commit 7d45f94ce3

@ -6,6 +6,7 @@ import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
@ -13,11 +14,15 @@ import java.io.File;
public class Main extends JavaPlugin { public class Main extends JavaPlugin {
public static Plugin plugin;
public static FileConfiguration config; public static FileConfiguration config;
public static FileConfiguration data; public static FileConfiguration data;
public void onEnable() { public void onEnable() {
plugin = this;
PluginManager pluginManager = Bukkit.getPluginManager(); PluginManager pluginManager = Bukkit.getPluginManager();
pluginManager.registerEvents(new OnBlockPlace(), this); pluginManager.registerEvents(new OnBlockPlace(), this);
pluginManager.registerEvents(new OnBlockBreak(), this); pluginManager.registerEvents(new OnBlockBreak(), this);

@ -7,6 +7,8 @@ import org.bukkit.entity.Player;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
import java.io.IOException;
public class OnBlockPlace implements Listener { public class OnBlockPlace implements Listener {
public void onBlockPlaceEvent(BlockPlaceEvent e){ public void onBlockPlaceEvent(BlockPlaceEvent e){
@ -30,6 +32,12 @@ public class OnBlockPlace implements Listener {
else{ else{
// Write place-data // Write place-data
Main.data.set(Main.serialiseLocation(loc), isAdmin); Main.data.set(Main.serialiseLocation(loc), isAdmin);
try {
Main.data.save("data.yml");
} catch (IOException ex) {
Main.plugin.getLogger().severe("Cannot save data to data.yml! Data will lost after restart!");
ex.printStackTrace();
}
// Send msg // Send msg
String msg = Main.config.getString("place.player.msg.success"); String msg = Main.config.getString("place.player.msg.success");

Loading…
Cancel
Save