Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 7 additions & 1 deletion src/main/java/xyz/srnyx/annoyingapi/AnnoyingPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,13 @@ public Relocation getRelocation(@NotNull String from, @NotNull String name) {
*/
@NotNull
public Relocation getRelocation(@NotNull String from) {
return getRelocation(from, from.substring(from.lastIndexOf("{}") + 2).toLowerCase().replaceAll("[^a-z0-9._{}]", ""));
String name = from;
if (name.contains("{}")) {
name = name.substring(name.lastIndexOf("{}") + 2);
} else if (name.contains(".")) {
name = name.substring(name.lastIndexOf(".") + 1);
}
return getRelocation(from, name.toLowerCase().replaceAll("[^a-z0-9._{}]", ""));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public SelectorOptional<T> mapRaw(@NotNull Function<String, String> mapper) {
*/
@Nullable @Unmodifiable
public List<T> orElse(@NotNull Function<String, List<T>> other) {
if (raw == null) return null;
if (selector == null) return other.apply(raw);
final List<T> expanded = selector.expand(sender);
if (expanded == null) sender.invalidArgument(raw);
Expand All @@ -102,6 +103,7 @@ public List<T> orElse(@NotNull Function<String, List<T>> other) {
*/
@Nullable @Unmodifiable
public List<T> orElseSingle(@NotNull Function<String, T> other) {
if (raw == null) return null;
if (selector == null) return Collections.singletonList(other.apply(raw));
final List<T> expanded = selector.expand(sender);
if (expanded == null) sender.invalidArgument(raw);
Expand All @@ -117,6 +119,7 @@ public List<T> orElseSingle(@NotNull Function<String, T> other) {
*/
@Nullable @Unmodifiable
public List<T> orElseFlat(@NotNull Function<String, Optional<List<T>>> other) {
if (raw == null) return null;
if (selector == null) {
final Optional<List<T>> result = other.apply(raw);
if (result.isEmpty()) sender.invalidArgument(raw);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,9 @@ private void downloadFile(@NotNull AnnoyingDependency dependency, @NotNull Plugi
final byte[] buffer = new byte[1024];
int numRead;
while ((numRead = in.read(buffer)) != -1) out.write(buffer, 0, numRead);
} catch (final IOException ignored) {
//ignored
} catch (final IOException e) {
fail(dependency, platform);
return;
}

// Send success message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import xyz.srnyx.annoyingapi.reflection.org.bukkit.attribute.RefAttributeModifier;

import static xyz.srnyx.annoyingapi.reflection.org.bukkit.attribute.RefAttributeModifier.ATTRIBUTE_MODIFIER_CLASS;
import static xyz.srnyx.annoyingapi.reflection.org.bukkit.attribute.RefAttributeModifier.ATTRIBUTE_MODIFIER_GET_AMOUNT_METHOD;
import static xyz.srnyx.annoyingapi.reflection.org.bukkit.attribute.RefAttributeModifier.ATTRIBUTE_MODIFIER_GET_NAME_METHOD;
import static xyz.srnyx.annoyingapi.reflection.org.bukkit.attribute.RefAttributeModifier.ATTRIBUTE_MODIFIER_GET_OPERATION_METHOD;
import static xyz.srnyx.annoyingapi.reflection.org.bukkit.attribute.RefAttributeModifier.ATTRIBUTE_MODIFIER_GET_SLOT_GROUP_METHOD;
Expand Down Expand Up @@ -43,6 +44,13 @@ public void serialize(@NotNull Object object, @NotNull SerializationData data, @
e.printStackTrace();
}

// amount
if (ATTRIBUTE_MODIFIER_GET_AMOUNT_METHOD != null) try {
data.set("amount", ATTRIBUTE_MODIFIER_GET_AMOUNT_METHOD.invoke(object));
} catch (final Exception e) {
e.printStackTrace();
}

// operation
try {
data.set("operation", ATTRIBUTE_MODIFIER_GET_OPERATION_METHOD.invoke(object));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ public class RefAttributeModifier {
*/
@Nullable public static final Method ATTRIBUTE_MODIFIER_GET_NAME_METHOD = ReflectionUtility.getMethod(1, 13, 2, ATTRIBUTE_MODIFIER_CLASS, "getName");

/**
* 1.13.2+ org.bukkit.attribute.AttributeModifier#getAmount()
*/
@Nullable public static final Method ATTRIBUTE_MODIFIER_GET_AMOUNT_METHOD = ReflectionUtility.getMethod(1, 13, 2, ATTRIBUTE_MODIFIER_CLASS, "getAmount");

/**
* 1.13.2+ org.bukkit.attribute.AttributeModifier#getOperation()
*/
Expand Down