public class SetCordArena implements Listener {
public static HashMap<String, Location> loc_arena = new HashMap<String, Location>();
@EventHandler
public void SetCord(PlayerInteractEvent event) {
Block block= event.getClickedBlock();
Player p = event.getPlayer();
ItemStack item = p.getItemInHand();
if(item.getType() == ColorControlItem.ItemArena().getType()) {
boolean RIGHT = event.getAction().equals(Action.RIGHT_CLICK_BLOCK);
boolean LEFT = event.getAction().equals(Action.LEFT_CLICK_BLOCK);
if (LEFT == true) {
event.setCancelled(true);
block.setType(Material.BEDROCK);
int x = block.getX();
int y = block.getY();
int z = block.getZ();
loc_arena.put("LEFT",new Location(p.getWorld(), x, y, z));
p.sendMessage("Кордината первая установлена ");
saveHashMap();
}
if (RIGHT == true) {
block.setType(Material.BEDROCK);
int x = block.getX();
int y = block.getY();
int z = block.getZ();
loc_arena.put("RIGHT",new Location(p.getWorld(), x, y, z));
p.sendMessage("Кордината вторая установлена ");
saveHashMap();
}
}
}
public static void saveHashMap(){
try {
YamlConfiguration cfg = new YamlConfiguration();
for (String key : loc_arena.keySet()){
cfg.set(key, loc_arena.get(key));
}
File f = new File ("plugins/ColorControl","hashmap.yml");
if (f.exists()) f.delete();
cfg.save(f);
} catch (Exception e){
e.printStackTrace();
}
}
public static void loadHashMap(){
try {
YamlConfiguration cfg = new YamlConfiguration();
File f = new File ("plugins/ColorControl","hashmap.yml");
loc_arena.clear();
if (f.exists()) {
cfg.load(f);
Set<String> keys = cfg.getKeys(false);
if (keys.size()>0)
for (String key : keys)
loc_arena.put(key, (Location) cfg.get(key));
}
} catch (Exception e){
e.printStackTrace();
}
}