mirror of
https://github.com/bloodmc/GriefDefender.git
synced 2024-11-29 13:25:19 +01:00
sponge: Add support for living entity mod id context groups.
Examples are as follows modid:#all - This would block all entities with modid. modid:#monster - This would block all monsters with modid. modid:#animal - This would block all animals with modid. These can be used in either source or target contexts.
This commit is contained in:
parent
8743c5fe96
commit
1c8a2692d1
@ -216,6 +216,10 @@ public static PermissionResult addFlagPermission(CommandSource src, GDPermission
|
|||||||
GriefDefenderPlugin.sendMessage(src, denyReason);
|
GriefDefenderPlugin.sendMessage(src, denyReason);
|
||||||
return new GDPermissionResult(ResultTypes.NO_PERMISSION);
|
return new GDPermissionResult(ResultTypes.NO_PERMISSION);
|
||||||
}
|
}
|
||||||
|
if (value == null) {
|
||||||
|
GriefDefenderPlugin.sendMessage(src, MessageCache.getInstance().COMMAND_INVALID);
|
||||||
|
return new GDPermissionResult(ResultTypes.FAILURE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// special handling for commands
|
// special handling for commands
|
||||||
@ -234,11 +238,13 @@ public static PermissionResult addFlagPermission(CommandSource src, GDPermission
|
|||||||
}
|
}
|
||||||
|
|
||||||
String[] parts = target.split(":");
|
String[] parts = target.split(":");
|
||||||
if (parts.length <= 1 || !parts[1].equalsIgnoreCase("any")) {
|
if (parts.length == 1) {
|
||||||
|
addFlagContexts(contexts, flag, target);
|
||||||
|
} else if (parts.length > 1 && !parts[1].equalsIgnoreCase("any")) {
|
||||||
// check for meta
|
// check for meta
|
||||||
parts = target.split("\\.");
|
parts = target.split("\\.");
|
||||||
String targetFlag = parts[0];
|
String targetId = parts[0];
|
||||||
if (parts.length > 1) {
|
/*if (parts.length > 1) {
|
||||||
try {
|
try {
|
||||||
Integer.parseInt(parts[1]);
|
Integer.parseInt(parts[1]);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
@ -248,15 +254,9 @@ public static PermissionResult addFlagPermission(CommandSource src, GDPermission
|
|||||||
GriefDefenderPlugin.sendMessage(src, message);
|
GriefDefenderPlugin.sendMessage(src, message);
|
||||||
return new GDPermissionResult(ResultTypes.TARGET_NOT_VALID);
|
return new GDPermissionResult(ResultTypes.TARGET_NOT_VALID);
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
addFlagContexts(contexts, flag, targetFlag);
|
addFlagContexts(contexts, flag, targetId);
|
||||||
if (!targetFlag.startsWith("#") && !CommandHelper.validateFlagTarget(flag, targetFlag)) {
|
if (!targetId.contains("#") && !CommandHelper.validateFlagTarget(flag, targetId)) {
|
||||||
//TODO
|
|
||||||
/*final Text message = GriefDefenderPlugin.getInstance().messageData.permissionClaimManage
|
|
||||||
.apply(ImmutableMap.of(
|
|
||||||
"target", targetFlag,
|
|
||||||
"flag", baseFlag)).build();*/
|
|
||||||
GriefDefenderPlugin.sendMessage(src,TextComponent.of("Invalid flag " + targetFlag, TextColor.RED));
|
|
||||||
return new GDPermissionResult(ResultTypes.TARGET_NOT_VALID);
|
return new GDPermissionResult(ResultTypes.TARGET_NOT_VALID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,6 +74,7 @@
|
|||||||
import net.kyori.text.TextComponent;
|
import net.kyori.text.TextComponent;
|
||||||
import net.kyori.text.adapter.spongeapi.TextAdapter;
|
import net.kyori.text.adapter.spongeapi.TextAdapter;
|
||||||
import net.kyori.text.format.TextColor;
|
import net.kyori.text.format.TextColor;
|
||||||
|
import net.minecraft.entity.EnumCreatureType;
|
||||||
import net.minecraft.entity.item.EntityItem;
|
import net.minecraft.entity.item.EntityItem;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import org.apache.commons.io.FilenameUtils;
|
import org.apache.commons.io.FilenameUtils;
|
||||||
@ -626,10 +627,11 @@ public Set<Context> getPermissionContexts(GDClaim claim, Object obj, boolean isS
|
|||||||
id = "minecraft:player";
|
id = "minecraft:player";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String modId = "";
|
||||||
if (mcEntity != null && targetEntity instanceof Living) {
|
if (mcEntity != null && targetEntity instanceof Living) {
|
||||||
String[] parts = id.split(":");
|
String[] parts = id.split(":");
|
||||||
if (parts.length > 1) {
|
if (parts.length > 1) {
|
||||||
final String modId = parts[0];
|
modId = parts[0];
|
||||||
String name = parts[1];
|
String name = parts[1];
|
||||||
if (modId.equalsIgnoreCase("pixelmon") && modId.equalsIgnoreCase(name)) {
|
if (modId.equalsIgnoreCase("pixelmon") && modId.equalsIgnoreCase(name)) {
|
||||||
name = EntityUtils.getFriendlyName(mcEntity).toLowerCase();
|
name = EntityUtils.getFriendlyName(mcEntity).toLowerCase();
|
||||||
@ -645,7 +647,7 @@ public Set<Context> getPermissionContexts(GDClaim claim, Object obj, boolean isS
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (type != null && !(targetEntity instanceof Player)) {
|
if (type != null && !(targetEntity instanceof Player)) {
|
||||||
addCustomEntityTypeContexts(targetEntity, contexts, type, isSource);
|
addCustomEntityTypeContexts(targetEntity, contexts, type, modId, isSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.isObjectIdBanned(claim, id, BanType.ENTITY)) {
|
if (this.isObjectIdBanned(claim, id, BanType.ENTITY)) {
|
||||||
@ -824,11 +826,17 @@ public boolean isObjectIdBanned(GDClaim claim, String id, BanType type) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addCustomEntityTypeContexts(Entity targetEntity, Set<Context> contexts, GDEntityType type, boolean isSource) {
|
public void addCustomEntityTypeContexts(Entity targetEntity, Set<Context> contexts, GDEntityType type, String modId, boolean isSource) {
|
||||||
if (isSource) {
|
if (isSource) {
|
||||||
contexts.add(ContextGroups.SOURCE_ALL);
|
contexts.add(ContextGroups.SOURCE_ALL);
|
||||||
|
if (modId != null && !modId.isEmpty()) {
|
||||||
|
contexts.add(new Context(ContextKeys.SOURCE, modId + ":" + ContextGroupKeys.ALL));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
contexts.add(ContextGroups.TARGET_ALL);
|
contexts.add(ContextGroups.TARGET_ALL);
|
||||||
|
if (modId != null && !modId.isEmpty()) {
|
||||||
|
contexts.add(new Context(ContextKeys.TARGET, modId + ":" + ContextGroupKeys.ALL));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// check vehicle
|
// check vehicle
|
||||||
if (targetEntity instanceof Boat || targetEntity instanceof Minecart) {
|
if (targetEntity instanceof Boat || targetEntity instanceof Minecart) {
|
||||||
@ -838,42 +846,96 @@ public void addCustomEntityTypeContexts(Entity targetEntity, Set<Context> contex
|
|||||||
contexts.add(ContextGroups.TARGET_VEHICLE);
|
contexts.add(ContextGroups.TARGET_VEHICLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final String creatureType = type.getEnumCreatureTypeId();
|
|
||||||
|
String creatureType = type.getEnumCreatureTypeId();
|
||||||
if (creatureType == null) {
|
if (creatureType == null) {
|
||||||
|
// fallback check for mods
|
||||||
|
if (targetEntity instanceof net.minecraft.entity.Entity) {
|
||||||
|
final net.minecraft.entity.Entity mcEntity = (net.minecraft.entity.Entity) targetEntity;
|
||||||
|
if (SpongeImplHooks.isCreatureOfType(mcEntity, EnumCreatureType.CREATURE)) {
|
||||||
|
type.setEnumCreatureType(EnumCreatureType.CREATURE);
|
||||||
|
creatureType = type.getEnumCreatureTypeId();
|
||||||
|
} else if (SpongeImplHooks.isCreatureOfType(mcEntity, EnumCreatureType.MONSTER)) {
|
||||||
|
type.setEnumCreatureType(EnumCreatureType.MONSTER);
|
||||||
|
creatureType = type.getEnumCreatureTypeId();
|
||||||
|
} else if (SpongeImplHooks.isCreatureOfType(mcEntity, EnumCreatureType.WATER_CREATURE)) {
|
||||||
|
type.setEnumCreatureType(EnumCreatureType.WATER_CREATURE);
|
||||||
|
creatureType = type.getEnumCreatureTypeId();
|
||||||
|
} else if (SpongeImplHooks.isCreatureOfType(mcEntity, EnumCreatureType.AMBIENT)) {
|
||||||
|
type.setEnumCreatureType(EnumCreatureType.AMBIENT);
|
||||||
|
creatureType = type.getEnumCreatureTypeId();
|
||||||
|
}
|
||||||
|
if (type.getEnumCreatureType() == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
creatureType = type.getEnumCreatureTypeId();
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
final String contextKey = isSource ? "source" : "target";
|
final String contextKey = isSource ? "source" : "target";
|
||||||
//contexts.add(new Context(contextKey, "#" + creatureType));
|
//contexts.add(new Context(contextKey, "#" + creatureType));
|
||||||
if (creatureType.contains("animal")) {
|
if (creatureType.contains("animal")) {
|
||||||
if (isSource) {
|
if (isSource) {
|
||||||
contexts.add(ContextGroups.SOURCE_ANIMAL);
|
contexts.add(ContextGroups.SOURCE_ANIMAL);
|
||||||
|
if (modId != null && !modId.isEmpty()) {
|
||||||
|
contexts.add(new Context(ContextKeys.SOURCE, modId + ":" + ContextGroupKeys.ANIMAL));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
contexts.add(ContextGroups.TARGET_ANIMAL);
|
contexts.add(ContextGroups.TARGET_ANIMAL);
|
||||||
|
if (modId != null && !modId.isEmpty()) {
|
||||||
|
contexts.add(new Context(ContextKeys.TARGET, modId + ":" + ContextGroupKeys.ANIMAL));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (creatureType.contains("aquatic")) {
|
} else if (creatureType.contains("aquatic")) {
|
||||||
if (isSource) {
|
if (isSource) {
|
||||||
contexts.add(ContextGroups.SOURCE_AQUATIC);
|
contexts.add(ContextGroups.SOURCE_AQUATIC);
|
||||||
|
if (modId != null && !modId.isEmpty()) {
|
||||||
|
contexts.add(new Context(ContextKeys.SOURCE, modId + ":" + ContextGroupKeys.AQUATIC));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
contexts.add(ContextGroups.TARGET_AQUATIC);
|
contexts.add(ContextGroups.TARGET_AQUATIC);
|
||||||
|
if (modId != null && !modId.isEmpty()) {
|
||||||
|
contexts.add(new Context(ContextKeys.TARGET, modId + ":" + ContextGroupKeys.AQUATIC));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (creatureType.contains("monster")) {
|
} else if (creatureType.contains("monster")) {
|
||||||
if (isSource) {
|
if (isSource) {
|
||||||
contexts.add(ContextGroups.SOURCE_MONSTER);
|
contexts.add(ContextGroups.SOURCE_MONSTER);
|
||||||
|
if (modId != null && !modId.isEmpty()) {
|
||||||
|
contexts.add(new Context(ContextKeys.SOURCE, modId + ":" + ContextGroupKeys.MONSTER));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
contexts.add(ContextGroups.TARGET_MONSTER);
|
contexts.add(ContextGroups.TARGET_MONSTER);
|
||||||
|
if (modId != null && !modId.isEmpty()) {
|
||||||
|
contexts.add(new Context(ContextKeys.TARGET, modId + ":" + ContextGroupKeys.MONSTER));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (creatureType.contains("ambient")) {
|
} else if (creatureType.contains("ambient")) {
|
||||||
if (isSource) {
|
if (isSource) {
|
||||||
contexts.add(ContextGroups.SOURCE_AMBIENT);
|
contexts.add(ContextGroups.SOURCE_AMBIENT);
|
||||||
|
if (modId != null && !modId.isEmpty()) {
|
||||||
|
contexts.add(new Context(ContextKeys.SOURCE, modId + ":" + ContextGroupKeys.AMBIENT));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
contexts.add(ContextGroups.TARGET_AMBIENT);
|
contexts.add(ContextGroups.TARGET_AMBIENT);
|
||||||
|
if (modId != null && !modId.isEmpty()) {
|
||||||
|
contexts.add(new Context(ContextKeys.TARGET, modId + ":" + ContextGroupKeys.AMBIENT));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (isSource) {
|
if (isSource) {
|
||||||
contexts.add(ContextGroups.SOURCE_MISC);
|
contexts.add(ContextGroups.SOURCE_MISC);
|
||||||
|
if (modId != null && !modId.isEmpty()) {
|
||||||
|
contexts.add(new Context(ContextKeys.SOURCE, modId + ":" + ContextGroupKeys.MISC));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
contexts.add(ContextGroups.TARGET_MISC);
|
contexts.add(ContextGroups.TARGET_MISC);
|
||||||
|
if (modId != null && !modId.isEmpty()) {
|
||||||
|
contexts.add(new Context(ContextKeys.TARGET, modId + ":" + ContextGroupKeys.MISC));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user