NoCheatPlus/NCPCompatNonFree/NCPCompatSpigotCB1_8_R2/src/main/java/fr/neatmonster/nocheatplus/compat/spigotcb1_8_R2/AttributeAccess.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.spigotcb1_8_R2;
import org.bukkit.craftbukkit.v1_8_R2.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_8_R2.AttributeInstance;
import net.minecraft.server.v1_8_R2.AttributeModifier;
import net.minecraft.server.v1_8_R2.GenericAttributes;
public class AttributeAccess implements IAttributeAccess {
public AttributeAccess() {
if (ReflectionUtil.getClass("net.minecraft.server.v1_8_R2.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());
}
}
}