Fix sponge context group permission check.

* Fix GDEntityType getEnumCreatureType.
This commit is contained in:
bloodshot 2019-12-02 00:28:50 -05:00
parent 6bd5bcf2c4
commit a51c954c78
4 changed files with 47 additions and 24 deletions

View File

@ -83,6 +83,10 @@ public final class EntityTypeRegistryModule {
SPAWN_TYPES.put("monster", EnumCreatureType.MONSTER);
}
public void registerAdditionalCatalog(EntityType type) {
this.entityTypeMappings.put(type.getId(), new GDEntityType(type));
}
private static final class Holder {
static final EntityTypeRegistryModule INSTANCE = new EntityTypeRegistryModule();

View File

@ -27,6 +27,7 @@ package com.griefdefender.internal.registry;
import com.griefdefender.api.CatalogType;
import com.griefdefender.api.permission.Context;
import net.minecraft.entity.EnumCreatureType;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.entity.EntityType;
import org.spongepowered.common.entity.SpongeEntityType;
@ -61,7 +62,7 @@ public class GDEntityType implements CatalogType {
@Nullable
public String getEnumCreatureTypeId() {
if (this.creatureType == null) {
if (this.getEnumCreatureType() == null) {
return null;
}
switch (this.creatureType) {
@ -95,6 +96,12 @@ public class GDEntityType implements CatalogType {
@Nullable
public EnumCreatureType getEnumCreatureType() {
if (this.creatureType == null) {
final SpongeEntityType spongeEntityType = ((SpongeEntityType) Sponge.getRegistry().getType(EntityType.class, this.getId()).orElse(null));
if (spongeEntityType != null) {
this.creatureType = spongeEntityType.getEnumCreatureType();
}
}
return this.creatureType;
}

View File

@ -168,7 +168,7 @@ public class CommonEntityEventHandler {
fromClaim = this.storage.getClaimAt(fromLocation);
}
if (GDFlags.ENTER_CLAIM && !enterBlacklisted && user != null && user.getInternalPlayerData().lastClaim != null) {
if (player != null && GDFlags.ENTER_CLAIM && !enterBlacklisted && user.getInternalPlayerData().lastClaim != null) {
final GDClaim lastClaim = (GDClaim) user.getInternalPlayerData().lastClaim.get();
if (lastClaim != null && lastClaim != fromClaim) {
if (GDPermissionManager.getInstance().getFinalPermission(event, toLocation, toClaim, GDPermissions.ENTER_CLAIM, targetEntity, targetEntity, player, TrustTypes.ACCESSOR, false) == Tristate.FALSE) {
@ -220,28 +220,30 @@ public class CommonEntityEventHandler {
} else {
final boolean showGpPrefix = GriefDefenderPlugin.getGlobalConfig().getConfig().message.enterExitShowGdPrefix;
user.getInternalPlayerData().lastClaim = new WeakReference<>(toClaim);
TextComponent welcomeMessage = (TextComponent) gpEvent.getEnterMessage().orElse(null);
if (welcomeMessage != null && !welcomeMessage.equals(TextComponent.empty()) && !welcomeMessage.content().equals("")) {
ChatType chatType = gpEvent.getEnterMessageChatType();
if (showGpPrefix) {
TextAdapter.sendComponent(player, TextComponent.builder("")
.append(enterClanTag != null ? enterClanTag : GriefDefenderPlugin.GD_TEXT)
.append(welcomeMessage).build(), SpongeUtil.getSpongeChatType(chatType));
} else {
TextAdapter.sendComponent(player, enterClanTag != null ? enterClanTag : welcomeMessage, SpongeUtil.getSpongeChatType(chatType));
if (player != null) {
TextComponent welcomeMessage = (TextComponent) gpEvent.getEnterMessage().orElse(null);
if (welcomeMessage != null && !welcomeMessage.equals(TextComponent.empty()) && !welcomeMessage.content().equals("")) {
ChatType chatType = gpEvent.getEnterMessageChatType();
if (showGpPrefix) {
TextAdapter.sendComponent(player, TextComponent.builder("")
.append(enterClanTag != null ? enterClanTag : GriefDefenderPlugin.GD_TEXT)
.append(welcomeMessage).build(), SpongeUtil.getSpongeChatType(chatType));
} else {
TextAdapter.sendComponent(player, enterClanTag != null ? enterClanTag : welcomeMessage, SpongeUtil.getSpongeChatType(chatType));
}
}
}
Component farewellMessage = gpEvent.getExitMessage().orElse(null);
if (farewellMessage != null && !farewellMessage.equals(Text.of())) {
ChatType chatType = gpEvent.getExitMessageChatType();
if (showGpPrefix) {
TextAdapter.sendComponent(player, TextComponent.builder("")
.append(exitClanTag != null ? exitClanTag : GriefDefenderPlugin.GD_TEXT)
.append(farewellMessage)
.build(), SpongeUtil.getSpongeChatType(chatType));
} else {
TextAdapter.sendComponent(player, exitClanTag != null ? exitClanTag : farewellMessage, SpongeUtil.getSpongeChatType(chatType));
Component farewellMessage = gpEvent.getExitMessage().orElse(null);
if (farewellMessage != null && !farewellMessage.equals(Text.of())) {
ChatType chatType = gpEvent.getExitMessageChatType();
if (showGpPrefix) {
TextAdapter.sendComponent(player, TextComponent.builder("")
.append(exitClanTag != null ? exitClanTag : GriefDefenderPlugin.GD_TEXT)
.append(farewellMessage)
.build(), SpongeUtil.getSpongeChatType(chatType));
} else {
TextAdapter.sendComponent(player, exitClanTag != null ? exitClanTag : farewellMessage, SpongeUtil.getSpongeChatType(chatType));
}
}
}

View File

@ -57,6 +57,7 @@ import com.griefdefender.configuration.MessageStorage;
import com.griefdefender.configuration.category.BanCategory;
import com.griefdefender.event.GDCauseStackManager;
import com.griefdefender.event.GDFlagPermissionEvent;
import com.griefdefender.internal.registry.EntityTypeRegistryModule;
import com.griefdefender.internal.registry.GDEntityType;
import com.griefdefender.internal.util.BlockUtil;
import com.griefdefender.internal.util.NMSUtil;
@ -106,7 +107,6 @@ import org.spongepowered.api.world.LocatableBlock;
import org.spongepowered.api.world.Location;
import org.spongepowered.api.world.World;
import org.spongepowered.common.SpongeImplHooks;
import org.spongepowered.common.registry.type.entity.EntityTypeRegistryModule;
import java.util.Arrays;
import java.util.HashMap;
@ -632,6 +632,16 @@ public class GDPermissionManager implements PermissionManager {
}
}
GDEntityType type = EntityTypeRegistryModule.getInstance().getById(targetEntity.getType().getId()).orElse(null);
if (type == null) {
EntityTypeRegistryModule.getInstance().registerAdditionalCatalog(targetEntity.getType());
type = EntityTypeRegistryModule.getInstance().getById(targetEntity.getType().getId()).orElse(null);
}
if (type != null && !(targetEntity instanceof Player)) {
addCustomEntityTypeContexts(targetEntity, contexts, type, isSource);
}
if (this.isObjectIdBanned(claim, id, BanType.ENTITY)) {
return null;
}