58 lines
2.3 KiB
Java
58 lines
2.3 KiB
Java
/*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
package fr.neatmonster.nocheatplus.compat.cb3043;
|
|
|
|
import org.bukkit.craftbukkit.v1_7_R3.entity.CraftLivingEntity;
|
|
import org.bukkit.entity.Player;
|
|
|
|
import fr.neatmonster.nocheatplus.compat.AttribUtil;
|
|
import fr.neatmonster.nocheatplus.components.modifier.IAttributeAccess;
|
|
import fr.neatmonster.nocheatplus.utilities.ReflectionUtil;
|
|
import net.minecraft.server.v1_7_R3.AttributeInstance;
|
|
import net.minecraft.server.v1_7_R3.AttributeModifier;
|
|
import net.minecraft.server.v1_7_R3.GenericAttributes;
|
|
|
|
public class AttributeAccess implements IAttributeAccess {
|
|
|
|
public AttributeAccess() {
|
|
if (ReflectionUtil.getClass("net.minecraft.server.v1_7_R3.AttributeInstance") == null) {
|
|
throw new RuntimeException("Service not available.");
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public double getSpeedAttributeMultiplier(Player player) {
|
|
final AttributeInstance attr = ((CraftLivingEntity) player).getHandle().getAttributeInstance(GenericAttributes.d);
|
|
final double val = attr.getValue() / attr.b();
|
|
final AttributeModifier mod = attr.a(AttribUtil.ID_SPRINT_BOOST);
|
|
if (mod == null) {
|
|
return val;
|
|
} else {
|
|
return val / AttribUtil.getMultiplier(mod.c(), mod.d());
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public double getSprintAttributeMultiplier(Player player) {
|
|
final AttributeModifier mod = ((CraftLivingEntity) player).getHandle().getAttributeInstance(GenericAttributes.d).a(AttribUtil.ID_SPRINT_BOOST);
|
|
if (mod == null) {
|
|
return 1.0;
|
|
} else {
|
|
return AttribUtil.getMultiplier(mod.c(), mod.d());
|
|
}
|
|
}
|
|
|
|
}
|