From 9360e147ac6ce4d1eb9c05f3af0fb4b94a11ed72 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Fri, 22 Dec 2023 13:07:34 -0800 Subject: [PATCH] Fun with arrows --- .../commands/skills/TridentsCommand.java | 6 +-- .../datatypes/skills/SubSkillType.java | 3 +- .../datatypes/skills/SuperAbilityType.java | 2 +- .../nossr50/listeners/EntityListener.java | 51 +++++++++++++++++-- src/main/java/com/gmail/nossr50/mcMMO.java | 2 +- .../gmail/nossr50/util/MetadataConstants.java | 1 + .../resources/locale/locale_en_US.properties | 1 + 7 files changed, 54 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/commands/skills/TridentsCommand.java b/src/main/java/com/gmail/nossr50/commands/skills/TridentsCommand.java index ef07c61f0..4acf203de 100644 --- a/src/main/java/com/gmail/nossr50/commands/skills/TridentsCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/skills/TridentsCommand.java @@ -2,11 +2,7 @@ package com.gmail.nossr50.commands.skills; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.datatypes.skills.SubSkillType; -import com.gmail.nossr50.mcMMO; -import com.gmail.nossr50.util.Permissions; -import com.gmail.nossr50.util.random.ProbabilityUtil; import com.gmail.nossr50.util.skills.CombatUtils; -import com.gmail.nossr50.util.skills.RankUtils; import com.gmail.nossr50.util.text.TextComponentFactory; import net.kyori.adventure.text.Component; import org.bukkit.entity.Player; @@ -31,7 +27,7 @@ public class TridentsCommand extends SkillCommand { protected List statsDisplay(Player player, float skillValue, boolean hasEndurance, boolean isLucky) { List messages = new ArrayList<>(); - if (canUseSubskill(player, SubSkillType.TRIDENTS_TRIDENTS_SUPER_ABILITY)) { + if (canUseSubskill(player, SubSkillType.TRIDENTS_SUPER)) { messages.add("Tridents Super Ability"); //TODO: Implement Tridents Super } diff --git a/src/main/java/com/gmail/nossr50/datatypes/skills/SubSkillType.java b/src/main/java/com/gmail/nossr50/datatypes/skills/SubSkillType.java index e4caa84e1..0eaf303a3 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/skills/SubSkillType.java +++ b/src/main/java/com/gmail/nossr50/datatypes/skills/SubSkillType.java @@ -35,6 +35,7 @@ public enum SubSkillType { /* CROSSBOWS */ CROSSBOWS_SUPER_SHOTGUN(1), CROSSBOWS_CROSSBOWS_LIMIT_BREAK(10), + CROSSBOWS_TRICK_SHOT(5), /* Excavation */ EXCAVATION_ARCHAEOLOGY(8), @@ -99,7 +100,7 @@ public enum SubSkillType { TAMING_THICK_FUR(1), /* Tridents */ - TRIDENTS_TRIDENTS_SUPER_ABILITY(1), + TRIDENTS_SUPER(1), TRIDENTS_TRIDENTS_LIMIT_BREAK(10), /* Unarmed */ diff --git a/src/main/java/com/gmail/nossr50/datatypes/skills/SuperAbilityType.java b/src/main/java/com/gmail/nossr50/datatypes/skills/SuperAbilityType.java index 21bdc041c..dab6d948d 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/skills/SuperAbilityType.java +++ b/src/main/java/com/gmail/nossr50/datatypes/skills/SuperAbilityType.java @@ -112,7 +112,7 @@ public enum SuperAbilityType { TREE_FELLER.subSkillTypeDefinition = SubSkillType.WOODCUTTING_TREE_FELLER; SERRATED_STRIKES.subSkillTypeDefinition = SubSkillType.SWORDS_SERRATED_STRIKES; BLAST_MINING.subSkillTypeDefinition = SubSkillType.MINING_BLAST_MINING; - TRIDENTS_SUPER_ABILITY.subSkillTypeDefinition = SubSkillType.TRIDENTS_TRIDENTS_SUPER_ABILITY; + TRIDENTS_SUPER_ABILITY.subSkillTypeDefinition = SubSkillType.TRIDENTS_SUPER; SUPER_SHOTGUN.subSkillTypeDefinition = SubSkillType.CROSSBOWS_SUPER_SHOTGUN; } diff --git a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java index 7f71c13f7..fa1b4307f 100644 --- a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java @@ -27,10 +27,7 @@ import com.gmail.nossr50.util.random.ProbabilityUtil; import com.gmail.nossr50.util.skills.CombatUtils; import com.gmail.nossr50.worldguard.WorldGuardManager; import com.gmail.nossr50.worldguard.WorldGuardUtils; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.NamespacedKey; -import org.bukkit.OfflinePlayer; +import org.bukkit.*; import org.bukkit.attribute.Attribute; import org.bukkit.block.Block; import org.bukkit.enchantments.Enchantment; @@ -48,6 +45,7 @@ import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.bukkit.projectiles.ProjectileSource; +import org.bukkit.util.Vector; import org.jetbrains.annotations.NotNull; public class EntityListener implements Listener { @@ -1111,5 +1109,50 @@ public class EntityListener implements Listener { } } + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onProjectileHitEvent(ProjectileHitEvent event) { + /* WORLD BLACKLIST CHECK */ + if (WorldBlacklist.isWorldBlacklisted(event.getEntity().getWorld())) + return; + if(event.getEntity() instanceof Arrow originalArrow && event.getHitBlock() != null) { + if (originalArrow.getShooter() instanceof Player) { + // Avoid infinite spawning of arrows + if (originalArrow.hasMetadata(MetadataConstants.METADATA_KEY_SPAWNED_ARROW)) { + return; + } + + // Spawn a new arrow shooting in a random direction + spawnArrow(originalArrow, originalArrow.getLocation()); + spawnArrow(originalArrow, originalArrow.getLocation()); + spawnArrow(originalArrow, originalArrow.getLocation()); + spawnArrow(originalArrow, originalArrow.getLocation()); + spawnArrow(originalArrow, originalArrow.getLocation()); + spawnArrow(originalArrow, originalArrow.getLocation()); + spawnArrow(originalArrow, originalArrow.getLocation()); + spawnArrow(originalArrow, originalArrow.getLocation()); + spawnArrow(originalArrow, originalArrow.getLocation()); + spawnArrow(originalArrow, originalArrow.getLocation()); + spawnArrow(originalArrow, originalArrow.getLocation()); + } + } + } + + private void spawnArrow(Arrow originalArrow, Location origin) { + // TODO: Add an event for this for plugins to hook into + // Spawn a new arrow shooting in a random direction + ProjectileSource originalArrowShooter = originalArrow.getShooter(); + Arrow arrow = originalArrow.getWorld().spawnArrow(origin, + new Vector( + // TODO: Spawn arrow away from surface + Math.random() * 2 - 1, + Math.random() * 2 - 1, + Math.random() * 2 - 1), 1, 1); + arrow.setShooter(originalArrowShooter); + arrow.setMetadata(MetadataConstants.METADATA_KEY_SPAWNED_ARROW, + new FixedMetadataValue(pluginRef, originalArrowShooter)); + arrow.setMetadata(MetadataConstants.METADATA_KEY_BOW_TYPE, + new FixedMetadataValue(pluginRef, originalArrow.getMetadata( + MetadataConstants.METADATA_KEY_BOW_TYPE).get(0))); + } } diff --git a/src/main/java/com/gmail/nossr50/mcMMO.java b/src/main/java/com/gmail/nossr50/mcMMO.java index f6e96c3fb..0b06663bc 100644 --- a/src/main/java/com/gmail/nossr50/mcMMO.java +++ b/src/main/java/com/gmail/nossr50/mcMMO.java @@ -98,7 +98,7 @@ public class mcMMO extends JavaPlugin { private static CommandManager commandManager; //ACF private static TransientEntityTracker transientEntityTracker; - private @NotNull SkillTools skillTools; + private SkillTools skillTools; private static boolean serverShutdownExecuted = false; diff --git a/src/main/java/com/gmail/nossr50/util/MetadataConstants.java b/src/main/java/com/gmail/nossr50/util/MetadataConstants.java index 8bec61365..321dcf2a1 100644 --- a/src/main/java/com/gmail/nossr50/util/MetadataConstants.java +++ b/src/main/java/com/gmail/nossr50/util/MetadataConstants.java @@ -14,6 +14,7 @@ public class MetadataConstants { * Take great care if you ever modify the value of these keys */ public static final @NotNull String METADATA_KEY_REPLANT = "mcMMO: Recently Replanted"; + public static final @NotNull String METADATA_KEY_SPAWNED_ARROW = "mcMMO: Spawned Arrow"; public static final @NotNull String METADATA_KEY_BOW_TYPE = "mcMMO: Bow Type"; public static final @NotNull String METADATA_KEY_EXPLOSION_FROM_RUPTURE = "mcMMO: Rupture Explosion"; public static final @NotNull String METADATA_KEY_FISH_HOOK_REF = "mcMMO: Fish Hook Tracker"; diff --git a/src/main/resources/locale/locale_en_US.properties b/src/main/resources/locale/locale_en_US.properties index 553240d5b..afc91df23 100644 --- a/src/main/resources/locale/locale_en_US.properties +++ b/src/main/resources/locale/locale_en_US.properties @@ -182,6 +182,7 @@ Archery.SubSkill.ArcheryLimitBreak.Description=Breaking your limits. Increased d Archery.SubSkill.ArcheryLimitBreak.Stat=Limit Break Max DMG Archery.Listener=Archery: Archery.SkillName=ARCHERY +Archery.SubSkill.ExplosiveShot.Name=Explosive Shot Archery.Skills.ExplosiveShot.Off= Archery.Skills.ExplosiveShot.On=&a**EXPLOSIVE SHOT ACTIVATED** Archery.Skills.ExplosiveShot.Other.Off=Explosive Shot&a has worn off for &e{0}