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