Learn how to join our server and start playing in 60 seconds!
Play Now

review for hack detection code

lfabrax

Pika Lover
Joined
Oct 13, 2023
Messages
76
Points
16
Hello and good day to u all please review this small code i created after studying plugin creation and with help from AI i wanna know how i can improve upon this code and become hopefully a plugin creator in the future

package com.example.antihack;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
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.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerToggleSneakEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

public class OptimizedAntiCheatPlugin extends JavaPlugin implements Listener {

private final Map<UUID, Long> lastHitTimestamps = new HashMap<>();

@Override
public void onEnable() {
getLogger().info("OptimizedAntiCheatPlugin has been enabled!");
Bukkit.getPluginManager().registerEvents(this, this);
}

@Override
public void onDisable() {
getLogger().info("OptimizedAntiCheatPlugin has been disabled!");
}

// Customizable Flying Check
private boolean isFlying(Player player) {
// Implement customizable flying check logic
return player.isFlying();
}

// Customizable Kill Aura Detection
private boolean isKillAura(Player player) {
// Implement customizable Kill Aura detection logic
// Example: Check nearby entities and their behavior
for (Entity entity : player.getNearbyEntities(5, 5, 5)) {
if (entity instanceof LivingEntity && entity != player && !((LivingEntity) entity).hasAI()) {
return true; // Kill Aura detected (entity is not a passive creature)
}
}
return false;
}

// Customizable NoSwing Detection
private boolean isNoSwing(Player player) {
// Implement customizable NoSwing detection logic
// Example: Check if the player is in the swing progress
ItemStack itemInHand = player.getInventory().getItemInMainHand();
return itemInHand != null && itemInHand.getType() != Material.AIR && player.isSwingInProgress();
}

// Customizable FastPlace Detection
private boolean isFastPlacing(Player player) {
// Implement customizable FastPlace detection logic
long currentTime = System.currentTimeMillis();
long lastBlockPlaceTime = lastHitTimestamps.getOrDefault(player.getUniqueId(), 0L);

if (currentTime - lastBlockPlaceTime < 1000) {
// Player placed a block within the last second
return true;
}

lastHitTimestamps.put(player.getUniqueId(), currentTime);
return false;
}

// Placeholder for Customizable Hack Detection
private boolean isCustomHack(Player player) {
// Implement customizable hack detection logic
return false; // Placeholder, replace with actual logic
}

// Handle event for PlayerMove
@EventHandler
public void onPlayerMove(PlayerMoveEvent event) {
Player player = event.getPlayer();

// Flying Check (Customizable Logic)
if (isFlying(player)) {
cancelAndNotify(player, "Flying is not allowed!");
}

// Kill Aura Detection (Customizable Logic)
if (isKillAura(player)) {
cancelAndNotify(player, "Kill Aura detected!");
}
}

// Handle event for EntityDamageByEntity
@EventHandler
public void onEntityDamage(EntityDamageByEntityEvent event) {
if (event.getDamager() instanceof Player) {
Player attacker = (Player) event.getDamager();

// Kill Aura Check (Customizable Logic)
if (isKillAura(attacker)) {
cancelAndNotify(attacker, "Kill Aura hacks are not allowed!");
}
}
}

// Handle event for PlayerInteract
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
Player player = event.getPlayer();

// NoSwing Check (Customizable Logic)
if (isNoSwing(player)) {
cancelAndNotify(player, "NoSwing hacks are not allowed!");
}
}

// Handle event for PlayerToggleSneak
@EventHandler
public void onPlayerToggleSneak(PlayerToggleSneakEvent event) {
Player player = event.getPlayer();

// FastPlace Check (Customizable Logic)
if (isFastPlacing(player)) {
cancelAndNotify(player, "FastPlace hacks are not allowed!");
}
}

private void cancelAndNotify(Player player, String message) {
player.sendMessage(ChatColor.RED + message);
player.setVelocity(player.getLocation().getDirection().multiply(-1)); // Cancel the movement
}
}





as i am not as good in java as i am in python i used ai to further optimize the code to make it run more efficiently and lessen the complexity of it
 
Last edited:
OP
OP
lfabrax

lfabrax

Pika Lover
Joined
Oct 13, 2023
Messages
76
Points
16
with thanks for all the good critics bad and good and if any developer finds this code good or usable please tell me before using it or atleast dm on discord name on discord is lfabrax and i am in pika discord as well if u want to find me
 
