Fixed killaura, added auto-updater

This commit is contained in:
Rammelkast committed 2016-05-30 19:45:02 +02:00
1 parent cf60474a6d
commit 671329369e
5 files changed
+45 -10

No files matched your search

@@ -18,12 +18,14 @@
package net.gravitydevelopment.anticheat;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import com.comphenix.protocol.ProtocolLibrary;
@@ -38,9 +40,9 @@ import net.gravitydevelopment.anticheat.event.InventoryListener;
import net.gravitydevelopment.anticheat.event.PlayerListener;
import net.gravitydevelopment.anticheat.event.VehicleListener;
import net.gravitydevelopment.anticheat.manage.AntiCheatManager;
import net.gravitydevelopment.anticheat.manage.PacketManager;
import net.gravitydevelopment.anticheat.util.User;
import net.gravitydevelopment.anticheat.util.VersionUtil;
import net.gravitydevelopment.updater.Updater;
public class AntiCheat extends JavaPlugin {
@@ -52,7 +54,7 @@ public class AntiCheat extends JavaPlugin {
private static Configuration config;
private static boolean verbose;
private static boolean developer;
private static final int PROJECT_ID = 38723;
private static final int PROJECT_ID = 100229;
private static ProtocolManager protocolManager;
private static boolean protocolLib = false;
private static Long loadTime;
@@ -71,6 +73,7 @@ public class AntiCheat extends JavaPlugin {
setupConfig();
setupEvents();
setupCommands();
setupUpdater();
setupProtocol();
// Enterprise must come before levels
setupEnterprise();
@@ -98,7 +101,26 @@ public class AntiCheat extends JavaPlugin {
KillAuraCheck.listenPackets();
}
@Override
private void setupUpdater() {
if (config.getConfig().autoUpdate.getValue()) {
final File file = this.getFile();
final Plugin plugin = this;
getServer().getScheduler().runTaskAsynchronously(this, new Runnable() {
@Override
public void run() {
verboseLog("Checking for a new update...");
Updater updater = new Updater(plugin, PROJECT_ID, file, Updater.UpdateType.DEFAULT, false);
update = updater.getResult() == Updater.UpdateResult.SUCCESS;
verboseLog("Update available: " + update);
if (update) {
updateDetails = updater.getLatestName() + " for " + updater.getLatestGameVersion();
}
}
});
}
}
@Override
public void onDisable() {
verboseLog("Saving user levels...");
config.getLevels().saveLevelsFromUsers(getManager().getUserManager().getUsers());
@@ -4,6 +4,7 @@ import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerMoveEvent;
@@ -40,7 +41,7 @@ public class KillAuraCheck {
@Override
public void onPacketReceiving(PacketEvent e) {
Player p = e.getPlayer();
if (!CHECKER_NPCS.containsKey(p.getUniqueId()))
if (!CHECKER_NPCS.containsKey(p.getUniqueId()) || AntiCheat.getManager().getCheckManager().isOpExempt(p) || AntiCheat.getManager().getCheckManager().isExempt(p, CheckType.KILLAURA))
return;
int entityId = ((Integer)e.getPacket().getIntegers().read(0));
boolean isBot = CHECKER_NPCS.get(p.getUniqueId()).onHit(entityId);
@@ -60,6 +61,8 @@ public class KillAuraCheck {
}
public static void doDamageEvent(EntityDamageByEntityEvent e, Player p) {
if (AntiCheat.getManager().getCheckManager().isOpExempt(p) || AntiCheat.getManager().getCheckManager().isExempt(p, CheckType.KILLAURA))
return;
if (VersionUtil.getVersion().equals("v1_8_R3")) { // TODO 1.9 support
if (!CHECKER_NPCS.containsKey(p.getUniqueId())) { // Enable killaura check after player damaged other player, this is more efficient
CHECKER_NPCS.put(p.getUniqueId(), new CheckerNPCS(p));
@@ -69,6 +72,10 @@ public class KillAuraCheck {
public static void doMove(PlayerMoveEvent e) {
if (CHECKER_NPCS.containsKey(e.getPlayer().getUniqueId())) {
if (AntiCheat.getManager().getCheckManager().isOpExempt(e.getPlayer()) || AntiCheat.getManager().getCheckManager().isExempt(e.getPlayer(), CheckType.KILLAURA)) {
cleanPlayer(e.getPlayer());
return;
}
CHECKER_NPCS.get(e.getPlayer().getUniqueId()).doMove(e);
}
}
@@ -43,7 +43,7 @@ public class CommandBase {
public static final ChatColor GOLD = ChatColor.GOLD;
public static final ChatColor AQUA = ChatColor.AQUA;
public static final Server SERVER = Bukkit.getServer();
public static final String PERMISSIONS_ERROR = RED + "Insufficient Permissions.";
public static final String PERMISSIONS_ERROR = RED + "You don't have the permissions to use this command.";
public static final String MENU_END = "-----------------------------------------------------";
private final String name;
@@ -73,9 +73,9 @@ public class CommandBase {
}
public void sendHelp(CommandSender cs) {
cs.sendMessage(GREEN + "== " + GRAY + getName() + GREEN + " ==");
cs.sendMessage(GREEN + "Usage: " + GRAY + (cs instanceof Player ? "/" : "") + getUsage());
cs.sendMessage(GREEN + "Permission: " + GRAY + getPermission().toString());
cs.sendMessage(RED + "== " + GRAY + getName() + RED + " ==");
cs.sendMessage(RED + "Usage: " + GRAY + (cs instanceof Player ? "/" : "") + getUsage());
cs.sendMessage(RED + "Permission: " + GRAY + getPermission().toString());
for (String string : getHelp()) {
cs.sendMessage(string);
}
@@ -48,7 +48,7 @@ public class CommandUpdate extends CommandBase {
}
} else {
cs.sendMessage(GRAY + "Your config settings have disabled update checking.");
cs.sendMessage(GRAY + "Please enable this setting or visit http://dev.bukkit.org/bukkit-plugins/anticheat/");
cs.sendMessage(GRAY + "Please enable this setting or visit http://dev.bukkit.org/bukkit-plugins/anticheatreloaded/");
}
}
}