Search in sources :

Example 6 with Floor

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()));
    }
}
Also used : LocalStorageAccess(mc.dragons.core.storage.local.LocalStorageAccess) Floor(mc.dragons.core.gameobject.floor.Floor) GameObject(mc.dragons.core.gameobject.GameObject)

Example 7 with Floor

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.");
}
Also used : Path(java.nio.file.Path) Floor(mc.dragons.core.gameobject.floor.Floor) ArrayList(java.util.ArrayList) IOException(java.io.IOException) World(org.bukkit.World) File(java.io.File)

Example 8 with Floor

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;
}
Also used : Document(org.bson.Document) DragonsLogger(mc.dragons.core.logging.DragonsLogger) AbstractLightweightLoader(mc.dragons.core.storage.loader.AbstractLightweightLoader) UserLoader(mc.dragons.core.gameobject.user.UserLoader) MessageDigest(java.security.MessageDigest) FloorLoader(mc.dragons.core.gameobject.floor.FloorLoader) Set(java.util.Set) User(mc.dragons.core.gameobject.user.User) HashMap(java.util.HashMap) Rank(mc.dragons.core.gameobject.user.Rank) UUID(java.util.UUID) Player(org.bukkit.entity.Player) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Dragons(mc.dragons.core.Dragons) SystemProfileFlags(mc.dragons.core.gameobject.user.permission.SystemProfile.SystemProfileFlags) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Floor(mc.dragons.core.gameobject.floor.Floor) List(java.util.List) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Map(java.util.Map) BigInteger(java.math.BigInteger) Bukkit(org.bukkit.Bukkit) SystemProfileFlags(mc.dragons.core.gameobject.user.permission.SystemProfile.SystemProfileFlags) Floor(mc.dragons.core.gameobject.floor.Floor) HashMap(java.util.HashMap) Document(org.bson.Document) UUID(java.util.UUID) HashMap(java.util.HashMap) Map(java.util.Map)

Example 9 with Floor

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);
}
Also used : Floor(mc.dragons.core.gameobject.floor.Floor) Item(mc.dragons.core.gameobject.item.Item) Document(org.bson.Document) ItemStack(org.bukkit.inventory.ItemStack)

Example 10 with Floor

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);
}
Also used : Floor(mc.dragons.core.gameobject.floor.Floor) WorldCreator(org.bukkit.WorldCreator) StorageManager(mc.dragons.core.storage.StorageManager) Document(org.bson.Document) File(java.io.File) StorageAccess(mc.dragons.core.storage.StorageAccess)

Aggregations

Floor (mc.dragons.core.gameobject.floor.Floor)20 User (mc.dragons.core.gameobject.user.User)4 Document (org.bson.Document)4 GameObject (mc.dragons.core.gameobject.GameObject)3 Player (org.bukkit.entity.Player)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 UUID (java.util.UUID)2 Dragons (mc.dragons.core.Dragons)2 FloorStatus (mc.dragons.core.gameobject.floor.Floor.FloorStatus)2 FloorLoader (mc.dragons.core.gameobject.floor.FloorLoader)2 Region (mc.dragons.core.gameobject.region.Region)2 Bukkit (org.bukkit.Bukkit)2 EventHandler (org.bukkit.event.EventHandler)2 IOException (java.io.IOException)1 BigInteger (java.math.BigInteger)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Path (java.nio.file.Path)1