Omaster
Omaster
JCHJava Community | Help. Code. Learn.
Created by Omaster on 2/13/2025 in #java-help
pass an instance
how can i pass an instance of this class into the main class
public class PetGoal implements Goal<Mob>, Listener {

private final GoalKey<Mob> key = GoalKey.of(Mob.class, new NamespacedKey("firstplugin", "key"));
private final Mob mob;
private final LivingEntity owner;

private LivingEntity target;
private boolean attackPlayers = true;
private boolean attackMobs = true;

private double moveDistance = 3.5D;
private double maxDistance = 16D;
private double maxForgetTargetDistance = 40D;

private boolean active = true;

public PetGoal(Mob mob, LivingEntity owner){
this.mob = mob;
this.owner = owner;

}

public PetGoal(Mob mob, LivingEntity owner, boolean attackMobs, boolean attackPlayers ){
this.mob = mob;
this.owner = owner;
this.attackMobs = attackMobs;
this.attackPlayers = attackPlayers;


}
public class PetGoal implements Goal<Mob>, Listener {

private final GoalKey<Mob> key = GoalKey.of(Mob.class, new NamespacedKey("firstplugin", "key"));
private final Mob mob;
private final LivingEntity owner;

private LivingEntity target;
private boolean attackPlayers = true;
private boolean attackMobs = true;

private double moveDistance = 3.5D;
private double maxDistance = 16D;
private double maxForgetTargetDistance = 40D;

private boolean active = true;

public PetGoal(Mob mob, LivingEntity owner){
this.mob = mob;
this.owner = owner;

}

public PetGoal(Mob mob, LivingEntity owner, boolean attackMobs, boolean attackPlayers ){
this.mob = mob;
this.owner = owner;
this.attackMobs = attackMobs;
this.attackPlayers = attackPlayers;


}
4 replies
JCHJava Community | Help. Code. Learn.
Created by Omaster on 2/4/2025 in #java-help
instance
public class CooldownManager {
private final Map<UUID, Instant> map = new HashMap<>();

// Set cooldown
public void setCooldown(UUID key, Duration duration) {
map.put(key, Instant.now().plus(duration));
}

// Check if cooldown has expired
public boolean hasCooldown(UUID key) {
Instant cooldown = map.get(key);
return cooldown != null && Instant.now().isBefore(cooldown);
}
public class CooldownManager {
private final Map<UUID, Instant> map = new HashMap<>();

// Set cooldown
public void setCooldown(UUID key, Duration duration) {
map.put(key, Instant.now().plus(duration));
}

// Check if cooldown has expired
public boolean hasCooldown(UUID key) {
Instant cooldown = map.get(key);
return cooldown != null && Instant.now().isBefore(cooldown);
}
I was reading on how to make a cooldown when i stumbled across this block of code. I was asking myslef if the last line should be
!Instant.now().isBefore(cooldown);
!Instant.now().isBefore(cooldown);
since without it, we would be checking if the current time is before cooldown (which we dont) so we should neagte that. right?
23 replies
JCHJava Community | Help. Code. Learn.
Created by Omaster on 2/1/2025 in #java-help
Organization
Hey guys, I would like some pointers from an experienced Java programmer. How should I organize my classes, methods, packages, etc?
7 replies