mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-01 22:16:08 +00:00
importer: ignore max homes when importing
This commit is contained in:
3 files changed
+25
-18
No files matched your search
@@ -25,7 +25,6 @@ import net.william278.huskhomes.HuskHomes;
|
||||
import net.william278.huskhomes.teleport.TeleportRequest;
|
||||
import net.william278.huskhomes.user.BukkitUser;
|
||||
import net.william278.huskhomes.user.CommandUser;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.Permission;
|
||||
|
||||
@@ -21,6 +21,7 @@ package net.william278.huskhomes.importer;
|
||||
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import com.earth2me.essentials.Warps;
|
||||
import com.earth2me.essentials.commands.WarpNotFoundException;
|
||||
import net.william278.huskhomes.BukkitHuskHomes;
|
||||
import net.william278.huskhomes.HuskHomes;
|
||||
import net.william278.huskhomes.position.Position;
|
||||
@@ -32,6 +33,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class EssentialsXImporter extends Importer {
|
||||
|
||||
@@ -67,6 +69,7 @@ public class EssentialsXImporter extends Importer {
|
||||
this.normalizeName(homeName),
|
||||
position,
|
||||
true,
|
||||
true,
|
||||
true
|
||||
);
|
||||
homesImported.getAndIncrement();
|
||||
@@ -80,19 +83,23 @@ public class EssentialsXImporter extends Importer {
|
||||
final AtomicInteger warpsImported = new AtomicInteger();
|
||||
final Warps warps = essentials.getWarps();
|
||||
for (String warpName : warps.getList()) {
|
||||
if (warps.getWarp(warpName) == null || warps.getWarp(warpName).getWorld() == null) {
|
||||
continue;
|
||||
try {
|
||||
if (warps.getWarp(warpName) == null || warps.getWarp(warpName).getWorld() == null) {
|
||||
continue;
|
||||
}
|
||||
BukkitAdapter.adaptLocation(warps.getWarp(warpName))
|
||||
.map(location -> Position.at(location, plugin.getServerName()))
|
||||
.ifPresent(position -> {
|
||||
plugin.getManager().warps().createWarp(
|
||||
this.normalizeName(warpName),
|
||||
position,
|
||||
true
|
||||
);
|
||||
warpsImported.getAndIncrement();
|
||||
});
|
||||
} catch (WarpNotFoundException e) {
|
||||
plugin.log(Level.WARNING, String.format("Skipped importing warp %s (could not be found)", warpName));
|
||||
}
|
||||
BukkitAdapter.adaptLocation(warps.getWarp(warpName))
|
||||
.map(location -> Position.at(location, plugin.getServerName()))
|
||||
.ifPresent(position -> {
|
||||
plugin.getManager().warps().createWarp(
|
||||
this.normalizeName(warpName),
|
||||
position,
|
||||
true
|
||||
);
|
||||
warpsImported.getAndIncrement();
|
||||
});
|
||||
}
|
||||
return warpsImported.get();
|
||||
}
|
||||
|
||||
@@ -183,7 +183,8 @@ public class HomesManager {
|
||||
|
||||
@NotNull
|
||||
public Home createHome(@NotNull User owner, @NotNull String name, @NotNull Position position,
|
||||
boolean overwrite, boolean buyAdditionalSlots) throws ValidationException {
|
||||
boolean overwrite, boolean buyAdditionalSlots, boolean ignoreMaxHomes)
|
||||
throws ValidationException {
|
||||
final Optional<Home> existingHome = plugin.getDatabase().getHome(owner, name);
|
||||
if (existingHome.isPresent() && !overwrite) {
|
||||
throw new ValidationException(ValidationException.Type.NAME_TAKEN);
|
||||
@@ -194,7 +195,7 @@ public class HomesManager {
|
||||
|
||||
// Determine what the new home count would be & validate against user max homes
|
||||
int homes = plugin.getDatabase().getHomes(owner).size() + (existingHome.isPresent() ? 0 : 1);
|
||||
if (homes > getMaxHomes(owner)) {
|
||||
if (!ignoreMaxHomes && homes > getMaxHomes(owner)) {
|
||||
throw new ValidationException(ValidationException.Type.REACHED_MAX_HOMES);
|
||||
}
|
||||
|
||||
@@ -227,9 +228,9 @@ public class HomesManager {
|
||||
return home;
|
||||
}
|
||||
|
||||
public void createHome(@NotNull OnlineUser owner, @NotNull String name,
|
||||
@NotNull Position position) throws ValidationException {
|
||||
this.createHome(owner, name, position, plugin.getSettings().doOverwriteExistingHomesWarps(), true);
|
||||
public void createHome(@NotNull OnlineUser owner, @NotNull String name, @NotNull Position position)
|
||||
throws ValidationException {
|
||||
this.createHome(owner, name, position, plugin.getSettings().doOverwriteExistingHomesWarps(), true, false);
|
||||
}
|
||||
|
||||
public void deleteHome(@NotNull User owner, @NotNull String name) throws ValidationException {
|
||||
|
||||
Reference in new issue
Block a user