mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-28 03:34:42 +02:00
Initial annotation usage cleanup + EditorConfig
This commit is contained in:
@ -29,8 +29,8 @@ import com.earth2me.essentials.Essentials;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.plotsquared.core.uuid.UUIDMapping;
|
||||
import com.plotsquared.core.uuid.UUIDService;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@ -47,11 +47,13 @@ public class EssentialsUUIDService implements UUIDService {
|
||||
this.essentials = Essentials.getPlugin(Essentials.class);
|
||||
}
|
||||
|
||||
@Override @Nonnull public List<UUIDMapping> getNames(@Nonnull final List<UUID> uuids) {
|
||||
@Override
|
||||
public @NonNull List<UUIDMapping> getNames(final @NonNull List<UUID> uuids) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override @Nonnull public List<UUIDMapping> getUUIDs(@Nonnull final List<String> usernames) {
|
||||
@Override
|
||||
public @NonNull List<UUIDMapping> getUUIDs(final @NonNull List<String> usernames) {
|
||||
final List<UUIDMapping> mappings = new ArrayList<>(usernames.size());
|
||||
for (final String username : usernames) {
|
||||
try {
|
||||
@ -62,7 +64,8 @@ public class EssentialsUUIDService implements UUIDService {
|
||||
mappings.add(new UUIDMapping(uuid, username));
|
||||
}
|
||||
}
|
||||
} catch (final Exception ignored){}
|
||||
} catch (final Exception ignored) {
|
||||
}
|
||||
}
|
||||
return mappings;
|
||||
}
|
||||
|
@ -31,8 +31,8 @@ import net.luckperms.api.LuckPerms;
|
||||
import net.luckperms.api.model.user.UserManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
@ -53,21 +53,24 @@ public class LuckPermsUUIDService implements UUIDService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override @Nonnull public List<UUIDMapping> getNames(@Nonnull final List<UUID> uuids) {
|
||||
final List<UUIDMapping> mappings = new ArrayList<>(uuids.size());
|
||||
final UserManager userManager = this.luckPerms.getUserManager();
|
||||
for (final UUID uuid : uuids) {
|
||||
try {
|
||||
final String username = userManager.lookupUsername(uuid).get();
|
||||
if (username != null) {
|
||||
mappings.add(new UUIDMapping(uuid, username));
|
||||
}
|
||||
} catch (final Exception ignored) {}
|
||||
}
|
||||
return mappings;
|
||||
@Override
|
||||
public @NonNull List<UUIDMapping> getNames(final @NonNull List<UUID> uuids) {
|
||||
final List<UUIDMapping> mappings = new ArrayList<>(uuids.size());
|
||||
final UserManager userManager = this.luckPerms.getUserManager();
|
||||
for (final UUID uuid : uuids) {
|
||||
try {
|
||||
final String username = userManager.lookupUsername(uuid).get();
|
||||
if (username != null) {
|
||||
mappings.add(new UUIDMapping(uuid, username));
|
||||
}
|
||||
} catch (final Exception ignored) {
|
||||
}
|
||||
}
|
||||
return mappings;
|
||||
}
|
||||
|
||||
@Override @Nonnull public List<UUIDMapping> getUUIDs(@Nonnull final List<String> usernames) {
|
||||
@Override
|
||||
public @NonNull List<UUIDMapping> getUUIDs(final @NonNull List<String> usernames) {
|
||||
final List<UUIDMapping> mappings = new ArrayList<>(usernames.size());
|
||||
final UserManager userManager = this.luckPerms.getUserManager();
|
||||
for (final String username : usernames) {
|
||||
@ -76,7 +79,8 @@ public class LuckPermsUUIDService implements UUIDService {
|
||||
if (username != null) {
|
||||
mappings.add(new UUIDMapping(uuid, username));
|
||||
}
|
||||
} catch (final Exception ignored) {}
|
||||
} catch (final Exception ignored) {
|
||||
}
|
||||
}
|
||||
return mappings;
|
||||
}
|
||||
|
@ -31,8 +31,8 @@ import com.plotsquared.core.uuid.UUIDMapping;
|
||||
import com.plotsquared.core.uuid.UUIDService;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@ -43,7 +43,8 @@ import java.util.UUID;
|
||||
*/
|
||||
public class OfflinePlayerUUIDService implements UUIDService {
|
||||
|
||||
@Override @Nonnull public List<UUIDMapping> getNames(@Nonnull final List<UUID> uuids) {
|
||||
@Override
|
||||
public @NonNull List<UUIDMapping> getNames(final @NonNull List<UUID> uuids) {
|
||||
if (Settings.UUID.FORCE_LOWERCASE || Bukkit.getWorlds().isEmpty()) {
|
||||
return Collections.emptyList(); // This is useless now
|
||||
}
|
||||
@ -54,14 +55,16 @@ public class OfflinePlayerUUIDService implements UUIDService {
|
||||
if (offlinePlayer.hasPlayedBefore()) {
|
||||
wrappers.add(new UUIDMapping(uuid, offlinePlayer.getName()));
|
||||
}
|
||||
} catch (final Exception ignored) {} /* This can be safely ignored. If this happens, it is
|
||||
} catch (final Exception ignored) {
|
||||
} /* This can be safely ignored. If this happens, it is
|
||||
probably because it's called before the worlds have
|
||||
been loaded. This is bad, but does not break anything */
|
||||
}
|
||||
return wrappers;
|
||||
}
|
||||
|
||||
@Override @Nonnull public List<UUIDMapping> getUUIDs(@Nonnull final List<String> usernames) {
|
||||
@Override
|
||||
public @NonNull List<UUIDMapping> getUUIDs(final @NonNull List<String> usernames) {
|
||||
final List<UUIDMapping> wrappers = new ArrayList<>(usernames.size());
|
||||
for (final String username : usernames) {
|
||||
if (Settings.UUID.OFFLINE) {
|
||||
|
@ -29,8 +29,8 @@ import com.destroystokyo.paper.profile.PlayerProfile;
|
||||
import com.plotsquared.core.uuid.UUIDMapping;
|
||||
import com.plotsquared.core.uuid.UUIDService;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
@ -40,7 +40,8 @@ import java.util.UUID;
|
||||
*/
|
||||
public class PaperUUIDService implements UUIDService {
|
||||
|
||||
@Override @Nonnull public List<UUIDMapping> getNames(@Nonnull final List<UUID> uuids) {
|
||||
@Override
|
||||
public @NonNull List<UUIDMapping> getNames(final @NonNull List<UUID> uuids) {
|
||||
final List<UUIDMapping> mappings = new ArrayList<>(uuids.size());
|
||||
for (final UUID uuid : uuids) {
|
||||
final PlayerProfile playerProfile = Bukkit.createProfile(uuid);
|
||||
@ -51,7 +52,8 @@ public class PaperUUIDService implements UUIDService {
|
||||
return mappings;
|
||||
}
|
||||
|
||||
@Override @Nonnull public List<UUIDMapping> getUUIDs(@Nonnull final List<String> usernames) {
|
||||
@Override
|
||||
public @NonNull List<UUIDMapping> getUUIDs(final @NonNull List<String> usernames) {
|
||||
final List<UUIDMapping> mappings = new ArrayList<>(usernames.size());
|
||||
for (final String username : usernames) {
|
||||
final PlayerProfile playerProfile = Bukkit.createProfile(username);
|
||||
|
@ -30,8 +30,8 @@ import com.plotsquared.core.database.SQLite;
|
||||
import com.plotsquared.core.util.FileUtils;
|
||||
import com.plotsquared.core.uuid.UUIDMapping;
|
||||
import com.plotsquared.core.uuid.UUIDService;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
@ -51,7 +51,7 @@ public class SQLiteUUIDService implements UUIDService, Consumer<List<UUIDMapping
|
||||
|
||||
public SQLiteUUIDService(final String fileName) {
|
||||
this.sqlite =
|
||||
new SQLite(FileUtils.getFile(PlotSquared.platform().getDirectory(), fileName));
|
||||
new SQLite(FileUtils.getFile(PlotSquared.platform().getDirectory(), fileName));
|
||||
try {
|
||||
this.sqlite.openConnection();
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
@ -59,7 +59,7 @@ public class SQLiteUUIDService implements UUIDService, Consumer<List<UUIDMapping
|
||||
}
|
||||
|
||||
try (PreparedStatement stmt = getConnection().prepareStatement(
|
||||
"CREATE TABLE IF NOT EXISTS `usercache` (uuid VARCHAR(32) NOT NULL, username VARCHAR(32) NOT NULL, PRIMARY KEY (uuid))")) {
|
||||
"CREATE TABLE IF NOT EXISTS `usercache` (uuid VARCHAR(32) NOT NULL, username VARCHAR(32) NOT NULL, PRIMARY KEY (uuid))")) {
|
||||
stmt.execute();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
@ -72,10 +72,11 @@ public class SQLiteUUIDService implements UUIDService, Consumer<List<UUIDMapping
|
||||
}
|
||||
}
|
||||
|
||||
@Override @Nonnull public List<UUIDMapping> getNames(@Nonnull final List<UUID> uuids) {
|
||||
@Override
|
||||
public @NonNull List<UUIDMapping> getNames(final @NonNull List<UUID> uuids) {
|
||||
final List<UUIDMapping> mappings = new ArrayList<>(uuids.size());
|
||||
try (final PreparedStatement statement = getConnection()
|
||||
.prepareStatement("SELECT `username` FROM `usercache` WHERE `uuid` = ?")) {
|
||||
.prepareStatement("SELECT `username` FROM `usercache` WHERE `uuid` = ?")) {
|
||||
for (final UUID uuid : uuids) {
|
||||
statement.setString(1, uuid.toString());
|
||||
try (final ResultSet resultSet = statement.executeQuery()) {
|
||||
@ -90,16 +91,19 @@ public class SQLiteUUIDService implements UUIDService, Consumer<List<UUIDMapping
|
||||
return mappings;
|
||||
}
|
||||
|
||||
@Override @Nonnull public List<UUIDMapping> getUUIDs(@Nonnull List<String> usernames) {
|
||||
@Override
|
||||
public @NonNull List<UUIDMapping> getUUIDs(@NonNull List<String> usernames) {
|
||||
final List<UUIDMapping> mappings = new ArrayList<>(usernames.size());
|
||||
try (final PreparedStatement statement = getConnection()
|
||||
.prepareStatement("SELECT `uuid` FROM `usercache` WHERE `username` = ?")) {
|
||||
.prepareStatement("SELECT `uuid` FROM `usercache` WHERE `username` = ?")) {
|
||||
for (final String username : usernames) {
|
||||
statement.setString(1, username);
|
||||
try (final ResultSet resultSet = statement.executeQuery()) {
|
||||
if (resultSet.next()) {
|
||||
mappings.add(new UUIDMapping(UUID.fromString(resultSet.getString("uuid")),
|
||||
username));
|
||||
mappings.add(new UUIDMapping(
|
||||
UUID.fromString(resultSet.getString("uuid")),
|
||||
username
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -109,9 +113,10 @@ public class SQLiteUUIDService implements UUIDService, Consumer<List<UUIDMapping
|
||||
return mappings;
|
||||
}
|
||||
|
||||
@Override public void accept(final List<UUIDMapping> uuidWrappers) {
|
||||
@Override
|
||||
public void accept(final List<UUIDMapping> uuidWrappers) {
|
||||
try (final PreparedStatement statement = getConnection()
|
||||
.prepareStatement("INSERT OR REPLACE INTO `usercache` (`uuid`, `username`) VALUES(?, ?)")) {
|
||||
.prepareStatement("INSERT OR REPLACE INTO `usercache` (`uuid`, `username`) VALUES(?, ?)")) {
|
||||
for (final UUIDMapping mapping : uuidWrappers) {
|
||||
statement.setString(1, mapping.getUuid().toString());
|
||||
statement.setString(2, mapping.getUsername());
|
||||
@ -127,7 +132,7 @@ public class SQLiteUUIDService implements UUIDService, Consumer<List<UUIDMapping
|
||||
*
|
||||
* @return All read mappings
|
||||
*/
|
||||
@Nonnull public List<UUIDMapping> getAll() {
|
||||
public @NonNull List<UUIDMapping> getAll() {
|
||||
final List<UUIDMapping> mappings = new LinkedList<>();
|
||||
try (final PreparedStatement statement = getConnection().prepareStatement("SELECT * FROM `usercache`")) {
|
||||
try (final ResultSet resultSet = statement.executeQuery()) {
|
||||
|
@ -32,10 +32,10 @@ import com.plotsquared.core.uuid.UUIDService;
|
||||
import com.sk89q.squirrelid.Profile;
|
||||
import com.sk89q.squirrelid.resolver.HttpRepositoryService;
|
||||
import com.sk89q.squirrelid.resolver.ProfileService;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@ -67,7 +67,8 @@ public class SquirrelIdUUIDService implements UUIDService {
|
||||
this.rateLimiter = RateLimiter.create(rateLimit / 600.0D);
|
||||
}
|
||||
|
||||
@Override @Nonnull public List<UUIDMapping> getNames(@Nonnull final List<UUID> uuids) {
|
||||
@Override
|
||||
public @NonNull List<UUIDMapping> getNames(final @NonNull List<UUID> uuids) {
|
||||
final List<UUIDMapping> results = new ArrayList<>(uuids.size());
|
||||
this.rateLimiter.acquire(uuids.size());
|
||||
try {
|
||||
@ -101,7 +102,8 @@ public class SquirrelIdUUIDService implements UUIDService {
|
||||
return results;
|
||||
}
|
||||
|
||||
@Override @Nonnull public List<UUIDMapping> getUUIDs(@Nonnull final List<String> usernames) {
|
||||
@Override
|
||||
public @NonNull List<UUIDMapping> getUUIDs(final @NonNull List<String> usernames) {
|
||||
final List<UUIDMapping> results = new ArrayList<>(usernames.size());
|
||||
this.rateLimiter.acquire(usernames.size());
|
||||
try {
|
||||
|
Reference in New Issue
Block a user