mirror of
https://github.com/bloodmc/GriefDefender.git
synced 2025-02-13 01:21:42 +01:00
Improve User Flag GUI.
User Flag GUI will no longer show values as 'undefined'. Instead, if no claim value is found then the default value will be displayed instead. This should be more friendly for end-users. * Fix sponge /givepet command. * Add 'protect-tamed-entities' claim config to allow protection for tamed entities such as horses. This new config setting is enabled by default.
This commit is contained in:
parent
95a7420d66
commit
89e57c17ba
@ -543,7 +543,7 @@ private void addFilteredContexts(Map<String, UIFlagData> filteredContextMap, Set
|
||||
|
||||
private Component getCustomFlagText(GDFlagDefinition customFlag) {
|
||||
TextComponent definitionType = TextComponent.empty();
|
||||
TextColor flagColor = TextColor.GREEN;
|
||||
TextColor flagColor = TextColor.YELLOW;
|
||||
for (Context context : customFlag.getContexts()) {
|
||||
if (context.getKey().contains("default")) {
|
||||
definitionType = TextComponent.builder()
|
||||
@ -659,7 +659,7 @@ private Component getCustomClickableText(GDPermissionUser src, GDClaim claim, GD
|
||||
newContexts.add(claim.getWorldContext());
|
||||
newContexts.add(claim.getOverrideTypeContext());
|
||||
newContexts.add(claim.getOverrideClaimContext());
|
||||
Tristate result = PermissionUtil.getInstance().getPermissionValueWithRequiredContexts(claim, GriefDefenderPlugin.DEFAULT_HOLDER, flagData.getFlag().getPermission(), newContexts, "gd_claim");
|
||||
Tristate result = PermissionUtil.getInstance().getPermissionValue(claim, GriefDefenderPlugin.DEFAULT_HOLDER, flagData.getFlag().getPermission(), newContexts);
|
||||
if (result != Tristate.UNDEFINED) {
|
||||
dataResults.add(new GDActiveFlagData(flagData, result, GDActiveFlagData.Type.OVERRIDE));
|
||||
continue;
|
||||
@ -669,7 +669,7 @@ private Component getCustomClickableText(GDPermissionUser src, GDClaim claim, GD
|
||||
newContexts = new HashSet<>(filteredContexts);
|
||||
newContexts.add(claim.getWorldContext());
|
||||
newContexts.add(claim.getContext());
|
||||
result = PermissionUtil.getInstance().getPermissionValueWithRequiredContexts(claim, GriefDefenderPlugin.DEFAULT_HOLDER, flagData.getFlag().getPermission(), newContexts, "gd_claim");
|
||||
result = PermissionUtil.getInstance().getPermissionValue(claim, GriefDefenderPlugin.DEFAULT_HOLDER, flagData.getFlag().getPermission(), newContexts);
|
||||
if (result != Tristate.UNDEFINED) {
|
||||
dataResults.add(new GDActiveFlagData(flagData, result, GDActiveFlagData.Type.CLAIM));
|
||||
continue;
|
||||
@ -680,7 +680,7 @@ private Component getCustomClickableText(GDPermissionUser src, GDClaim claim, GD
|
||||
newContexts.add(claim.getWorldContext());
|
||||
newContexts.add(ClaimContexts.GLOBAL_DEFAULT_CONTEXT);
|
||||
newContexts.add(claim.getDefaultTypeContext());
|
||||
result = PermissionUtil.getInstance().getPermissionValueWithRequiredContexts(claim, GriefDefenderPlugin.DEFAULT_HOLDER, flagData.getFlag().getPermission(), newContexts, "gd_claim");
|
||||
result = PermissionUtil.getInstance().getPermissionValue(claim, GriefDefenderPlugin.DEFAULT_HOLDER, flagData.getFlag().getPermission(), newContexts);
|
||||
if (result != Tristate.UNDEFINED) {
|
||||
dataResults.add(new GDActiveFlagData(flagData, result, GDActiveFlagData.Type.DEFAULT));
|
||||
continue;
|
||||
@ -714,7 +714,7 @@ private Component getCustomClickableText(GDPermissionUser src, GDClaim claim, GD
|
||||
} else {
|
||||
TextColor valueColor = TextColor.GRAY;
|
||||
if (lastResult == Tristate.TRUE) {
|
||||
valueColor = TextColor.GOLD;
|
||||
valueColor = TextColor.GREEN;
|
||||
} else if (lastResult == Tristate.FALSE) {
|
||||
valueColor = TextColor.RED;
|
||||
}
|
||||
@ -722,12 +722,10 @@ private Component getCustomClickableText(GDPermissionUser src, GDClaim claim, GD
|
||||
}
|
||||
|
||||
if (hasEditPermission) {
|
||||
if (lastResult == null || lastResult == Tristate.UNDEFINED) {
|
||||
hoverBuilder.append(MessageCache.getInstance().FLAG_UI_CLICK_ALLOW);
|
||||
} else if (lastResult == Tristate.TRUE) {
|
||||
if (lastResult == Tristate.TRUE) {
|
||||
hoverBuilder.append(MessageCache.getInstance().FLAG_UI_CLICK_DENY);
|
||||
} else {
|
||||
hoverBuilder.append(MessageCache.getInstance().FLAG_UI_CLICK_REMOVE);
|
||||
hoverBuilder.append(MessageCache.getInstance().FLAG_UI_CLICK_ALLOW);
|
||||
}
|
||||
|
||||
if (!customFlag.getContexts().isEmpty()) {
|
||||
@ -938,12 +936,10 @@ private Consumer<CommandSender> createCustomFlagConsumer(GDPermissionUser src, G
|
||||
final Set<Context> newContexts = new HashSet<>(definitionContexts);
|
||||
newContexts.addAll(flagData.getContexts());
|
||||
Tristate newValue = Tristate.UNDEFINED;
|
||||
if (currentValue == null || currentValue == Tristate.UNDEFINED) {
|
||||
newValue = Tristate.TRUE;
|
||||
} else if (currentValue == Tristate.TRUE) {
|
||||
if (currentValue == Tristate.TRUE) {
|
||||
newValue = Tristate.FALSE;
|
||||
} else {
|
||||
newValue = Tristate.UNDEFINED;
|
||||
newValue = Tristate.TRUE;
|
||||
}
|
||||
|
||||
final Flag flag = flagData.getFlag();
|
||||
|
@ -58,6 +58,8 @@ public class ClaimCategory extends ConfigCategory {
|
||||
@Setting(value = "claims-enabled",
|
||||
comment = "Whether claiming is enabled or not. (0 = Disabled, 1 = Enabled)")
|
||||
public int claimsEnabled = 1;
|
||||
@Setting(value = "protect-tamed-entities", comment = "Whether tamed entities should be protected in claims. Default: true")
|
||||
public boolean protectTamedEntities = true;
|
||||
@Setting(value = "reserved-claim-names", comment = "A list of reserved claim names for use only by administrators."
|
||||
+ "\nNote: Names support wildcards '?' and '*' by using Apache's wildcard matcher."
|
||||
+ "\nThe wildcard '?' represents a single character."
|
||||
|
@ -25,6 +25,7 @@
|
||||
package com.griefdefender.listener;
|
||||
|
||||
import com.flowpowered.math.vector.Vector3i;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.griefdefender.GDPlayerData;
|
||||
import com.griefdefender.GDTimings;
|
||||
@ -41,6 +42,7 @@
|
||||
import com.griefdefender.cache.PermissionHolderCache;
|
||||
import com.griefdefender.claim.GDClaim;
|
||||
import com.griefdefender.claim.GDClaimManager;
|
||||
import com.griefdefender.configuration.MessageStorage;
|
||||
import com.griefdefender.event.GDCauseStackManager;
|
||||
import com.griefdefender.internal.tracking.EntityTracker;
|
||||
import com.griefdefender.internal.tracking.entity.GDEntity;
|
||||
@ -51,6 +53,7 @@
|
||||
import com.griefdefender.storage.BaseStorage;
|
||||
import com.griefdefender.util.CauseContextHelper;
|
||||
import com.griefdefender.util.PlayerUtil;
|
||||
import net.kyori.text.Component;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.World;
|
||||
@ -333,6 +336,25 @@ public void onEntityDamage(EntityDamageByEntityEvent event) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (event.getEntity() instanceof Tameable) {
|
||||
final UUID uuid = NMSUtil.getInstance().getTameableOwnerUUID(event.getEntity());
|
||||
if (uuid != null) {
|
||||
// always allow owner to damage their pets
|
||||
if (player.getUniqueId().equals(uuid)) {
|
||||
return;
|
||||
}
|
||||
// If pet protection is enabled, deny the interaction
|
||||
if (GriefDefenderPlugin.getActiveConfig(player.getWorld().getUID()).getConfig().claim.protectTamedEntities) {
|
||||
final GDPermissionUser user = PermissionHolderCache.getInstance().getOrCreateUser(uuid);
|
||||
final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.CLAIM_PROTECTED_ENTITY,
|
||||
ImmutableMap.of(
|
||||
"player", user.getName()));
|
||||
GriefDefenderPlugin.sendMessage(player, message);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GDTimings.ENTITY_DAMAGE_EVENT.startTiming();
|
||||
|
@ -517,16 +517,34 @@ public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
|
||||
final ItemStack activeItem = NMSUtil.getInstance().getActiveItem(player, event);
|
||||
final GDPlayerData playerData = this.dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
|
||||
|
||||
if (targetEntity instanceof Tameable && playerData.petRecipientUniqueId != null) {
|
||||
final Tameable tameableEntity = (Tameable) targetEntity;
|
||||
final GDPermissionUser recipientUser = PermissionHolderCache.getInstance().getOrCreateUser(playerData.petRecipientUniqueId);
|
||||
if (recipientUser != null) {
|
||||
if (targetEntity instanceof Tameable) {
|
||||
if (playerData.petRecipientUniqueId != null) {
|
||||
final Tameable tameableEntity = (Tameable) targetEntity;
|
||||
final GDPermissionUser recipientUser = PermissionHolderCache.getInstance().getOrCreateUser(playerData.petRecipientUniqueId);
|
||||
tameableEntity.setOwner(recipientUser.getOfflinePlayer());
|
||||
playerData.petRecipientUniqueId = null;
|
||||
TextAdapter.sendComponent(player, MessageCache.getInstance().COMMAND_PET_CONFIRMATION);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
final UUID uuid = NMSUtil.getInstance().getTameableOwnerUUID(targetEntity);
|
||||
if (uuid != null) {
|
||||
// always allow owner to interact with their pets
|
||||
if (player.getUniqueId().equals(uuid)) {
|
||||
return;
|
||||
}
|
||||
// If pet protection is enabled, deny the interaction
|
||||
if (GriefDefenderPlugin.getActiveConfig(player.getWorld().getUID()).getConfig().claim.protectTamedEntities) {
|
||||
final GDPermissionUser user = PermissionHolderCache.getInstance().getOrCreateUser(uuid);
|
||||
final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.CLAIM_PROTECTED_ENTITY,
|
||||
ImmutableMap.of(
|
||||
"player", user.getName()));
|
||||
GriefDefenderPlugin.sendMessage(player, message);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (activeItem != null && activeItem.getType() != Material.AIR) {
|
||||
|
@ -543,7 +543,7 @@ private void addFilteredContexts(Map<String, UIFlagData> filteredContextMap, Set
|
||||
|
||||
private Component getCustomFlagText(GDFlagDefinition customFlag) {
|
||||
TextComponent definitionType = TextComponent.empty();
|
||||
TextColor flagColor = TextColor.GREEN;
|
||||
TextColor flagColor = TextColor.YELLOW;
|
||||
for (Context context : customFlag.getContexts()) {
|
||||
if (context.getKey().contains("default")) {
|
||||
definitionType = TextComponent.builder()
|
||||
@ -659,7 +659,7 @@ private Component getCustomClickableText(GDPermissionUser src, GDClaim claim, GD
|
||||
newContexts.add(claim.getWorldContext());
|
||||
newContexts.add(claim.getOverrideTypeContext());
|
||||
newContexts.add(claim.getOverrideClaimContext());
|
||||
Tristate result = PermissionUtil.getInstance().getPermissionValueWithRequiredContexts(claim, GriefDefenderPlugin.DEFAULT_HOLDER, flagData.getFlag().getPermission(), newContexts, "gd_claim");
|
||||
Tristate result = PermissionUtil.getInstance().getPermissionValue(claim, GriefDefenderPlugin.DEFAULT_HOLDER, flagData.getFlag().getPermission(), newContexts);
|
||||
if (result != Tristate.UNDEFINED) {
|
||||
dataResults.add(new GDActiveFlagData(flagData, result, GDActiveFlagData.Type.OVERRIDE));
|
||||
continue;
|
||||
@ -669,7 +669,7 @@ private Component getCustomClickableText(GDPermissionUser src, GDClaim claim, GD
|
||||
newContexts = new HashSet<>(filteredContexts);
|
||||
newContexts.add(claim.getWorldContext());
|
||||
newContexts.add(claim.getContext());
|
||||
result = PermissionUtil.getInstance().getPermissionValueWithRequiredContexts(claim, GriefDefenderPlugin.DEFAULT_HOLDER, flagData.getFlag().getPermission(), newContexts, "gd_claim");
|
||||
result = PermissionUtil.getInstance().getPermissionValue(claim, GriefDefenderPlugin.DEFAULT_HOLDER, flagData.getFlag().getPermission(), newContexts);
|
||||
if (result != Tristate.UNDEFINED) {
|
||||
dataResults.add(new GDActiveFlagData(flagData, result, GDActiveFlagData.Type.CLAIM));
|
||||
continue;
|
||||
@ -680,7 +680,7 @@ private Component getCustomClickableText(GDPermissionUser src, GDClaim claim, GD
|
||||
newContexts.add(claim.getWorldContext());
|
||||
newContexts.add(ClaimContexts.GLOBAL_DEFAULT_CONTEXT);
|
||||
newContexts.add(claim.getDefaultTypeContext());
|
||||
result = PermissionUtil.getInstance().getPermissionValueWithRequiredContexts(claim, GriefDefenderPlugin.DEFAULT_HOLDER, flagData.getFlag().getPermission(), newContexts, "gd_claim");
|
||||
result = PermissionUtil.getInstance().getPermissionValue(claim, GriefDefenderPlugin.DEFAULT_HOLDER, flagData.getFlag().getPermission(), newContexts);
|
||||
if (result != Tristate.UNDEFINED) {
|
||||
dataResults.add(new GDActiveFlagData(flagData, result, GDActiveFlagData.Type.DEFAULT));
|
||||
continue;
|
||||
@ -714,7 +714,7 @@ private Component getCustomClickableText(GDPermissionUser src, GDClaim claim, GD
|
||||
} else {
|
||||
TextColor valueColor = TextColor.GRAY;
|
||||
if (lastResult == Tristate.TRUE) {
|
||||
valueColor = TextColor.GOLD;
|
||||
valueColor = TextColor.GREEN;
|
||||
} else if (lastResult == Tristate.FALSE) {
|
||||
valueColor = TextColor.RED;
|
||||
}
|
||||
@ -722,12 +722,10 @@ private Component getCustomClickableText(GDPermissionUser src, GDClaim claim, GD
|
||||
}
|
||||
|
||||
if (hasEditPermission) {
|
||||
if (lastResult == null || lastResult == Tristate.UNDEFINED) {
|
||||
hoverBuilder.append(MessageCache.getInstance().FLAG_UI_CLICK_ALLOW);
|
||||
} else if (lastResult == Tristate.TRUE) {
|
||||
if (lastResult == Tristate.TRUE) {
|
||||
hoverBuilder.append(MessageCache.getInstance().FLAG_UI_CLICK_DENY);
|
||||
} else {
|
||||
hoverBuilder.append(MessageCache.getInstance().FLAG_UI_CLICK_REMOVE);
|
||||
hoverBuilder.append(MessageCache.getInstance().FLAG_UI_CLICK_ALLOW);
|
||||
}
|
||||
|
||||
if (!customFlag.getContexts().isEmpty()) {
|
||||
@ -938,12 +936,10 @@ private Consumer<CommandSource> createCustomFlagConsumer(GDPermissionUser src, G
|
||||
final Set<Context> newContexts = new HashSet<>(definitionContexts);
|
||||
newContexts.addAll(flagData.getContexts());
|
||||
Tristate newValue = Tristate.UNDEFINED;
|
||||
if (currentValue == null || currentValue == Tristate.UNDEFINED) {
|
||||
newValue = Tristate.TRUE;
|
||||
} else if (currentValue == Tristate.TRUE) {
|
||||
if (currentValue == Tristate.TRUE) {
|
||||
newValue = Tristate.FALSE;
|
||||
} else {
|
||||
newValue = Tristate.UNDEFINED;
|
||||
newValue = Tristate.TRUE;
|
||||
}
|
||||
|
||||
final Flag flag = flagData.getFlag();
|
||||
|
@ -58,6 +58,8 @@ public class ClaimCategory extends ConfigCategory {
|
||||
@Setting(value = "claims-enabled",
|
||||
comment = "Whether claiming is enabled or not. (0 = Disabled, 1 = Enabled)")
|
||||
public int claimsEnabled = 1;
|
||||
@Setting(value = "protect-tamed-entities", comment = "Whether tamed entities should be protected in claims. Default: true")
|
||||
public boolean protectedTamedEntities = true;
|
||||
@Setting(value = "reserved-claim-names", comment = "A list of reserved claim names for use only by administrators."
|
||||
+ "\nNote: Names support wildcards '?' and '*' by using Apache's wildcard matcher."
|
||||
+ "\nThe wildcard '?' represents a single character."
|
||||
|
@ -52,6 +52,7 @@
|
||||
import org.spongepowered.api.block.BlockSnapshot;
|
||||
import org.spongepowered.api.block.tileentity.TileEntity;
|
||||
import org.spongepowered.api.command.source.ConsoleSource;
|
||||
import org.spongepowered.api.data.key.Keys;
|
||||
import org.spongepowered.api.entity.Entity;
|
||||
import org.spongepowered.api.entity.EntityTypes;
|
||||
import org.spongepowered.api.entity.ExperienceOrb;
|
||||
@ -447,6 +448,31 @@ public boolean protectEntity(Event event, Entity targetEntity, Cause cause, Dama
|
||||
if (player == null) {
|
||||
player = (Player) source;
|
||||
}
|
||||
|
||||
final GDPlayerData playerData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
|
||||
// check give pet
|
||||
if (playerData.petRecipientUniqueId != null) {
|
||||
// cancel
|
||||
playerData.petRecipientUniqueId = null;
|
||||
GriefDefenderPlugin.sendMessage(player, MessageCache.getInstance().COMMAND_PET_TRANSFER_CANCEL);
|
||||
return true;
|
||||
}
|
||||
if (targetEntity instanceof Living && targetEntity.get(Keys.TAMED_OWNER).isPresent()) {
|
||||
final UUID ownerID = targetEntity.get(Keys.TAMED_OWNER).get().orElse(null);
|
||||
// always allow owner to interact with their pets
|
||||
if (player.getUniqueId().equals(ownerID)) {
|
||||
return false;
|
||||
}
|
||||
// If pet protection is enabled, deny the interaction
|
||||
if (GriefDefenderPlugin.getActiveConfig(player.getWorld().getProperties()).getConfig().claim.protectedTamedEntities) {
|
||||
final GDPermissionUser owner = PermissionHolderCache.getInstance().getOrCreateUser(ownerID);
|
||||
final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.CLAIM_PROTECTED_ENTITY,
|
||||
ImmutableMap.of(
|
||||
"player", owner.getName()));
|
||||
GriefDefenderPlugin.sendMessage(player, message);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,6 +47,7 @@
|
||||
import com.griefdefender.api.permission.option.Options;
|
||||
import com.griefdefender.api.permission.option.type.CreateModeTypes;
|
||||
import com.griefdefender.cache.MessageCache;
|
||||
import com.griefdefender.cache.PermissionHolderCache;
|
||||
import com.griefdefender.claim.GDClaim;
|
||||
import com.griefdefender.claim.GDClaimManager;
|
||||
import com.griefdefender.command.CommandHelper;
|
||||
@ -58,6 +59,7 @@
|
||||
import com.griefdefender.internal.util.NMSUtil;
|
||||
import com.griefdefender.internal.visual.ClaimVisual;
|
||||
import com.griefdefender.permission.GDPermissionManager;
|
||||
import com.griefdefender.permission.GDPermissionUser;
|
||||
import com.griefdefender.permission.GDPermissions;
|
||||
import com.griefdefender.permission.flag.GDFlags;
|
||||
import com.griefdefender.provider.NucleusProvider;
|
||||
@ -84,6 +86,7 @@
|
||||
import org.spongepowered.api.data.type.HandTypes;
|
||||
import org.spongepowered.api.entity.Entity;
|
||||
import org.spongepowered.api.entity.living.ArmorStand;
|
||||
import org.spongepowered.api.entity.living.Living;
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
import org.spongepowered.api.entity.living.player.User;
|
||||
import org.spongepowered.api.event.Listener;
|
||||
@ -669,7 +672,6 @@ public void onPlayerInteractInventoryClick(ClickInventoryEvent event, @First Pla
|
||||
GDTimings.PLAYER_INTERACT_INVENTORY_CLICK_EVENT.stopTimingIfSync();
|
||||
}
|
||||
|
||||
// when a player interacts with an entity...
|
||||
@Listener(order = Order.FIRST, beforeModifications = true)
|
||||
public void onPlayerInteractEntity(InteractEntityEvent.Primary event, @First Player player) {
|
||||
if (!GDFlags.INTERACT_ENTITY_PRIMARY || !GriefDefenderPlugin.getInstance().claimsEnabledForWorld(player.getWorld().getUniqueId())) {
|
||||
@ -689,6 +691,34 @@ public void onPlayerInteractEntity(InteractEntityEvent.Primary event, @First Pla
|
||||
}
|
||||
|
||||
GDTimings.PLAYER_INTERACT_ENTITY_PRIMARY_EVENT.startTimingIfSync();
|
||||
// check give pet
|
||||
final GDPlayerData playerData = this.dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
|
||||
if (playerData.petRecipientUniqueId != null) {
|
||||
playerData.petRecipientUniqueId = null;
|
||||
GriefDefenderPlugin.sendMessage(player, MessageCache.getInstance().COMMAND_PET_TRANSFER_CANCEL);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (targetEntity instanceof Living && targetEntity.get(Keys.TAMED_OWNER).isPresent()) {
|
||||
final UUID ownerID = targetEntity.get(Keys.TAMED_OWNER).get().orElse(null);
|
||||
// always allow owner to interact with their pets
|
||||
if (player.getUniqueId().equals(ownerID)) {
|
||||
GDTimings.PLAYER_INTERACT_ENTITY_PRIMARY_EVENT.stopTimingIfSync();
|
||||
return;
|
||||
}
|
||||
// If pet protection is enabled, deny the interaction
|
||||
if (GriefDefenderPlugin.getActiveConfig(player.getWorld().getProperties()).getConfig().claim.protectedTamedEntities) {
|
||||
final GDPermissionUser user = PermissionHolderCache.getInstance().getOrCreateUser(ownerID);
|
||||
final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.CLAIM_PROTECTED_ENTITY,
|
||||
ImmutableMap.of(
|
||||
"player", user.getName()));
|
||||
GriefDefenderPlugin.sendMessage(player, message);
|
||||
event.setCancelled(true);
|
||||
GDTimings.PLAYER_INTERACT_ENTITY_PRIMARY_EVENT.stopTimingIfSync();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Location<World> location = targetEntity.getLocation();
|
||||
GDClaim claim = this.dataStore.getClaimAt(location);
|
||||
if (event.isCancelled() && claim.getData().getPvpOverride() == Tristate.TRUE && targetEntity instanceof Player) {
|
||||
@ -710,7 +740,6 @@ public void onPlayerInteractEntity(InteractEntityEvent.Primary event, @First Pla
|
||||
}
|
||||
}
|
||||
|
||||
// when a player interacts with an entity...
|
||||
@Listener(order = Order.FIRST, beforeModifications = true)
|
||||
public void onPlayerInteractEntity(InteractEntityEvent.Secondary event, @First Player player) {
|
||||
if (!GDFlags.INTERACT_ENTITY_SECONDARY || !GriefDefenderPlugin.getInstance().claimsEnabledForWorld(player.getWorld().getUniqueId())) {
|
||||
@ -726,9 +755,34 @@ public void onPlayerInteractEntity(InteractEntityEvent.Secondary event, @First P
|
||||
}
|
||||
|
||||
GDTimings.PLAYER_INTERACT_ENTITY_SECONDARY_EVENT.startTimingIfSync();
|
||||
Location<World> location = targetEntity.getLocation();
|
||||
GDClaim claim = this.dataStore.getClaimAt(location);
|
||||
GDPlayerData playerData = this.dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
|
||||
final Location<World> location = targetEntity.getLocation();
|
||||
final GDClaim claim = this.dataStore.getClaimAt(location);
|
||||
final GDPlayerData playerData = this.dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
|
||||
if (targetEntity instanceof Living && targetEntity.get(Keys.TAMED_OWNER).isPresent()) {
|
||||
final UUID ownerID = targetEntity.get(Keys.TAMED_OWNER).get().orElse(null);
|
||||
// always allow owner to interact with their pets
|
||||
if (player.getUniqueId().equals(ownerID) || playerData.canIgnoreClaim(claim)) {
|
||||
if (playerData.petRecipientUniqueId != null) {
|
||||
targetEntity.offer(Keys.TAMED_OWNER, Optional.of(playerData.petRecipientUniqueId));
|
||||
playerData.petRecipientUniqueId = null;
|
||||
GriefDefenderPlugin.sendMessage(player, MessageCache.getInstance().COMMAND_PET_CONFIRMATION);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
GDTimings.PLAYER_INTERACT_ENTITY_SECONDARY_EVENT.stopTimingIfSync();
|
||||
return;
|
||||
}
|
||||
// If pet protection is enabled, deny the interaction
|
||||
if (GriefDefenderPlugin.getActiveConfig(player.getWorld().getProperties()).getConfig().claim.protectedTamedEntities) {
|
||||
final GDPermissionUser user = PermissionHolderCache.getInstance().getOrCreateUser(ownerID);
|
||||
final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.CLAIM_PROTECTED_ENTITY,
|
||||
ImmutableMap.of(
|
||||
"player", user.getName()));
|
||||
GriefDefenderPlugin.sendMessage(player, message);
|
||||
event.setCancelled(true);
|
||||
GDTimings.PLAYER_INTERACT_ENTITY_SECONDARY_EVENT.stopTimingIfSync();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (playerData.canIgnoreClaim(claim)) {
|
||||
GDTimings.PLAYER_INTERACT_ENTITY_SECONDARY_EVENT.stopTimingIfSync();
|
||||
@ -761,7 +815,6 @@ public void onPlayerInteractItem(InteractItemEvent event, @Root Player player) {
|
||||
handleItemInteract(event, player, world, itemInHand);
|
||||
}
|
||||
|
||||
// when a player picks up an item...
|
||||
@Listener(order = Order.LAST, beforeModifications = true)
|
||||
public void onPlayerPickupItem(ChangeInventoryEvent.Pickup.Pre event, @Root Player player) {
|
||||
if (!GDFlags.ITEM_PICKUP || !GriefDefenderPlugin.getInstance().claimsEnabledForWorld(player.getWorld().getUniqueId())) {
|
||||
@ -783,7 +836,6 @@ public void onPlayerPickupItem(ChangeInventoryEvent.Pickup.Pre event, @Root Play
|
||||
GDTimings.PLAYER_PICKUP_ITEM_EVENT.stopTimingIfSync();
|
||||
}
|
||||
|
||||
// when a player switches in-hand items
|
||||
@Listener
|
||||
public void onPlayerChangeHeldItem(ChangeInventoryEvent.Held event, @First Player player) {
|
||||
if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(player.getWorld().getUniqueId())) {
|
||||
|
Loading…
Reference in New Issue
Block a user