Search in sources :

Example 1 with LibraryHook

use of me.staartvin.plugins.pluginlibrary.hooks.LibraryHook in project Statz by Staartvin.

the class ImportManager method importFromStats3.

/**
 * Import data from Stats 3.
 *
 * @return number of entries imported from Stats 3.
 */
@SuppressWarnings("deprecation")
public int importFromStats3() {
    int importedEntries = 0;
    LibraryHook hook = plugin.getDependencyManager().getLibraryHook(Library.STATS);
    if (hook == null || !hook.isAvailable()) {
        plugin.getLogger().warning("Cannot import data from Stats 3 as it is not running!");
        return -1;
    }
    int waitingTime = 10;
    StatsHook stats3 = (StatsHook) hook;
    List<UUID> loggedPlayers = stats3.getLoggedPlayers();
    plugin.getLogsManager().writeToLogFile("Requested " + loggedPlayers.size() + " users from Stats. Now waiting " + "" + ((loggedPlayers.size() * waitingTime) / 1000.0) + " seconds for the response...");
    plugin.getLogger().info("Requested all users for importing, now wait " + ((loggedPlayers.size() * waitingTime) / 1000.0) + " seconds for Stats to load all users.");
    try {
        Thread.sleep(loggedPlayers.size() * waitingTime);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    plugin.getLogsManager().writeToLogFile("Started processing UUIDs of Stats.");
    for (UUID uuid : loggedPlayers) {
        StatsHolder user = stats3.getStatsHolder(uuid);
        importedEntries++;
        if (importedEntries % 1000 == 0) {
            plugin.getLogsManager().writeToLogFile("Processed " + importedEntries + " / " + loggedPlayers.size() + " uuids.");
        }
        Collection<Stat> storedStats = user.getStats();
        for (Stat stat : storedStats) {
            for (StatEntry entry : user.getStats(stat)) {
                Map<String, Object> metadata = entry.getMetadata();
                double value = entry.getValue();
                String worldName = (String) metadata.get("world");
                if (stat instanceof Move) {
                    // Movement stat
                    double moveType = Double.parseDouble(metadata.get("type").toString());
                    String movementType = "WALK";
                    switch((int) moveType) {
                        case 0:
                            movementType = "WALK";
                            break;
                        case 1:
                            movementType = "BOAT";
                            break;
                        case 2:
                            movementType = "MINECART";
                            break;
                        case 3:
                            movementType = "PIG";
                            break;
                        case 4:
                            movementType = "PIG IN MINECART";
                            break;
                        case 5:
                            movementType = "HORSE";
                            break;
                        case 6:
                            movementType = "FLY";
                            break;
                    }
                    plugin.getDataManager().setPlayerInfo(uuid, PlayerStat.DISTANCE_TRAVELLED, StatzUtil.makeQuery("value", (value), "moveType", movementType, "world", worldName));
                } else if (stat instanceof Kill) {
                    // Kill stat
                    EntityType entity = EntityType.fromName((String) metadata.get("entityType"));
                    String entityName = entity != null ? entity.toString() : "UNKNOWN";
                    plugin.getDataManager().setPlayerInfo(uuid, PlayerStat.KILLS_MOBS, StatzUtil.makeQuery("value", (value), "mob", entityName, "world", worldName, "weapon", "UNKNOWN"));
                } else if (stat instanceof Teleports) {
                    // Teleport stat
                    plugin.getDataManager().setPlayerInfo(uuid, PlayerStat.TELEPORTS, StatzUtil.makeQuery("value", (value), "world", "UNKNOWN", "destWorld", worldName, "cause", "UNKNOWN"));
                } else if (stat instanceof Arrows) {
                    // Arrows shot stat
                    plugin.getDataManager().setPlayerInfo(uuid, PlayerStat.ARROWS_SHOT, StatzUtil.makeQuery("value", (value), "world", worldName, "forceShot", 1));
                } else if (stat instanceof BedEnter) {
                    // Beds entered stat
                    plugin.getDataManager().setPlayerInfo(uuid, PlayerStat.ENTERED_BEDS, StatzUtil.makeQuery("value", (value), "world", worldName));
                } else if (stat instanceof BlockBreak) {
                    // Blocks broken stat
                    int dataValue = Integer.parseInt(metadata.get("data").toString());
                    String blockName = (String) metadata.get("name");
                    Material material = Material.getMaterial(blockName);
                    plugin.getDataManager().setPlayerInfo(uuid, PlayerStat.BLOCKS_BROKEN, StatzUtil.makeQuery("value", (value), "world", worldName, "datavalue", dataValue, "typeid", material.getId()));
                } else if (stat instanceof BlockPlace) {
                    // Blocks placed stat
                    int dataValue = Integer.parseInt(metadata.get("data").toString());
                    String blockName = (String) metadata.get("name");
                    Material material = Material.getMaterial(blockName);
                    plugin.getDataManager().setPlayerInfo(uuid, PlayerStat.BLOCKS_PLACED, StatzUtil.makeQuery("value", (value), "world", worldName, "datavalue", dataValue, "typeid", material.getId()));
                } else if (stat instanceof BucketEmpty) {
                    // Buckets emptied stat
                    plugin.getDataManager().setPlayerInfo(uuid, PlayerStat.BUCKETS_EMPTIED, StatzUtil.makeQuery("value", (value), "world", worldName));
                } else if (stat instanceof BucketFill) {
                    // Buckets filled stat
                    plugin.getDataManager().setPlayerInfo(uuid, PlayerStat.BUCKETS_FILLED, StatzUtil.makeQuery("value", (value), "world", worldName));
                } else if (stat instanceof CommandsDone) {
                    // Commands performed stat
                    plugin.getDataManager().setPlayerInfo(uuid, PlayerStat.COMMANDS_PERFORMED, StatzUtil.makeQuery("value", (value), "world", worldName, "command", "UNKNOWN", "arguments", "UNKNOWN"));
                } else if (stat instanceof DamageTaken) {
                    // Damage taken stat
                    String cause = metadata == null ? "UNKNOWN" : (metadata.get("cause") != null ? metadata.get("cause").toString() : "UNKNOWN");
                    plugin.getDataManager().setPlayerInfo(uuid, PlayerStat.DAMAGE_TAKEN, StatzUtil.makeQuery("value", (value), "world", worldName, "cause", cause));
                } else if (stat instanceof Death) {
                    // Times died stat
                    plugin.getDataManager().setPlayerInfo(uuid, PlayerStat.DEATHS, StatzUtil.makeQuery("value", (value), "world", worldName));
                } else if (stat instanceof EggsThrown) {
                    // Eggs thrown stat
                    plugin.getDataManager().setPlayerInfo(uuid, PlayerStat.EGGS_THROWN, StatzUtil.makeQuery("value", (value), "world", worldName));
                } else if (stat instanceof FishCaught) {
                    // Fish caught stat
                    plugin.getDataManager().setPlayerInfo(uuid, PlayerStat.ITEMS_CAUGHT, StatzUtil.makeQuery("value", (value), "world", worldName, "caught", "UNKNOWN"));
                } else if (stat instanceof ItemsCrafted) {
                    // Items crafted stat
                    String name = metadata == null ? "UNKNOWN" : (metadata.get("name") != null ? metadata.get("name").toString() : "UNKNOWN");
                    plugin.getDataManager().setPlayerInfo(uuid, PlayerStat.ITEMS_CRAFTED, StatzUtil.makeQuery("value", (value), "world", worldName, "item", name));
                } else if (stat instanceof ItemsDropped) {
                    // Items dropped stat
                    String name = metadata == null ? "UNKNOWN" : (metadata.get("name") != null ? metadata.get("name").toString() : "UNKNOWN");
                    plugin.getDataManager().setPlayerInfo(uuid, PlayerStat.ITEMS_DROPPED, StatzUtil.makeQuery("value", (value), "world", worldName, "item", name));
                } else if (stat instanceof ItemsPickedUp) {
                    // Items picked up stat
                    String name = metadata == null ? "UNKNOWN" : (metadata.get("name") != null ? metadata.get("name").toString() : "UNKNOWN");
                    plugin.getDataManager().setPlayerInfo(uuid, PlayerStat.ITEMS_PICKED_UP, StatzUtil.makeQuery("value", (value), "world", worldName, "item", name));
                } else if (stat instanceof ItemsDropped) {
                    // Items dropped stat
                    String name = metadata == null ? "UNKNOWN" : (metadata.get("name") != null ? metadata.get("name").toString() : "UNKNOWN");
                    plugin.getDataManager().setPlayerInfo(uuid, PlayerStat.ITEMS_DROPPED, StatzUtil.makeQuery("value", (value), "world", worldName, "item", name));
                } else if (stat instanceof Joins) {
                    // Times joined stat
                    plugin.getDataManager().setPlayerInfo(uuid, PlayerStat.JOINS, StatzUtil.makeQuery("value", (value)));
                } else if (stat instanceof Omnomnom) {
                    // Food eaten stat
                    plugin.getDataManager().setPlayerInfo(uuid, PlayerStat.FOOD_EATEN, StatzUtil.makeQuery("value", (value), "world", worldName, "foodEaten", "UNKNOWN"));
                } else if (stat instanceof Playtime) {
                    // Time played stat
                    plugin.getDataManager().setPlayerInfo(uuid, PlayerStat.TIME_PLAYED, StatzUtil.makeQuery("value", (value / 60d), "world", worldName));
                } else if (stat instanceof PVP) {
                    // Number of players killed stat
                    String victim = metadata == null ? "UNKNOWN" : (metadata.get("victim") != null ? metadata.get("victim").toString() : "UNKNOWN");
                    plugin.getDataManager().setPlayerInfo(uuid, PlayerStat.KILLS_PLAYERS, StatzUtil.makeQuery("value", (value), "world", worldName, "playerKilled", victim));
                } else if (stat instanceof Shears) {
                    // Number of sheep shorn stat
                    plugin.getDataManager().setPlayerInfo(uuid, PlayerStat.TIMES_SHORN, StatzUtil.makeQuery("value", (value), "world", worldName));
                } else if (stat instanceof WorldChanged) {
                    // Times changed of worlds stat
                    plugin.getDataManager().setPlayerInfo(uuid, PlayerStat.WORLDS_CHANGED, StatzUtil.makeQuery("value", (value), "world", "UNKNOWN", "destWorld", "UNKNOWN"));
                } else if (stat instanceof TimesKicked) {
                    // Times kicked stat
                    plugin.getDataManager().setPlayerInfo(uuid, PlayerStat.TIMES_KICKED, StatzUtil.makeQuery("value", (value), "world", worldName, "reason", "UNKNOWN"));
                } else if (stat instanceof ToolsBroken) {
                    // Tools broken stat
                    String name = metadata == null ? "UNKNOWN" : (metadata.get("name") != null ? metadata.get("name").toString() : "UNKNOWN");
                    plugin.getDataManager().setPlayerInfo(uuid, PlayerStat.TOOLS_BROKEN, StatzUtil.makeQuery("value", (value), "world", worldName, "item", name));
                } else if (stat instanceof Trades) {
                    // Number of trades made stat
                    plugin.getDataManager().setPlayerInfo(uuid, PlayerStat.VILLAGER_TRADES, StatzUtil.makeQuery("value", (value), "world", worldName, "trade", "UNKNOWN"));
                } else if (stat instanceof XpGained) {
                    // XP gained stat
                    plugin.getDataManager().setPlayerInfo(uuid, PlayerStat.XP_GAINED, StatzUtil.makeQuery("value", (value), "world", worldName));
                }
            }
        }
    }
    return importedEntries;
}
Also used : LibraryHook(me.staartvin.plugins.pluginlibrary.hooks.LibraryHook) PlayerStat(me.staartvin.statz.datamanager.player.PlayerStat) Stat(nl.lolmewn.stats.api.stat.Stat) UUID(java.util.UUID) StatsHook(me.staartvin.plugins.pluginlibrary.hooks.StatsHook) Material(org.bukkit.Material) StatsHolder(nl.lolmewn.stats.api.user.StatsHolder) EntityType(org.bukkit.entity.EntityType) StatEntry(nl.lolmewn.stats.api.stat.StatEntry)

Example 2 with LibraryHook

use of me.staartvin.plugins.pluginlibrary.hooks.LibraryHook in project Statz by Staartvin.

the class DisableManager method isStatDisabledLocation.

/**
 * Is a stat disabled in a certain location?
 *
 * @param loc  Location to check
 * @param stat Stat to check
 * @return true if it is disabled on this location, false otherwise.
 */
public boolean isStatDisabledLocation(Location loc, PlayerStat stat) {
    // We cannot check if PluginLibrary is not available.
    if (!plugin.getDependencyManager().isAvailable(StatzDependency.PLUGINLIBRARY)) {
        return false;
    }
    LibraryHook worldGuardHook = plugin.getDependencyManager().getLibraryHook(Library.WORLDGUARD);
    // Only check for WG regions if WorldGuard is installed
    if (worldGuardHook != null && worldGuardHook.isAvailable()) {
        List<String> disabledRegions = this.getDisabledWorldGuardRegions(stat);
        WorldGuardHook wgHook = (WorldGuardHook) plugin.getDependencyManager().getLibraryHook(Library.WORLDGUARD);
        // Check for all disabled regions if a player is in them.
        if (!disabledRegions.isEmpty()) {
            for (String regionName : disabledRegions) {
                if (wgHook.isInRegion(loc, regionName)) {
                    return true;
                }
            }
        }
    }
    LibraryHook griefPreventionHook = plugin.getDependencyManager().getLibraryHook(Library.GRIEFPREVENTION);
    // Check GriefPrevention claims
    if (griefPreventionHook != null && griefPreventionHook.isAvailable()) {
        List<String> disabledUUIDs = this.getDisabledGriefPreventionClaims(stat);
        GriefPreventionHook gpHook = (GriefPreventionHook) plugin.getDependencyManager().getLibraryHook(Library.GRIEFPREVENTION);
        // Check for all disabled uuid claims if a player is in them.
        if (!disabledUUIDs.isEmpty()) {
            for (String disabledClaim : disabledUUIDs) {
                if (gpHook.isInRegion(loc, UUID.fromString(disabledClaim))) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : LibraryHook(me.staartvin.plugins.pluginlibrary.hooks.LibraryHook) WorldGuardHook(me.staartvin.plugins.pluginlibrary.hooks.WorldGuardHook) GriefPreventionHook(me.staartvin.plugins.pluginlibrary.hooks.GriefPreventionHook)

Example 3 with LibraryHook

use of me.staartvin.plugins.pluginlibrary.hooks.LibraryHook in project Statz by Staartvin.

the class DependencyManager method isAvailable.

/**
 * Check whether a plugin is available using PluginLibrary.
 * @param library Library to check
 * @return true if it is available, false otherwise.
 */
public boolean isAvailable(Library library) {
    if (!this.isAvailable(StatzDependency.PLUGINLIBRARY))
        return false;
    if (library == null)
        return false;
    PluginLibraryHandler handler = (PluginLibraryHandler) getDependency(StatzDependency.PLUGINLIBRARY);
    if (handler == null) {
        return false;
    }
    LibraryHook hook = handler.getLibraryHook(library);
    if (hook == null) {
        return false;
    }
    return hook.isAvailable();
}
Also used : PluginLibraryHandler(me.staartvin.statz.hooks.handlers.PluginLibraryHandler) LibraryHook(me.staartvin.plugins.pluginlibrary.hooks.LibraryHook)

Aggregations

LibraryHook (me.staartvin.plugins.pluginlibrary.hooks.LibraryHook)3 UUID (java.util.UUID)1 GriefPreventionHook (me.staartvin.plugins.pluginlibrary.hooks.GriefPreventionHook)1 StatsHook (me.staartvin.plugins.pluginlibrary.hooks.StatsHook)1 WorldGuardHook (me.staartvin.plugins.pluginlibrary.hooks.WorldGuardHook)1 PlayerStat (me.staartvin.statz.datamanager.player.PlayerStat)1 PluginLibraryHandler (me.staartvin.statz.hooks.handlers.PluginLibraryHandler)1 Stat (nl.lolmewn.stats.api.stat.Stat)1 StatEntry (nl.lolmewn.stats.api.stat.StatEntry)1 StatsHolder (nl.lolmewn.stats.api.user.StatsHolder)1 Material (org.bukkit.Material)1 EntityType (org.bukkit.entity.EntityType)1