mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 21:26:46 +01:00
Calculate bonus XP based on initial arrow location, rather than final
shooter location.
This commit is contained in:
parent
8d5696507a
commit
d8ddd27d71
@ -61,12 +61,16 @@ public class EntityListener implements Listener {
|
|||||||
public void onEntityShootBow(EntityShootBowEvent event) {
|
public void onEntityShootBow(EntityShootBowEvent event) {
|
||||||
ItemStack bow = event.getBow();
|
ItemStack bow = event.getBow();
|
||||||
|
|
||||||
if (bow != null && bow.containsEnchantment(Enchantment.ARROW_INFINITE)) {
|
if (bow != null) {
|
||||||
Entity projectile = event.getProjectile();
|
Entity projectile = event.getProjectile();
|
||||||
|
|
||||||
if (projectile instanceof Arrow) {
|
if (projectile instanceof Arrow) {
|
||||||
projectile.setMetadata(mcMMO.infiniteArrowKey, mcMMO.metadataValue);
|
if (bow.containsEnchantment(Enchantment.ARROW_INFINITE)) {
|
||||||
|
projectile.setMetadata(mcMMO.infiniteArrowKey, mcMMO.metadataValue);
|
||||||
|
}
|
||||||
|
|
||||||
projectile.setMetadata(mcMMO.bowForceKey, new FixedMetadataValue(plugin, Math.min(event.getForce() * AdvancedConfig.getInstance().getForceMultiplier(), 1.0)));
|
projectile.setMetadata(mcMMO.bowForceKey, new FixedMetadataValue(plugin, Math.min(event.getForce() * AdvancedConfig.getInstance().getForceMultiplier(), 1.0)));
|
||||||
|
projectile.setMetadata(mcMMO.arrowDistanceKey, new FixedMetadataValue(plugin, Archery.locationToString(projectile.getLocation())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,6 +96,7 @@ public class mcMMO extends JavaPlugin {
|
|||||||
public final static String droppedItemKey = "mcMMO: Tracked Item";
|
public final static String droppedItemKey = "mcMMO: Tracked Item";
|
||||||
public final static String infiniteArrowKey = "mcMMO: Infinite Arrow";
|
public final static String infiniteArrowKey = "mcMMO: Infinite Arrow";
|
||||||
public final static String bowForceKey = "mcMMO: Bow Force";
|
public final static String bowForceKey = "mcMMO: Bow Force";
|
||||||
|
public final static String arrowDistanceKey = "mcMMO: Arrow Distance";
|
||||||
|
|
||||||
public static FixedMetadataValue metadataValue;
|
public static FixedMetadataValue metadataValue;
|
||||||
|
|
||||||
|
@ -4,10 +4,12 @@ import java.util.ArrayList;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import com.gmail.nossr50.mcMMO;
|
||||||
import com.gmail.nossr50.config.AdvancedConfig;
|
import com.gmail.nossr50.config.AdvancedConfig;
|
||||||
import com.gmail.nossr50.util.Misc;
|
import com.gmail.nossr50.util.Misc;
|
||||||
|
|
||||||
@ -65,4 +67,14 @@ public class Archery {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Location stringToLocation(String location) {
|
||||||
|
String[] values = location.split(",");
|
||||||
|
|
||||||
|
return new Location(mcMMO.p.getServer().getWorld(values[0]), Double.parseDouble(values[1]), Double.parseDouble(values[2]), Double.parseDouble(values[3]), Float.parseFloat(values[4]), Float.parseFloat(values[5]));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String locationToString(Location location) {
|
||||||
|
return location.getWorld().getName() + "," + location.getX() + "," + location.getY() + "," + location.getZ() + "," + location.getYaw() + "," + location.getPitch();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
package com.gmail.nossr50.skills.archery;
|
package com.gmail.nossr50.skills.archery;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.potion.PotionEffect;
|
import org.bukkit.potion.PotionEffect;
|
||||||
import org.bukkit.potion.PotionEffectType;
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
|
||||||
|
import com.gmail.nossr50.mcMMO;
|
||||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||||
import com.gmail.nossr50.locale.LocaleLoader;
|
import com.gmail.nossr50.locale.LocaleLoader;
|
||||||
@ -37,20 +39,15 @@ public class ArcheryManager extends SkillManager {
|
|||||||
*
|
*
|
||||||
* @param target The {@link LivingEntity} damaged by the arrow
|
* @param target The {@link LivingEntity} damaged by the arrow
|
||||||
*/
|
*/
|
||||||
public void distanceXpBonus(LivingEntity target) {
|
public void distanceXpBonus(LivingEntity target, Entity damager) {
|
||||||
Player player = getPlayer();
|
Location firedLocation = Archery.stringToLocation(damager.getMetadata(mcMMO.arrowDistanceKey).get(0).asString());
|
||||||
Location shooterLocation = player.getLocation();
|
|
||||||
Location targetLocation = target.getLocation();
|
Location targetLocation = target.getLocation();
|
||||||
|
|
||||||
if (shooterLocation.getWorld() != targetLocation.getWorld()) {
|
if (firedLocation.getWorld() != targetLocation.getWorld()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cap distance at 100^2 to prevent teleport exploit.
|
applyXpGain((int) (firedLocation.distanceSquared(targetLocation) * Archery.DISTANCE_XP_MULTIPLIER));
|
||||||
// TODO: Better way to handle this would be great...
|
|
||||||
double squaredDistance = Math.min(shooterLocation.distanceSquared(targetLocation), 10000);
|
|
||||||
|
|
||||||
applyXpGain((int) (squaredDistance * Archery.DISTANCE_XP_MULTIPLIER));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -249,10 +249,9 @@ public final class CombatUtils {
|
|||||||
archeryManager.trackArrows(target);
|
archeryManager.trackArrows(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
archeryManager.distanceXpBonus(target);
|
archeryManager.distanceXpBonus(target, damager);
|
||||||
|
|
||||||
double forceMultiplier = damager.hasMetadata(mcMMO.bowForceKey) ? damager.getMetadata(mcMMO.bowForceKey).get(0).asDouble() : 1.0;
|
startGainXp(mcMMOPlayer, target, SkillType.ARCHERY, damager.getMetadata(mcMMO.bowForceKey).get(0).asDouble());
|
||||||
startGainXp(mcMMOPlayer, target, SkillType.ARCHERY, forceMultiplier);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user