Skip to content

Commit

Permalink
Fixed HookManager bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubix327 committed Aug 27, 2023
1 parent 369acb3 commit e11def7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<groupId>org.mineacademy</groupId>
<artifactId>Foundation</artifactId>
<version>6.2.5.7</version>
<version>6.2.5.8</version>
<packaging>jar</packaging>

<name>Foundation</name>
Expand Down
27 changes: 20 additions & 7 deletions src/main/java/org/mineacademy/fo/model/HookManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import me.clip.placeholderapi.PlaceholderAPI;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import me.clip.placeholderapi.PlaceholderHook;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
Expand Down Expand Up @@ -73,6 +72,7 @@
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
* Our main class hooking into different plugins, providing you
Expand Down Expand Up @@ -178,7 +178,7 @@ else if (ver.startsWith("2.")) {

try {
mplayer = Class.forName("com.massivecraft.factions.entity.MPlayer"); // only support the free version of the plugin
} catch (final ClassNotFoundException ex) {
} catch (final ClassNotFoundException ignored) {
}

if (mplayer != null)
Expand Down Expand Up @@ -2413,7 +2413,8 @@ final String replaceRelationPlaceholders(final Player one, final Player two, fin
}

private String setRelationalPlaceholders(final Player one, final Player two, String text) {
final Map<String, PlaceholderHook> hooks = PlaceholderAPI.getPlaceholders();
final Map<String, PlaceholderHook> hooks = PlaceholderAPIPlugin.getInstance().getLocalExpansionManager()
.getExpansions().stream().collect(Collectors.toMap(PlaceholderExpansion::getIdentifier, ex -> ex));;

if (hooks.isEmpty())
return text;
Expand All @@ -2429,7 +2430,7 @@ private String setRelationalPlaceholders(final Player one, final Player two, Str
final String format = matcher.group(2);
final int index = format.indexOf("_");

if (index <= 0 || index >= format.length())
if (index <= 0)
continue;

final String identifier = format.substring(0, index);
Expand Down Expand Up @@ -2465,8 +2466,8 @@ public boolean persist() {
}

/**
* Because this is a internal class, this check is not needed
* and we can simply return {@code true}
* Because this is an internal class, this check is not needed,
* so we can simply return {@code true}
*
* @return Always true since it's an internal class.
*/
Expand Down Expand Up @@ -3208,7 +3209,19 @@ void setGodMode(final Player player, final boolean godMode) {
final CMIUser user = this.getUser(player);

if (user != null)
user.setGod(godMode);
try {
CMI.getInstance().getNMS().changeGodMode(player, godMode);

} catch (final Throwable tt) {
try {
final Method setGod = CMIUser.class.getMethod("setGod", Boolean.class);

setGod.invoke(user, godMode);

} catch (final Throwable t) {
// unavailable
}
}
}

void setLastTeleportLocation(final Player player, final Location location) {
Expand Down

0 comments on commit e11def7

Please sign in to comment.