Search in sources :

Example 1 with Modules

use of com.loohp.interactionvisualizer.api.InteractionVisualizerAPI.Modules in project InteractionVisualizer by LOOHP.

the class Database method getPlayerInfo.

public static Map<Modules, BitSet> getPlayerInfo(UUID uuid) {
    Map<Modules, BitSet> map = new HashMap<>();
    synchronized (syncdb) {
        open();
        try {
            PreparedStatement statement = getConnection().prepareStatement("SELECT * FROM " + preferenceTable + " WHERE UUID=?");
            statement.setString(1, uuid.toString());
            ResultSet results = statement.executeQuery();
            results.next();
            String itemstand = results.getString("ITEMSTAND");
            String itemdrop = results.getString("ITEMDROP");
            String hologram = results.getString("HOLOGRAM");
            try {
                if (VALID_BITSET.matcher(itemstand).matches()) {
                    map.put(Modules.ITEMSTAND, BitSetUtils.fromNumberString(itemstand));
                } else {
                    map.put(Modules.ITEMSTAND, BitSet.valueOf(ArrayUtils.fromBase64String(itemstand)));
                }
                if (VALID_BITSET.matcher(itemdrop).matches()) {
                    map.put(Modules.ITEMDROP, BitSetUtils.fromNumberString(itemdrop));
                } else {
                    map.put(Modules.ITEMDROP, BitSet.valueOf(ArrayUtils.fromBase64String(itemdrop)));
                }
                if (VALID_BITSET.matcher(hologram).matches()) {
                    map.put(Modules.HOLOGRAM, BitSetUtils.fromNumberString(hologram));
                } else {
                    map.put(Modules.HOLOGRAM, BitSet.valueOf(ArrayUtils.fromBase64String(hologram)));
                }
            } catch (Throwable e) {
                new RuntimeException("Unable to load player preference (" + uuid + ")", e).printStackTrace();
                map.put(Modules.ITEMSTAND, new BitSet());
                map.put(Modules.ITEMDROP, new BitSet());
                map.put(Modules.HOLOGRAM, new BitSet());
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        try {
            connection.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    return map;
}
Also used : HashMap(java.util.HashMap) SQLException(java.sql.SQLException) Modules(com.loohp.interactionvisualizer.api.InteractionVisualizerAPI.Modules) BitSet(java.util.BitSet) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 2 with Modules

use of com.loohp.interactionvisualizer.api.InteractionVisualizerAPI.Modules in project InteractionVisualizer by LOOHP.

the class PreferenceManager method hasAnyPreferenceEnabled.

public boolean hasAnyPreferenceEnabled(UUID uuid, EntryKey entry) {
    int i = entries.indexOf(entry);
    if (i < 0) {
        return false;
    }
    Map<Modules, BitSet> info = preferences.get(uuid);
    if (info != null) {
        for (BitSet bitset : info.values()) {
            if (!bitset.get(i)) {
                return true;
            }
        }
    }
    return false;
}
Also used : Modules(com.loohp.interactionvisualizer.api.InteractionVisualizerAPI.Modules) BitSet(java.util.BitSet)

Example 3 with Modules

use of com.loohp.interactionvisualizer.api.InteractionVisualizerAPI.Modules in project InteractionVisualizer by LOOHP.

the class PreferenceManager method hasAnyPreferenceDisabled.

public boolean hasAnyPreferenceDisabled(UUID uuid, EntryKey entry) {
    int i = entries.indexOf(entry);
    if (i < 0) {
        return false;
    }
    Map<Modules, BitSet> info = preferences.get(uuid);
    if (info != null) {
        for (BitSet bitset : info.values()) {
            if (bitset.get(i)) {
                return true;
            }
        }
    }
    return false;
}
Also used : Modules(com.loohp.interactionvisualizer.api.InteractionVisualizerAPI.Modules) BitSet(java.util.BitSet)

Example 4 with Modules

use of com.loohp.interactionvisualizer.api.InteractionVisualizerAPI.Modules in project InteractionVisualizer by LOOHP.

the class PreferenceManager method getPlayerPreferences.

public Map<Modules, Map<EntryKey, Boolean>> getPlayerPreferences(UUID uuid) {
    Map<Modules, Map<EntryKey, Boolean>> preferences = new HashMap<>();
    for (Modules module : Modules.values()) {
        Map<EntryKey, Boolean> entryPreference = new HashMap<>();
        for (EntryKey entry : getRegisteredEntries()) {
            entryPreference.put(entry, getPlayerPreference(uuid, module, entry));
        }
        preferences.put(module, entryPreference);
    }
    return preferences;
}
Also used : EntryKey(com.loohp.interactionvisualizer.objectholders.EntryKey) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Modules(com.loohp.interactionvisualizer.api.InteractionVisualizerAPI.Modules) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 5 with Modules

use of com.loohp.interactionvisualizer.api.InteractionVisualizerAPI.Modules in project InteractionVisualizer by LOOHP.

the class PreferenceManager method setPlayerPreference.

public void setPlayerPreference(UUID uuid, Modules module, EntryKey entry, boolean enabled, boolean update) {
    int i = entries.indexOf(entry);
    if (i < 0) {
        return;
    }
    Map<Modules, BitSet> info = preferences.get(uuid);
    if (info != null) {
        BitSet bitset = info.get(module);
        bitset.set(i, !enabled);
    }
    if (update) {
        Player player = Bukkit.getPlayer(uuid);
        if (player != null) {
            updatePlayer(player, true);
        }
    }
}
Also used : Player(org.bukkit.entity.Player) Modules(com.loohp.interactionvisualizer.api.InteractionVisualizerAPI.Modules) BitSet(java.util.BitSet)

Aggregations

Modules (com.loohp.interactionvisualizer.api.InteractionVisualizerAPI.Modules)8 BitSet (java.util.BitSet)6 EntryKey (com.loohp.interactionvisualizer.objectholders.EntryKey)2 HashMap (java.util.HashMap)2 Player (org.bukkit.entity.Player)2 UpdaterResponse (com.loohp.interactionvisualizer.updater.Updater.UpdaterResponse)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Component (net.kyori.adventure.text.Component)1