mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-10-13 17:48:20 +02:00
misc optimization
This commit is contained in:
@@ -90,13 +90,18 @@ import org.bukkit.potion.PotionEffectType;
|
|||||||
import org.bukkit.projectiles.ProjectileSource;
|
import org.bukkit.projectiles.ProjectileSource;
|
||||||
|
|
||||||
public class EntityListener implements Listener {
|
public class EntityListener implements Listener {
|
||||||
|
private static final String MULTISHOT = "multishot";
|
||||||
|
private static final String PIERCING = "piercing";
|
||||||
|
private static final String DEEPSLATE_REDSTONE_ORE = "deepslate_redstone_ore";
|
||||||
|
private static final Set<String> ARMOR_STAND = Set.of("ARMOR_STAND", "armor_stand");
|
||||||
|
private static final Set<String> MANNEQUIN = Set.of("mannequin", "MANNEQUIN");
|
||||||
private final mcMMO pluginRef;
|
private final mcMMO pluginRef;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* We can use this {@link NamespacedKey} for {@link Enchantment} comparisons to check if a
|
* We can use this {@link NamespacedKey} for {@link Enchantment} comparisons to check if a
|
||||||
* {@link Player} has a {@link Trident} enchanted with "Piercing".
|
* {@link Player} has a {@link Trident} enchanted with "Piercing".
|
||||||
*/
|
*/
|
||||||
private final NamespacedKey piercingEnchantment = NamespacedKey.minecraft("piercing");
|
private final NamespacedKey piercingEnchantment = NamespacedKey.minecraft(PIERCING);
|
||||||
private final static Set<EntityType> TRANSFORMABLE_ENTITIES
|
private final static Set<EntityType> TRANSFORMABLE_ENTITIES
|
||||||
= Set.of(EntityType.SLIME, EntityType.MAGMA_CUBE);
|
= Set.of(EntityType.SLIME, EntityType.MAGMA_CUBE);
|
||||||
|
|
||||||
@@ -206,7 +211,7 @@ public class EntityListener implements Listener {
|
|||||||
CombatUtils.delayArrowMetaCleanup(arrow);
|
CombatUtils.delayArrowMetaCleanup(arrow);
|
||||||
|
|
||||||
// If fired from an item with multi-shot, we need to track
|
// If fired from an item with multi-shot, we need to track
|
||||||
if (ItemUtils.doesPlayerHaveEnchantmentInHands(player, "multishot")) {
|
if (ItemUtils.doesPlayerHaveEnchantmentInHands(player, MULTISHOT)) {
|
||||||
arrow.setMetadata(MetadataConstants.METADATA_KEY_MULTI_SHOT_ARROW,
|
arrow.setMetadata(MetadataConstants.METADATA_KEY_MULTI_SHOT_ARROW,
|
||||||
MetadataConstants.MCMMO_METADATA_VALUE);
|
MetadataConstants.MCMMO_METADATA_VALUE);
|
||||||
}
|
}
|
||||||
@@ -222,7 +227,7 @@ public class EntityListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Check both hands
|
//Check both hands
|
||||||
if (ItemUtils.doesPlayerHaveEnchantmentInHands(player, "piercing")) {
|
if (ItemUtils.doesPlayerHaveEnchantmentInHands(player, PIERCING)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -283,7 +288,7 @@ public class EntityListener implements Listener {
|
|||||||
entity.removeMetadata(MetadataConstants.METADATA_KEY_TRAVELING_BLOCK, pluginRef);
|
entity.removeMetadata(MetadataConstants.METADATA_KEY_TRAVELING_BLOCK, pluginRef);
|
||||||
}
|
}
|
||||||
} else if ((block.getType() == Material.REDSTONE_ORE || block.getType().getKey().getKey()
|
} else if ((block.getType() == Material.REDSTONE_ORE || block.getType().getKey().getKey()
|
||||||
.equalsIgnoreCase("deepslate_redstone_ore"))) {
|
.equalsIgnoreCase(DEEPSLATE_REDSTONE_ORE))) {
|
||||||
//Redstone ore fire this event and should be ignored
|
//Redstone ore fire this event and should be ignored
|
||||||
} else {
|
} else {
|
||||||
if (mcMMO.getUserBlockTracker().isIneligible(block)) {
|
if (mcMMO.getUserBlockTracker().isIneligible(block)) {
|
||||||
@@ -354,12 +359,12 @@ public class EntityListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (ExperienceConfig.getInstance().isArmorStandInteractionPrevented()
|
if (ExperienceConfig.getInstance().isArmorStandInteractionPrevented()
|
||||||
&& attacker.getType().toString().toLowerCase(Locale.ENGLISH).equals("armor_stand")) {
|
&& isArmorStandEntity(attacker)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ExperienceConfig.getInstance().isMannequinInteractionPrevented()
|
if (ExperienceConfig.getInstance().isMannequinInteractionPrevented()
|
||||||
&& attacker.getType().toString().toLowerCase(Locale.ENGLISH).equals("mannequin")) {
|
&& isMannequinEntity(attacker)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1199,4 +1204,12 @@ public class EntityListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean isMannequinEntity(Entity attacker) {
|
||||||
|
return MANNEQUIN.contains(attacker.getType().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isArmorStandEntity(Entity attacker) {
|
||||||
|
return ARMOR_STAND.contains(attacker.getType().toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user