Add lookclose setting

This commit is contained in:
fullwall 2021-02-04 09:51:02 +08:00
parent c28cf09ef3
commit 8039f6e9d3

View File

@ -15,6 +15,8 @@ import net.citizensnpcs.Settings.Setting;
import net.citizensnpcs.api.CitizensAPI; import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.command.CommandConfigurable; import net.citizensnpcs.api.command.CommandConfigurable;
import net.citizensnpcs.api.command.CommandContext; import net.citizensnpcs.api.command.CommandContext;
import net.citizensnpcs.api.command.CommandMessages;
import net.citizensnpcs.api.command.exception.CommandException;
import net.citizensnpcs.api.event.NPCLookCloseChangeTargetEvent; import net.citizensnpcs.api.event.NPCLookCloseChangeTargetEvent;
import net.citizensnpcs.api.persistence.Persist; import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.api.trait.Trait; import net.citizensnpcs.api.trait.Trait;
@ -29,6 +31,8 @@ import net.citizensnpcs.util.Util;
*/ */
@TraitName("lookclose") @TraitName("lookclose")
public class LookClose extends Trait implements Toggleable, CommandConfigurable { public class LookClose extends Trait implements Toggleable, CommandConfigurable {
@Persist("disablewhilenavigating")
private boolean disableWhileNavigating = Setting.DISABLE_LOOKCLOSE_WHILE_NAVIGATING.asBoolean();
@Persist("enabled") @Persist("enabled")
private boolean enabled = Setting.DEFAULT_LOOK_CLOSE.asBoolean(); private boolean enabled = Setting.DEFAULT_LOOK_CLOSE.asBoolean();
@Persist @Persist
@ -64,11 +68,19 @@ public class LookClose extends Trait implements Toggleable, CommandConfigurable
} }
@Override @Override
public void configure(CommandContext args) { public void configure(CommandContext args) throws CommandException {
try {
range = args.getFlagDouble("range", args.getFlagDouble("r", range)); range = args.getFlagDouble("range", args.getFlagDouble("r", range));
} catch (NumberFormatException ex) {
throw new CommandException(CommandMessages.INVALID_NUMBER);
}
realisticLooking = args.hasFlag('r'); realisticLooking = args.hasFlag('r');
} }
public boolean disableWhileNavigating() {
return disableWhileNavigating;
}
/** /**
* Finds a new look-close target * Finds a new look-close target
*/ */
@ -183,7 +195,7 @@ public class LookClose extends Trait implements Toggleable, CommandConfigurable
if (!enabled || !npc.isSpawned()) { if (!enabled || !npc.isSpawned()) {
return; return;
} }
if (npc.getNavigator().isNavigating() && Setting.DISABLE_LOOKCLOSE_WHILE_NAVIGATING.asBoolean()) { if (npc.getNavigator().isNavigating() && disableWhileNavigating()) {
return; return;
} }
npc.getEntity().getLocation(NPC_LOCATION); npc.getEntity().getLocation(NPC_LOCATION);
@ -211,6 +223,10 @@ public class LookClose extends Trait implements Toggleable, CommandConfigurable
key.setDouble("range", range); key.setDouble("range", range);
} }
public void setDisableWhileNavigating(boolean set) {
disableWhileNavigating = set;
}
/** /**
* Enables random looking - will look at a random {@link Location} every so often if enabled. * Enables random looking - will look at a random {@link Location} every so often if enabled.
*/ */