mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-04 06:28:49 +00:00
essentials: Fix NPE when importing users
This commit is contained in:
1 file changed
+13
-21
@@ -37,40 +37,32 @@ public class EssentialsXImporter extends Importer {
|
|||||||
private final Essentials essentials;
|
private final Essentials essentials;
|
||||||
|
|
||||||
public EssentialsXImporter(@NotNull HuskHomes plugin) {
|
public EssentialsXImporter(@NotNull HuskHomes plugin) {
|
||||||
super("EssentialsX", List.of(ImportData.USERS, ImportData.HOMES, ImportData.WARPS), plugin);
|
super("EssentialsX", List.of(ImportData.HOMES, ImportData.WARPS), plugin);
|
||||||
this.essentials = (Essentials) ((BukkitHuskHomes) plugin).getServer().getPluginManager().getPlugin("Essentials");
|
this.essentials = (Essentials) ((BukkitHuskHomes) plugin).getServer().getPluginManager().getPlugin("Essentials");
|
||||||
}
|
}
|
||||||
|
|
||||||
private int importUsers() {
|
|
||||||
final AtomicInteger usersImported = new AtomicInteger();
|
|
||||||
for (UUID uuid : essentials.getUserMap().getAllUniqueUsers()) {
|
|
||||||
final User user = User.of(
|
|
||||||
uuid,
|
|
||||||
essentials.getUser(uuid).getLastAccountName()
|
|
||||||
);
|
|
||||||
plugin.getDatabase().ensureUser(user);
|
|
||||||
plugin.editUserData(user, (editor -> editor.setHomeSlots(Math.max(
|
|
||||||
plugin.getSettings().getFreeHomeSlots(),
|
|
||||||
essentials.getUser(uuid).getHomes().size()
|
|
||||||
))));
|
|
||||||
usersImported.getAndIncrement();
|
|
||||||
}
|
|
||||||
return usersImported.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
private int importHomes() {
|
private int importHomes() {
|
||||||
final AtomicInteger homesImported = new AtomicInteger();
|
final AtomicInteger homesImported = new AtomicInteger();
|
||||||
for (UUID uuid : essentials.getUserMap().getAllUniqueUsers()) {
|
for (UUID uuid : essentials.getUserMap().getAllUniqueUsers()) {
|
||||||
|
// Ensure the user is present and valid
|
||||||
final com.earth2me.essentials.User essentialsUser = essentials.getUser(uuid);
|
final com.earth2me.essentials.User essentialsUser = essentials.getUser(uuid);
|
||||||
|
if (essentialsUser == null || essentialsUser.getName() == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
final User user = User.of(uuid, essentialsUser.getName());
|
||||||
|
plugin.getDatabase().ensureUser(user);
|
||||||
|
|
||||||
|
// Create the home
|
||||||
for (String homeName : essentialsUser.getHomes()) {
|
for (String homeName : essentialsUser.getHomes()) {
|
||||||
BukkitAdapter.adaptLocation(essentialsUser.getHome(homeName))
|
BukkitAdapter.adaptLocation(essentialsUser.getHome(homeName))
|
||||||
.map(location -> Position.at(location, plugin.getServerName()))
|
.map(location -> Position.at(location, plugin.getServerName()))
|
||||||
.ifPresent(position -> {
|
.ifPresent(position -> {
|
||||||
plugin.getManager().homes().createHome(
|
plugin.getManager().homes().createHome(
|
||||||
User.of(uuid, essentialsUser.getLastAccountName()),
|
user,
|
||||||
this.normalizeName(homeName),
|
this.normalizeName(homeName),
|
||||||
position,
|
position,
|
||||||
true, true
|
true,
|
||||||
|
true
|
||||||
);
|
);
|
||||||
homesImported.getAndIncrement();
|
homesImported.getAndIncrement();
|
||||||
});
|
});
|
||||||
@@ -126,7 +118,7 @@ public class EssentialsXImporter extends Importer {
|
|||||||
@Override
|
@Override
|
||||||
protected int importData(@NotNull Importer.ImportData importData) throws Throwable {
|
protected int importData(@NotNull Importer.ImportData importData) throws Throwable {
|
||||||
return switch (importData) {
|
return switch (importData) {
|
||||||
case USERS -> importUsers();
|
case USERS -> 0;
|
||||||
case HOMES -> importHomes();
|
case HOMES -> importHomes();
|
||||||
case WARPS -> importWarps();
|
case WARPS -> importWarps();
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in new issue
Block a user