- Баллы
- 78
- Имя в Minecraft
- PuxTa4
Вот как я его использовалА что вы сделали для этого? Оно же не будет все само делаться.
Я вам код весь нужный предоставил, вам осталось только додуматься как его использовать.
Код:
package ru.ShaKe.AGP;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.logging.Logger;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
public class Core extends JavaPlugin {
public final Logger logger = Logger.getLogger("Minecraft");
public final AdvancedGriefProtectionListener agp = new AdvancedGriefProtectionListener(this);
public final CubeGenerateProtect cgp = new CubeGenerateProtect(this);
public final Methods m = new Methods();
public final AdvancedGriefProtectionCommandListener ce = new AdvancedGriefProtectionCommandListener(this);
public ArrayList<Location> protectedBlocks = new ArrayList<Location>();
public Location start = null;
public Location end = null;
public int ID = 0;
public void onEnable() {
PluginManager pm = getServer().getPluginManager();
PluginDescriptionFile pdfFile = this.getDescription();
getCommand("protect").setExecutor(ce);
this.logger.info(" [AdvancedProtection] " + pdfFile.getName() + " Version " + pdfFile.getVersion() + " Has Been Enabled! ");
this.logger.info(" [AdvancedProtection] Plugin Made By" + pdfFile.getAuthors());
pm.registerEvents(agp, this);
}
public void onDisable() {
}
public class RegionData
{
Location start;//начальные координаты
Location end;//конченые координаты
String name = "";//имя
//конструктор по-умолчанию
public RegionData(Location start, Location end, String name)
{
this.start = start;
this.end = end;
this.name = name;
}
//get-, set-методы
public String getName()
{
return name;
}
public Location getStartLocation()
{
return start;
}
public Location getEndLocation()
{
return end;
}
public void setName(String val)
{
name = val;
}
public void setStartLocation(Location val)
{
start = val;
}
public void setEndLocation(Location val)
{
end = val;
}
}
Map<String, RegionData> regions = new HashMap<String, RegionData>();
//загразка
public void Load()
{
File f = new File(this.getDataFolder().getAbsolutePath()+"/regions.yml");//ищем файл regions.yml
if(!f.exists())//если его нет, пропускаем код ниже
return;
FileConfiguration data = YamlConfiguration.loadConfiguration(f);//загружаем кофиг
Set <String> keys = data.getKeys(false);//ключевые значения главной секции из конфига.
for(String region : keys)//проходим по списку
{
RegionData rg;//объявление переменной типа RegionData
String world = data.getString(region + ".world");
Location start = data.getVector(region + ".start").toLocation(Bukkit.getWorld(world));
Location end = data.getVector(region + ".end").toLocation(Bukkit.getWorld(world));
rg = new RegionData(start, end, region);
regions.put(region, rg);
}
}
public void Save()
{
File f = new File(this.getDataFolder().getAbsolutePath()+"/regions.yml");//ищем файл regions.yml
YamlConfiguration data = new YamlConfiguration();
for(Map.Entry<String, RegionData> entry : regions.entrySet())
{
data.set(entry.getKey()+".world", entry.getValue().getStartLocation().getWorld().getName());
data.set(entry.getKey() + ".start", entry.getValue().getStartLocation().toVector());
data.set(entry.getKey() + ".end", entry.getValue().getEndLocation().toVector());
}
try
{
data.save(f);
}
catch (IOException e)
{
e.printStackTrace();
}
}
}

