use of mc.dragons.core.gameobject.floor.Floor in project DragonsOnline by UniverseCraft.
the class FloorCommand method listFloors.
private void listFloors(CommandSender sender) {
sender.sendMessage(ChatColor.GREEN + "Listing all floors:");
for (GameObject gameObject : registry.getRegisteredObjects(GameObjectType.FLOOR)) {
Floor floor = (Floor) gameObject;
sender.spigot().sendMessage(StringUtil.clickableHoverableText(ChatColor.GRAY + "- " + floor.getFloorName() + " [" + floor.getFloorStatus() + "] [Lv " + floor.getLevelMin() + "]" + (floor.getStorageAccess() instanceof LocalStorageAccess ? LOCAL_FLOOR_WARNING : ""), "/floor goto " + floor.getFloorName(), "Click to go to floor " + floor.getFloorName()));
}
}
use of mc.dragons.core.gameobject.floor.Floor in project DragonsOnline by UniverseCraft.
the class DragonsDev method backupFloors.
public void backupFloors() {
getLogger().info("Backing up all floors...");
String backupRoot = BACKUP_FOLDER + dragons.getServerName() + " " + StringUtil.dateFormatNow().replaceAll(Pattern.quote(":"), ".") + "\\";
for (World world : Bukkit.getWorlds()) {
Floor floor = FloorLoader.fromWorld(world);
if (floor == null)
continue;
File backupFolder = new File(backupRoot + floor.getWorldName());
backupFolder.mkdirs();
File sourceFolder = world.getWorldFolder();
FileUtil.copyFolder(sourceFolder, backupFolder);
}
File folder = new File(BACKUP_FOLDER);
if (!folder.exists()) {
getLogger().warning("Configured backup folder (" + BACKUP_FOLDER + ") does not exist! Cannot inspect past backups to enforce retention policy.");
}
if (!folder.isDirectory()) {
getLogger().warning("Configured backup folder (" + BACKUP_FOLDER + ") is not a directory! Cannot inspect past backups to enforce retention policy.");
}
List<Path> purge = new ArrayList<>();
if (BACKUP_RETENTION_DAYS != -1) {
long now = System.currentTimeMillis();
try {
Files.walk(folder.toPath(), 1, FileVisitOption.FOLLOW_LINKS).forEach(backup -> {
int age = 0;
try {
age = (int) Math.floor((double) (now - Files.getLastModifiedTime(backup).toMillis()) / (1000 * 60 * 60 * 24));
} catch (IOException e) {
e.printStackTrace();
}
if (age > BACKUP_RETENTION_DAYS) {
purge.add(backup);
}
});
} catch (IOException e) {
e.printStackTrace();
}
for (Path path : purge) {
FileUtil.deleteFolder(path.toFile());
}
}
Bukkit.broadcastMessage(ChatColor.GOLD + "[Dev Server] Automated backup completed successfully.");
getLogger().info(purge.size() + " old backups were purged.");
}
use of mc.dragons.core.gameobject.floor.Floor in project DragonsOnline by UniverseCraft.
the class SystemProfileLoader method loadProfile.
public SystemProfile loadProfile(String profileName) {
LOGGER.trace("Loading profile " + profileName);
for (SystemProfile systemProfile : profileCache) {
if (systemProfile.getProfileName().equalsIgnoreCase(profileName)) {
return systemProfile;
}
}
LOGGER.verbose("-Profile was not found in cache, fetching from database");
Document profile = collection.find(new Document("profileName", profileName)).first();
if (profile == null) {
return null;
}
Document flags = profile.get("flags", Document.class);
@SuppressWarnings("unchecked") Map<String, String> hashesRaw = (Map<String, String>) profile.get("profilePasswordHashes");
Map<UUID, String> hashes = new HashMap<>();
hashesRaw.forEach((k, v) -> hashes.put(UUID.fromString(k), v));
List<Floor> adminFloors = profile.getList("adminFloors", String.class).stream().map(name -> FloorLoader.fromFloorName(name)).collect(Collectors.toList());
SystemProfile systemProfile = new SystemProfile(null, profileName, hashes, PermissionLevel.valueOf(profile.getString("maxPermissionLevel")), new SystemProfileFlags(flags), adminFloors, profile.getBoolean("active").booleanValue());
profileCache.add(systemProfile);
return systemProfile;
}
use of mc.dragons.core.gameobject.floor.Floor in project DragonsOnline by UniverseCraft.
the class User method autoSave.
@Override
public void autoSave() {
super.autoSave();
if (player == null) {
return;
}
sendActionBar(ChatColor.GREEN + "Autosaving...");
Document autoSaveData = new Document("lastSeen", System.currentTimeMillis()).append("maxHealth", player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()).append("health", player.getHealth()).append("gamemode", joined ? player.getGameMode().toString() : getSavedGameMode().toString()).append("inventory", getInventoryAsDocument());
if (joined) {
String key = PermissionUtil.verifyActivePermissionLevel(this, PermissionLevel.TESTER, false) ? "lastStaffLocation" : "lastLocation";
Floor floor = FloorLoader.fromLocation(player.getLocation());
if (!floor.isVolatile()) {
autoSaveData.append(key, StorageUtil.locToDoc(player.getLocation()));
}
}
for (ItemStack itemStack : player.getInventory().getContents()) {
if (itemStack != null) {
Item item = ItemLoader.fromBukkit(itemStack);
if (item != null) {
item.autoSave();
}
}
}
userHookRegistry.getHooks().forEach(h -> h.onAutoSave(this, autoSaveData));
update(autoSaveData);
}
use of mc.dragons.core.gameobject.floor.Floor in project DragonsOnline by UniverseCraft.
the class DragonsResidences method resetResWorld.
private void resetResWorld() {
getLogger().info("Resetting residential world...");
resetResWorld_recursiveStep(new File("res_temp"));
WorldCreator creator = WorldCreator.name("res_temp");
creator.type(WorldType.FLAT);
Bukkit.createWorld(creator);
StorageManager lsm = dragons.getLocalStorageManager();
StorageAccess lsa = lsm.getNewStorageAccess(GameObjectType.FLOOR, new Document("worldName", "res_temp").append("floorName", "RES").append("displayName", "Residence").append("levelMin", 0).append("volatile", true).append("status", FloorStatus.LIVE.toString()));
Floor resFloor = new Floor(lsm, lsa, true);
FloorLoader.link(Bukkit.getWorld("res_temp"), resFloor);
dragons.getGameObjectRegistry().getRegisteredObjects().add(resFloor);
}
Aggregations