added 1.21

This commit is contained in:
nulli0n committed 2024-06-14 17:30:22 +05:00
1 parent bc8594db61
commit 8823d0eecd
10 files changed
+61 -12

No files matched your search

@@ -109,6 +109,6 @@ public class NightCore extends NightPlugin implements ImprovedCommands {
if (nbt == null) return false; if (nbt == null) return false;
ItemStack decompressed = ItemNbt.decompress(nbt); ItemStack decompressed = ItemNbt.decompress(nbt);
return decompressed != null && decompressed.getType() == testItem.getType(); return decompressed != null && decompressed.isSimilar(testItem);
} }
} }
@@ -100,7 +100,8 @@ public class ChainedNode extends CommandNode {
//System.out.println("context.getArgs() = " + Arrays.toString(context.getArgs())); //System.out.println("context.getArgs() = " + Arrays.toString(context.getArgs()));
//System.out.println("context.getIndex() = " + context.getIndex()); //System.out.println("context.getIndex() = " + context.getIndex());
if (context.getIndex() == context.getArgs().length - 1) { if (context.getIndex() == context.getArgs().length - 1) {
return new ArrayList<>(this.commandMap.keySet()); return this.getChildrens().stream().filter(node -> node.hasPermission(context.getSender())).map(CommandNode::getName).toList();
//return new ArrayList<>(this.commandMap.keySet());
} }
if (context.getIndex() >= context.getArgs().length) { if (context.getIndex() >= context.getArgs().length) {
return Collections.emptyList(); return Collections.emptyList();
@@ -324,7 +324,7 @@ public class FileConfig extends YamlConfiguration {
else { else {
String headTexture = this.getString(path + "Head_Texture", ""); String headTexture = this.getString(path + "Head_Texture", "");
if (!headTexture.isEmpty()) { if (!headTexture.isEmpty()) {
Plugins.CORE.warn("'Head_Texture' itemstack option is deprecated and will be removed soon. Please, use 'SkinURL' option instead."); Plugins.CORE.warn("'Head_Texture' itemstack option is deprecated and will be removed soon. Please, use 'SkinURL' option instead. Caused by: " + file.getPath());
ItemUtil.setSkullTexture(item, headTexture); ItemUtil.setSkullTexture(item, headTexture);
} }
} }
@@ -140,7 +140,7 @@ public class Colorizer {
} }
} }
return tagPlainHex(builder.toString()); return builder.toString();//tagPlainHex(builder.toString());
} }
@NotNull @NotNull
@@ -153,8 +153,9 @@ public class Colorizer {
while ((index = builder.toString().indexOf("#", lastIndex)) >= 0) { while ((index = builder.toString().indexOf("#", lastIndex)) >= 0) {
lastIndex = index + 1; lastIndex = index + 1;
if (builder.length() < 7) break; //if (builder.length() < 7) break;
if (index > 0 && builder.charAt(index - 1) == Tag.OPEN_BRACKET) continue; if (index > 0 && builder.charAt(index - 1) == Tag.OPEN_BRACKET) continue;
if (builder.length() < index + 7) break;
String sub = builder.substring(index, index + 7); String sub = builder.substring(index, index + 7);
try { try {
@@ -64,6 +64,8 @@ public class ItemUtil {
if (item.getType() != Material.PLAYER_HEAD) return; if (item.getType() != Material.PLAYER_HEAD) return;
if (!(item.getItemMeta() instanceof SkullMeta meta)) return; if (!(item.getItemMeta() instanceof SkullMeta meta)) return;
String name = urlData.substring(0, 16);
if (!urlData.startsWith(TEXTURES_HOST)) { if (!urlData.startsWith(TEXTURES_HOST)) {
urlData = TEXTURES_HOST + urlData; urlData = TEXTURES_HOST + urlData;
} }
@@ -73,7 +75,7 @@ public class ItemUtil {
// If no name, then meta#getOwnerProfile will return 'null' (wtf?) // If no name, then meta#getOwnerProfile will return 'null' (wtf?)
// sometimes swtiching to "new" spigot api is a pain. // sometimes swtiching to "new" spigot api is a pain.
// why the hell i have to dig into nms to learn that... // why the hell i have to dig into nms to learn that...
PlayerProfile profile = Bukkit.createPlayerProfile(uuid, urlData.substring(0, 16)); PlayerProfile profile = Bukkit.createPlayerProfile(uuid, name);
URL url = new URL(urlData); URL url = new URL(urlData);
PlayerTextures textures = profile.getTextures(); PlayerTextures textures = profile.getTextures();
textures.setSkin(url); textures.setSkin(url);
@@ -59,15 +59,32 @@ public class LocationUtil {
} }
@NotNull @NotNull
@Deprecated
public static Location getCenter(@NotNull Location location) { public static Location getCenter(@NotNull Location location) {
return getCenter(location, true); return setCenter3D(location);
} }
@NotNull @NotNull
@Deprecated
public static Location getCenter(@NotNull Location location, boolean doVertical) { public static Location getCenter(@NotNull Location location, boolean doVertical) {
return setCenter(location, doVertical);
}
@NotNull
public static Location setCenter2D(@NotNull Location location) {
return setCenter(location, false);
}
@NotNull
public static Location setCenter3D(@NotNull Location location) {
return setCenter(location, true);
}
@NotNull
public static Location setCenter(@NotNull Location location, boolean is3D) {
//Location centered = location.clone(); //Location centered = location.clone();
location.setX(location.getBlockX() + 0.5); location.setX(location.getBlockX() + 0.5);
location.setY(location.getBlockY() + (doVertical ? 0.5 : 0)); location.setY(location.getBlockY() + (is3D ? 0.5 : 0));
location.setZ(location.getBlockZ() + 0.5); location.setZ(location.getBlockZ() + 0.5);
return location; return location;
} }
@@ -3,16 +3,18 @@ package su.nightexpress.nightcore.util;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.Comparator;
import java.util.stream.Stream; import java.util.stream.Stream;
public enum Version { public enum Version {
V1_18_R2("1.18.2"), V1_18_R2("1.18.2", true),
V1_19_R3("1.19.4"), V1_19_R3("1.19.4"),
V1_20_R1("1.20.1", true), V1_20_R1("1.20.1", true),
V1_20_R2("1.20.2", true), V1_20_R2("1.20.2", true),
V1_20_R3("1.20.4"), V1_20_R3("1.20.4"),
MC_1_20_6("1.20.6"), MC_1_20_6("1.20.6"),
MC_1_21("1.21"),
UNKNOWN("Unknown"), UNKNOWN("Unknown"),
; ;
@@ -42,7 +44,7 @@ public enum Version {
public static Version getCurrent() { public static Version getCurrent() {
if (current == null) { if (current == null) {
String protocol = Bukkit.getServer().getBukkitVersion(); String protocol = Bukkit.getServer().getBukkitVersion();
current = Stream.of(values()).filter(version -> protocol.startsWith(version.getLocalized())).findFirst().orElse(UNKNOWN); current = Stream.of(values()).sorted(Comparator.reverseOrder()).filter(version -> protocol.startsWith(version.getLocalized())).findFirst().orElse(UNKNOWN);
} }
return current; return current;
} }
@@ -2,8 +2,10 @@ package su.nightexpress.nightcore.util.text;
import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.ComponentBuilder; import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.TextComponent;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import su.nightexpress.nightcore.util.Version;
import su.nightexpress.nightcore.util.text.tag.decorator.ColorDecorator; import su.nightexpress.nightcore.util.text.tag.decorator.ColorDecorator;
import su.nightexpress.nightcore.util.text.tag.decorator.Decorator; import su.nightexpress.nightcore.util.text.tag.decorator.Decorator;
import su.nightexpress.nightcore.util.text.tag.decorator.GradientColorDecorator; import su.nightexpress.nightcore.util.text.tag.decorator.GradientColorDecorator;
@@ -81,9 +83,23 @@ public class TextGroup implements ComponentBuildable {
//} //}
}); });
return this.build(builder);
}
private BaseComponent build(@NotNull ComponentBuilder builder) {
if (Version.isAtLeast(Version.MC_1_20_6)) {
return builder.build(); return builder.build();
} }
TextComponent base = new TextComponent();
if (!builder.getParts().isEmpty()) {
List<BaseComponent> cloned = new ArrayList<>(builder.getParts());
cloned.replaceAll(BaseComponent::duplicate);
base.setExtra(cloned);
}
return base;
}
private void countLength(@NotNull TextGroup parent, @NotNull AtomicInteger length) { private void countLength(@NotNull TextGroup parent, @NotNull AtomicInteger length) {
for (ComponentBuildable buildable : parent.getChildrens()) { for (ComponentBuildable buildable : parent.getChildrens()) {
if (buildable instanceof TextNode textNode) { if (buildable instanceof TextNode textNode) {
@@ -38,7 +38,7 @@ public class TextRoot {
} }
public void setString(@NotNull String string) { public void setString(@NotNull String string) {
string = Colorizer.plain(string); string = Colorizer.tagPlainHex(Colorizer.plain(string));
/*if (CoreConfig.LEGACY_COLOR_SUPPORT.get()) { /*if (CoreConfig.LEGACY_COLOR_SUPPORT.get()) {
TimedMatcher timedMatcher = TimedMatcher.create(Colorizer.PATTERN_HEX_LEGACY, string); TimedMatcher timedMatcher = TimedMatcher.create(Colorizer.PATTERN_HEX_LEGACY, string);
@@ -1,11 +1,13 @@
package su.nightexpress.nightcore.util.text.tag.decorator; package su.nightexpress.nightcore.util.text.tag.decorator;
import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent; import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.hover.content.Text; import net.md_5.bungee.api.chat.hover.content.Text;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import su.nightexpress.nightcore.util.Lists; import su.nightexpress.nightcore.util.Lists;
import su.nightexpress.nightcore.util.Placeholders; import su.nightexpress.nightcore.util.Placeholders;
import su.nightexpress.nightcore.util.Version;
import su.nightexpress.nightcore.util.text.NightMessage; import su.nightexpress.nightcore.util.text.NightMessage;
import java.util.List; import java.util.List;
@@ -25,7 +27,15 @@ public class ShowTextDecorator implements Decorator {
@NotNull @NotNull
public HoverEvent createEvent() { public HoverEvent createEvent() {
String fused = String.join(Placeholders.TAG_LINE_BREAK, this.text); String fused = String.join(Placeholders.TAG_LINE_BREAK, this.text);
Text text = new Text(NightMessage.parse(fused)); BaseComponent component = NightMessage.parse(fused);
Text text;
if (Version.isAtLeast(Version.MC_1_20_6)) {
text = new Text(component);
}
else {
text = new Text(new ComponentBuilder().append(component).create());
}
return new HoverEvent(HoverEvent.Action.SHOW_TEXT, text); return new HoverEvent(HoverEvent.Action.SHOW_TEXT, text);
} }