Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix support for Chinese and other characters in setwarp and sethome filenames; ensure backward compatibility with old safe string names replaced by underscores#5890

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
wkea wants to merge7 commits intoEssentialsX:2.x
base:2.x
Choose a base branch
Loading
fromwkea:2.x
Open
Show file tree
Hide file tree
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
fix sethome delhome renamehome
Avoid causing potential bugs
  • Loading branch information
@wkea
wkea committedAug 1, 2024
commitef5de49271d4ef63652ab91beeb88d8d97eb35d9
26 changes: 16 additions & 10 deletionsEssentials/src/main/java/com/earth2me/essentials/UserData.java
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -143,10 +143,12 @@ private String getHomeName(String search) {
}
return search;
}

//Optimize character compatibility
public Location getHome(final String name) {
final String search = getHomeName(name);
final LazyLocation loc = holder.homes().get(search);
LazyLocation loc = holder.homes().get(getHomeName(name));
if (loc == null) {
loc = holder.homes().get(getHomeName(StringUtil.safeString(name)));
}
return loc != null ? loc.location() : null;
}

Expand DownExpand Up@@ -179,28 +181,32 @@ public List<String> getHomes() {

public void setHome(String name, final Location loc) {
//Invalid names will corrupt the yaml
name = StringUtil.safeString(name);
name = StringUtil.new_safeString(name);
holder.homes().put(name, LazyLocation.fromLocation(loc));
config.save();
}

public void delHome(final String name) throws Exception {
String search = getHomeName(name);
if (!holder.homes().containsKey(search)) {
search = StringUtil.safeString(search);
}
if (holder.homes().containsKey(search)) {
holder.homes().remove(search);
String safeSearch = StringUtil.new_safeString(search);
String oldSafeSearch = StringUtil.safeString(search);
if (holder.homes().containsKey(safeSearch)) {
holder.homes().remove(safeSearch);
config.save();
} else if (holder.homes().containsKey(oldSafeSearch)) {
holder.homes().remove(oldSafeSearch);
config.save();
} else {
throw new TranslatableException("invalidHome", search);
}
}


public void renameHome(final String name, final String newName) throws Exception {
final LazyLocation location = holder.homes().remove(name);
//If possible, it is necessary to improve the compatibility here to make it support underscores
if (location != null) {
holder.homes().put(StringUtil.safeString(newName), location);
holder.homes().put(StringUtil.new_safeString(newName), location);
config.save();
} else {
throw new TranslatableException("invalidHome", name);
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,7 +8,6 @@
import io.papermc.lib.PaperLib;
import net.ess3.api.TranslatableException;
import net.ess3.api.events.UserTeleportHomeEvent;

import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
Expand All@@ -19,7 +18,6 @@
import java.util.Optional;
import java.util.concurrent.CompletableFuture;


public class Commandhome extends EssentialsCommand {
public Commandhome() {
super("home");
Expand DownExpand Up@@ -128,8 +126,7 @@ private void goHome(final User user, final User player, final String home, final
throw new NotEnoughArgumentsException();
}

final Location loc = Optional.ofNullable(player.getHome(home))
.orElse(player.getHome(StringUtil.old_safeString(home)));
final Location loc = player.getHome(home);

if (loc == null) {
throw new NotEnoughArgumentsException();
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,8 +11,7 @@

public final class StringUtil {
private static final Pattern INVALIDCHARACTER = Pattern.compile("[/\\\\:*?\"<>|\\x00-\\x1F]");
private static final Pattern OLD_INVALIDCHARACTER = Pattern.compile("[^a-z0-9-]");
//private static final Pattern STRICTINVALIDCHARS = Pattern.compile("[^a-z0-9]");
private static final Pattern STRICTINVALIDCHARS = Pattern.compile("[^a-z0-9]");
@SuppressWarnings("CheckStyle")
private static final Pattern INVALIDCHARS = Pattern.compile("[^\t\n\r\u0020-\u007E\u0085\u00A0-\uD7FF\uE000-\uFFFD]");

Expand All@@ -30,14 +29,15 @@ public static String safeString(final String string) {
if (string == null) {
return null;
}
returnINVALIDCHARACTER.matcher(string.toLowerCase(Locale.ENGLISH)).replaceAll("_");
returnSTRICTINVALIDCHARS.matcher(string.toLowerCase(Locale.ENGLISH)).replaceAll("_");
}
public static Stringold_safeString(final String string) {
public static Stringnew_safeString(final String string) {
if (string == null) {
return null;
}
returnOLD_INVALIDCHARACTER.matcher(string.toLowerCase(Locale.ENGLISH)).replaceAll("_");
returnINVALIDCHARACTER.matcher(string.toLowerCase(Locale.ENGLISH)).replaceAll("_");
}

//Less restrictive string sanitizing, when not used as perm or filename
public static String sanitizeString(final String string) {
return INVALIDCHARS.matcher(string).replaceAll("");
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp