89 lines
2.3 KiB
Java
89 lines
2.3 KiB
Java
/*
|
|
* Copyright (c) 2017 univento.eu - All rights reserved
|
|
* You are not allowed to use, distribute or modify this code
|
|
*/
|
|
|
|
package eu.univento.core.antihack.modules;
|
|
|
|
import eu.univento.core.api.player.CustomPlayer;
|
|
import org.bukkit.entity.Arrow;
|
|
import org.bukkit.entity.Player;
|
|
import org.bukkit.event.EventHandler;
|
|
import org.bukkit.event.Listener;
|
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
|
import org.bukkit.event.entity.ProjectileLaunchEvent;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import static jdk.nashorn.internal.objects.NativeMath.log;
|
|
|
|
/**
|
|
* @author joethei
|
|
* @version 0.1
|
|
*/
|
|
|
|
public class BowAimbot implements Listener {
|
|
|
|
private HashMap<CustomPlayer, Integer> totalShots = new HashMap<>();
|
|
private HashMap<CustomPlayer, Integer> totalHits = new HashMap<>();
|
|
|
|
|
|
|
|
private int getTotalShots(CustomPlayer p){
|
|
if(!(totalShots.containsKey(p))){
|
|
totalShots.put(p, 0);
|
|
}
|
|
|
|
return totalShots.get(p);
|
|
}
|
|
|
|
private int getTotalHits(CustomPlayer p){
|
|
if(!(totalHits.containsKey(p))){
|
|
totalHits.put(p, 0);
|
|
}
|
|
|
|
return totalHits.get(p);
|
|
}
|
|
|
|
private int getHitRatio(CustomPlayer p){
|
|
int shots = getTotalShots(p);
|
|
int hits = getTotalHits(p);
|
|
|
|
return (hits / shots) * 100;
|
|
}
|
|
|
|
@EventHandler
|
|
public void onEntityDamageByEntity(EntityDamageByEntityEvent event){
|
|
if(event.getDamager() instanceof Arrow){
|
|
Arrow arrow = (Arrow) event.getDamager();
|
|
|
|
if(arrow.getShooter() instanceof Player){
|
|
CustomPlayer p = CustomPlayer.getPlayer((Player) arrow.getShooter());
|
|
int hits = getTotalHits(p) + 1;
|
|
|
|
totalHits.put(p, hits);
|
|
|
|
if(hits >= 10){
|
|
int ratio = getHitRatio(p);
|
|
|
|
if(ratio >= 80){
|
|
log(p, ratio + "% hits");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@EventHandler
|
|
public void onProjectileLaunch(ProjectileLaunchEvent event){
|
|
if(event.getEntity() instanceof Arrow){
|
|
Arrow arrow = (Arrow) event.getEntity();
|
|
|
|
if(arrow.getShooter() instanceof Player){
|
|
CustomPlayer p = CustomPlayer.getPlayer((Player) arrow.getShooter());
|
|
|
|
totalShots.put(p, getTotalShots(p) + 1);
|
|
}
|
|
}
|
|
}
|
|
} |