OP
OP
lfabrax

lfabrax

Pika Lover
Joined
Oct 13, 2023
Messages
76
Points
16
if possible can a developer help me get the ropes on how to place the logic required for the code to run efficiently on a large scale calculating the different pings of players and lessen the possibility of a crash
 
OP
OP
lfabrax

lfabrax

Pika Lover
Joined
Oct 13, 2023
Messages
76
Points
16
if possible can a developer help me get the ropes on how to place the logic required for the code to run efficiently on a large scale calculating the different pings of players and lessen the possibility of a crash
i forgot as well as to set ban using console with alot of thanks for the feedback
 
OP
OP
lfabrax

lfabrax

Pika Lover
Joined
Oct 13, 2023
Messages
76
Points
16
Spoiler alert, your code (well made by ChatGPT), does nothing.
yeah ik i used chat gpt alot to get the grabs on the basic build and understand a couple of things but i wanna learn more on the logic required and later on build my own plugins i am a data scientist and i program with python and handle data sets mainly and study machine learning but i wanna expand to plugin make and i need tips so i used this basic code made from chatgpt so i can have a sample for critics and ideas that i can use to make my own version then it will take months mostly but i am excited at the prospect
 
OP
OP
lfabrax

lfabrax

Pika Lover
Joined
Oct 13, 2023
Messages
76
Points
16
LOL bro got caught XD
not caught or anything i admited on using AI to optimise code and btw the comments on the code make sure its pasted from AI i am not stupid nor a kid i am only trying to get ideas and posted this code as an example on where it can be improved so that i can create my own later on please if u dont wanna supply critics or ideas on the code dont reply on this thread i am serious on what i wanna make and i dont take kindly to people who make fun of what i want to achieve
 
OP
OP
lfabrax

lfabrax

Pika Lover
Joined
Oct 13, 2023
Messages
76
Points
16
Spoiler alert, your code (well made by ChatGPT), does nothing.
as well i know it does nothing because logic is not supplied to suite any server ( no logic no detection ) i just want to learn how to specify the required logic to work the code and tips on how to improve it
 
OP
OP
lfabrax

lfabrax

Pika Lover
Joined
Oct 13, 2023
Messages
76
Points
16
to anyone that reads:


please either supply tips or ideas or give me links that i can study from or don't reply at all because i want to learn and i wont tolerate any jokes on this thread i wanna learn and become a developer for a server if u wanna have fun at my expense then please never reply here and have respect for hard working people
 
OP
OP
lfabrax

lfabrax

Pika Lover
Joined
Oct 13, 2023
Messages
76
Points
16
I respectfully ask for no fun or callout for being "exposed" on using openAI when i specified above i used AI i apologize if saying "i created this code and optimized using AI" meant that i was trying to hide the fact i used chatgpt i wish to state again that i merely made a code base for people to supply me tips about and give me ideas on where to change edit things on this code to help me create my own to fully functional working anti cheat plugin and hopefully i can improve my skills later on and do something i love doing i am not a child and i tolerate no disrespect

and please remember we all start somewhere this is my start right here dont ruin it for me or others willing to learn and educate ourselves its desrespectful and rude

thanks for reading and for critics
 

ovovo

Rare Pika
Joined
Apr 14, 2022
Messages
83
Points
30
the time you spent yapping could’ve been used to read spigot docs 😊
 
OP
OP
lfabrax

lfabrax

Pika Lover
Joined
Oct 13, 2023
Messages
76
Points
16
the time you spent yapping could’ve been used to read spigot docs 😊
i am and today i spent 4 hours so far between college and home reading and working and improving i just made a base code to actually get some tips and ideas that i can implement and read later on while i am or in college and have a debate on what's the best way to create the plugin please don't reply here again unless its helpful critic its annoying what u are doing i am actually atm reading up on some things and unlike u i am actually learning something secondary i am an approved data scientist and actually have a degree from coursera and udemy on data science i just wanna learn plugins and actually learn not some joke for u to make fun of i have no need for this but i love pika and actually wanna learn and help this server in some way the proof if u think me joking just a small proof
 

Attachments

  • certificate.pdf
    203.2 KB · Views: 7
Top