mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-27 19:24:44 +02:00
Calculate bonus XP based on initial arrow location, rather than final
shooter location.
This commit is contained in:
@ -4,10 +4,12 @@ import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.AdvancedConfig;
|
||||
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;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
@ -37,20 +39,15 @@ public class ArcheryManager extends SkillManager {
|
||||
*
|
||||
* @param target The {@link LivingEntity} damaged by the arrow
|
||||
*/
|
||||
public void distanceXpBonus(LivingEntity target) {
|
||||
Player player = getPlayer();
|
||||
Location shooterLocation = player.getLocation();
|
||||
public void distanceXpBonus(LivingEntity target, Entity damager) {
|
||||
Location firedLocation = Archery.stringToLocation(damager.getMetadata(mcMMO.arrowDistanceKey).get(0).asString());
|
||||
Location targetLocation = target.getLocation();
|
||||
|
||||
if (shooterLocation.getWorld() != targetLocation.getWorld()) {
|
||||
if (firedLocation.getWorld() != targetLocation.getWorld()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Cap distance at 100^2 to prevent teleport exploit.
|
||||
// TODO: Better way to handle this would be great...
|
||||
double squaredDistance = Math.min(shooterLocation.distanceSquared(targetLocation), 10000);
|
||||
|
||||
applyXpGain((int) (squaredDistance * Archery.DISTANCE_XP_MULTIPLIER));
|
||||
applyXpGain((int) (firedLocation.distanceSquared(targetLocation) * Archery.DISTANCE_XP_MULTIPLIER));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user