mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-01-30 12:00:34 +08:00
Confirm home replacement when overwriting existing homes (#3338)
Co-authored-by: Josh Roy <10731363+JRoy@users.noreply.github.com> Co-authored-by: MD <1917406+md678685@users.noreply.github.com> Warns the player that they are trying to replace a home, if they try to set one with the same name, when `confirm-home-overwrite` is set to `true` in the config. https://user-images.githubusercontent.com/17698576/83004206-3633eb00-9fc4-11ea-9317-fe245fed9cbb.png Fixes #2038 Closes #2847
This commit is contained in:
parent
7a5aea0bcf
commit
9f384c71f3
@ -372,6 +372,8 @@ public interface ISettings extends IConf {
|
|||||||
|
|
||||||
boolean isSpawnIfNoHome();
|
boolean isSpawnIfNoHome();
|
||||||
|
|
||||||
|
boolean isConfirmHomeOverwrite();
|
||||||
|
|
||||||
boolean infoAfterDeath();
|
boolean infoAfterDeath();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1742,7 +1742,12 @@ public class Settings implements net.ess3.api.ISettings {
|
|||||||
public boolean isSpawnIfNoHome() {
|
public boolean isSpawnIfNoHome() {
|
||||||
return config.getBoolean("spawn-if-no-home", true);
|
return config.getBoolean("spawn-if-no-home", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isConfirmHomeOverwrite() {
|
||||||
|
return config.getBoolean("confirm-home-overwrite", false);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean infoAfterDeath() {
|
public boolean infoAfterDeath() {
|
||||||
return config.getBoolean("send-info-after-death", false);
|
return config.getBoolean("send-info-after-death", false);
|
||||||
|
@ -66,6 +66,8 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
|||||||
private final Map<User, BigDecimal> confirmingPayments = new WeakHashMap<>();
|
private final Map<User, BigDecimal> confirmingPayments = new WeakHashMap<>();
|
||||||
private String confirmingClearCommand;
|
private String confirmingClearCommand;
|
||||||
private long lastNotifiedAboutMailsMs;
|
private long lastNotifiedAboutMailsMs;
|
||||||
|
private String lastHomeConfirmation;
|
||||||
|
private long lastHomeConfirmationTimestamp;
|
||||||
|
|
||||||
public User(final Player base, final IEssentials ess) {
|
public User(final Player base, final IEssentials ess) {
|
||||||
super(base, ess);
|
super(base, ess);
|
||||||
@ -979,4 +981,20 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getLastHomeConfirmation() {
|
||||||
|
return lastHomeConfirmation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastHomeConfirmation(String lastHomeConfirmation) {
|
||||||
|
this.lastHomeConfirmation = lastHomeConfirmation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getLastHomeConfirmationTimestamp() {
|
||||||
|
return lastHomeConfirmationTimestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastHomeConfirmationTimestamp() {
|
||||||
|
this.lastHomeConfirmationTimestamp = System.currentTimeMillis();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -217,6 +217,10 @@ public abstract class UserData extends PlayerExtension implements IConf {
|
|||||||
return config.hasProperty("home");
|
return config.hasProperty("home");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasHome(String name) {
|
||||||
|
return config.hasProperty("homes." + name);
|
||||||
|
}
|
||||||
|
|
||||||
private String nickname;
|
private String nickname;
|
||||||
|
|
||||||
public String _getNickname() {
|
public String _getNickname() {
|
||||||
|
@ -10,6 +10,7 @@ import org.bukkit.Server;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import static com.earth2me.essentials.I18n.tl;
|
import static com.earth2me.essentials.I18n.tl;
|
||||||
|
|
||||||
@ -55,8 +56,16 @@ public class Commandsethome extends EssentialsCommand {
|
|||||||
throw new Exception(tl("unsafeTeleportDestination", location.getWorld().getName(), location.getBlockX(), location.getBlockY(), location.getBlockZ()));
|
throw new Exception(tl("unsafeTeleportDestination", location.getWorld().getName(), location.getBlockX(), location.getBlockY(), location.getBlockZ()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ess.getSettings().isConfirmHomeOverwrite() && usersHome.hasHome(name) && (!name.equals(usersHome.getLastHomeConfirmation()) || name.equals(usersHome.getLastHomeConfirmation()) && System.currentTimeMillis() - usersHome.getLastHomeConfirmationTimestamp() > TimeUnit.MINUTES.toMillis(2))) {
|
||||||
|
usersHome.setLastHomeConfirmation(name);
|
||||||
|
usersHome.setLastHomeConfirmationTimestamp();
|
||||||
|
user.sendMessage(tl("homeConfirmation", name));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
usersHome.setHome(name, location);
|
usersHome.setHome(name, location);
|
||||||
user.sendMessage(tl("homeSet", user.getLocation().getWorld().getName(), user.getLocation().getBlockX(), user.getLocation().getBlockY(), user.getLocation().getBlockZ(), name));
|
user.sendMessage(tl("homeSet", user.getLocation().getWorld().getName(), user.getLocation().getBlockX(), user.getLocation().getBlockY(), user.getLocation().getBlockZ(), name));
|
||||||
|
usersHome.setLastHomeConfirmation(null);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -676,6 +676,9 @@ compass-towards-home-perm: false
|
|||||||
# If set to false, players will not be teleported when they run /home without setting a home first.
|
# If set to false, players will not be teleported when they run /home without setting a home first.
|
||||||
spawn-if-no-home: true
|
spawn-if-no-home: true
|
||||||
|
|
||||||
|
# Should players be asked to provide confirmation for homes which they attempt to overwrite?
|
||||||
|
confirm-home-overwrite: false
|
||||||
|
|
||||||
############################################################
|
############################################################
|
||||||
# +------------------------------------------------------+ #
|
# +------------------------------------------------------+ #
|
||||||
# | Economy | #
|
# | Economy | #
|
||||||
|
@ -280,6 +280,7 @@ holeInFloor=\u00a74Hole in floor\!
|
|||||||
homeCommandDescription=Teleport to your home.
|
homeCommandDescription=Teleport to your home.
|
||||||
homeCommandUsage=/<command> [player:][name]
|
homeCommandUsage=/<command> [player:][name]
|
||||||
homes=\u00a76Homes\:\u00a7r {0}
|
homes=\u00a76Homes\:\u00a7r {0}
|
||||||
|
homeConfirmation=\u00a76You already have a home named \u00a7c{0}\u00a76!\nTo overwrite your existing home, type the command again.
|
||||||
homeSet=\u00a76Home set to current location.
|
homeSet=\u00a76Home set to current location.
|
||||||
hour=hour
|
hour=hour
|
||||||
hours=hours
|
hours=hours
|
||||||
|
Loading…
Reference in New Issue
Block a user