Generate getters for trait methods

This commit is contained in:
fullwall 2020-10-07 19:16:41 +08:00
parent 8f009d5598
commit 27b0bc107c
28 changed files with 230 additions and 6 deletions

View File

@ -1,11 +1,8 @@
package net.citizensnpcs.commands;
import org.bukkit.command.CommandSender;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.Team;
import net.citizensnpcs.Citizens;
import net.citizensnpcs.Settings.Setting;
import net.citizensnpcs.api.command.Command;
import net.citizensnpcs.api.command.CommandContext;
import net.citizensnpcs.api.command.Requirements;
@ -15,7 +12,6 @@ import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.StringHelper;
import net.citizensnpcs.util.Util;
@Requirements
public class AdminCommands {
@ -31,7 +27,7 @@ public class AdminCommands {
Messaging.send(sender, " <7>-- <c>Author: fullwall");
Messaging.send(sender, " <7>-- <c>Source Code: http://github.com/CitizensDev");
Messaging.send(sender, " <7>-- <c>Website: " + plugin.getDescription().getWebsite());
Messaging.send(sender, " <7>-- <c>Report an issue: http://github.com/CitizensDev/Citizens2/issues");
Messaging.send(sender, " <7>-- <c>Report an issue: http://github.com/CitizensDev/Citizens2/issues");
}
@Command(

View File

@ -34,6 +34,10 @@ public class Age extends Trait implements Toggleable {
Messaging.sendTr(sender, Messages.AGE_TRAIT_DESCRIPTION, npc.getName(), age, locked);
}
public int getAge() {
return age;
}
private boolean isAgeable() {
return ageable != null;
}

View File

@ -41,6 +41,30 @@ public class ArmorStandTrait extends Trait {
super("armorstandtrait");
}
public boolean getGravity() {
return gravity;
}
public boolean getHasArms() {
return hasarms;
}
public boolean getHasBaseplate() {
return hasbaseplate;
}
public boolean isMarker() {
return marker;
}
public boolean isSmall() {
return small;
}
public boolean isVisible() {
return visible;
}
@Override
public void onSpawn() {
if (npc.getEntity() instanceof ArmorStand) {

View File

@ -217,6 +217,10 @@ public class CommandTrait extends Trait {
}
}
public double getCost() {
return cost;
}
public ExecutionMode getExecutionMode() {
return executionMode;
}

View File

@ -19,6 +19,10 @@ public class EndermanTrait extends Trait {
super("endermantrait");
}
public boolean isAngry() {
return angry;
}
@Override
public void run() {
if (npc.getEntity() instanceof Enderman) {

View File

@ -31,6 +31,10 @@ public class FollowTrait extends Trait {
super("followtrait");
}
public Player getFollowingPlayer() {
return player;
}
/**
* Returns whether the trait is actively following a {@link Player}.
*/

View File

@ -9,7 +9,7 @@ import net.citizensnpcs.api.trait.TraitName;
/**
* Persists the {@link GameMode} of a {@link Player} NPC.
*
*
* @see Player#setGameMode(GameMode)
*/
@TraitName("gamemodetrait")
@ -21,6 +21,10 @@ public class GameModeTrait extends Trait {
super("gamemodetrait");
}
public GameMode getGameMode() {
return mode;
}
@Override
public void run() {
if (npc.isSpawned() && npc.getEntity() instanceof Player && mode != null) {

View File

@ -67,6 +67,10 @@ public class HologramTrait extends Trait {
return hologramNPC;
}
public HologramDirection getDirection() {
return direction;
}
private double getEntityHeight() {
return NMS.getHeight(npc.getEntity());
}
@ -75,6 +79,10 @@ public class HologramTrait extends Trait {
return (lineHeight == -1 ? Setting.DEFAULT_NPC_HOLOGRAM_LINE_HEIGHT.asDouble() : lineHeight) * (lineNumber + 1);
}
public double getLineHeight() {
return lineHeight;
}
public List<String> getLines() {
return lines;
}

View File

@ -96,6 +96,26 @@ public class LookClose extends Trait implements Toggleable, CommandConfigurable
}
}
public int getRandomLookDelay() {
return randomLookDelay;
}
public float[] getRandomLookPitchRange() {
return randomPitchRange;
}
public float[] getRandomLookYawRange() {
return randomYawRange;
}
public double getRange() {
return range;
}
public Player getTarget() {
return lookingAt;
}
private boolean hasInvalidTarget() {
if (lookingAt == null)
return true;
@ -119,6 +139,10 @@ public class LookClose extends Trait implements Toggleable, CommandConfigurable
return false;
}
public boolean isRandomLook() {
return enableRandomLook;
}
@Override
public void load(DataKey key) {
range = key.getDouble("range");
@ -225,6 +249,10 @@ public class LookClose extends Trait implements Toggleable, CommandConfigurable
return "LookClose{" + enabled + "}";
}
public boolean useRealisticLooking() {
return realisticLooking;
}
private static final Location CACHE_LOCATION = new Location(null, 0, 0, 0);
private static final Location CACHE_LOCATION2 = new Location(null, 0, 0, 0);
private static final Location NPC_LOCATION = new Location(null, 0, 0, 0);

View File

@ -36,6 +36,10 @@ public class MountTrait extends Trait {
}
}
public UUID getMountedOn() {
return mountedOn;
}
@Override
public void onDespawn() {
Entity e = NMS.getVehicle(npc.getEntity());

View File

@ -21,6 +21,10 @@ public class RabbitType extends Trait {
super("rabbittype");
}
public Rabbit.Type getRabbitType() {
return type;
}
@Override
public void onSpawn() {
rabbit = npc.getEntity() instanceof Rabbit ? (Rabbit) npc.getEntity() : null;

View File

@ -51,4 +51,8 @@ public class Saddle extends Trait implements Toggleable {
public String toString() {
return "Saddle{" + saddle + "}";
}
public boolean useSaddle() {
return saddle;
}
}

View File

@ -93,6 +93,14 @@ public class ScoreboardTrait extends Trait {
Util.sendTeamPacketToOnlinePlayers(team, 2);
}
public ChatColor getColor() {
return color;
}
public Set<String> getTags() {
return tags;
}
public void removeTag(String tag) {
tags.remove(tag);
}

View File

@ -24,6 +24,14 @@ public class SheepTrait extends Trait {
super("sheeptrait");
}
public DyeColor getColor() {
return color;
}
public boolean isSheared() {
return sheared;
}
@EventHandler
private void onPlayerShearEntityEvent(PlayerShearEntityEvent event) {
if (npc != null && npc.equals(CitizensAPI.getNPCRegistry().getNPC(event.getEntity()))) {

View File

@ -28,6 +28,10 @@ public class SlimeSize extends Trait {
Messaging.sendTr(sender, Messages.SIZE_DESCRIPTION, npc.getName(), size);
}
public int getSize() {
return size;
}
@Override
public void onSpawn() {
if (!(npc.getEntity() instanceof Slime)) {

View File

@ -22,6 +22,10 @@ public class VillagerProfession extends Trait {
super("profession");
}
public Profession getProfession() {
return profession;
}
@Override
public void load(DataKey key) throws NPCLoadException {
try {

View File

@ -25,6 +25,10 @@ public class WoolColor extends Trait {
super("woolcolor");
}
public DyeColor getColor() {
return color;
}
@Override
public void load(DataKey key) throws NPCLoadException {
try {

View File

@ -31,11 +31,27 @@ public class BossBarTrait extends Trait {
super("bossbar");
}
public BarColor getColor() {
return color;
}
public List<BarFlag> getFlags() {
return flags;
}
public String getTitle() {
return title;
}
private boolean isBoss(Entity entity) {
return entity.getType() == EntityType.ENDER_DRAGON || entity.getType() == EntityType.WITHER
|| entity.getType() == EntityType.GUARDIAN;
}
public boolean isVisible() {
return visible;
}
@Override
public void run() {
if (!npc.isSpawned() || !isBoss(npc.getEntity()))
@ -67,6 +83,10 @@ public class BossBarTrait extends Trait {
this.flags = Lists.newArrayList(flags);
}
public void setFlags(List<BarFlag> flags) {
this.flags = flags;
}
public void setTitle(String title) {
this.title = title;
}

View File

@ -21,6 +21,22 @@ public class FoxTrait extends Trait {
super("foxtrait");
}
public Fox.Type getType() {
return type;
}
public boolean isCrouching() {
return crouching;
}
public boolean isSitting() {
return sitting;
}
public boolean isSleeping() {
return sleeping;
}
@Override
public void run() {
if (npc.isSpawned() && npc.getEntity() instanceof Fox) {

View File

@ -18,6 +18,14 @@ public class LlamaTrait extends Trait {
super("llamatrait");
}
public Color getColor() {
return color;
}
public int getStrength() {
return strength;
}
@Override
public void run() {
if (npc.isSpawned() && npc.getEntity() instanceof Llama) {

View File

@ -16,6 +16,10 @@ public class MushroomCowTrait extends Trait {
super("mushroomcowtrait");
}
public Variant getVariant() {
return variant;
}
@Override
public void onSpawn() {
setVariant(variant);

View File

@ -20,6 +20,18 @@ public class PandaTrait extends Trait {
super("pandatrait");
}
public Panda.Gene getHiddenGene() {
return hiddenGene;
}
public Panda.Gene getMainGene() {
return mainGene;
}
public boolean isSitting() {
return sitting;
}
@Override
public void run() {
if (npc.isSpawned() && npc.getEntity() instanceof Panda) {
@ -40,6 +52,10 @@ public class PandaTrait extends Trait {
this.mainGene = gene;
}
public void setSitting(boolean sitting) {
this.sitting = sitting;
}
public boolean toggleSitting() {
return sitting = !sitting;
}

View File

@ -16,6 +16,10 @@ public class ParrotTrait extends Trait {
super("parrottrait");
}
public Variant getVariant() {
return variant;
}
@Override
public void run() {
if (npc.isSpawned() && npc.getEntity() instanceof Parrot) {

View File

@ -15,6 +15,10 @@ public class PhantomTrait extends Trait {
super("phantomtrait");
}
public int getSize() {
return size;
}
@Override
public void run() {
if (npc.isSpawned() && npc.getEntity() instanceof Phantom) {

View File

@ -20,6 +20,14 @@ public class ShulkerTrait extends Trait {
super("shulkertrait");
}
public DyeColor getColor() {
return color;
}
public int getPeek() {
return peek;
}
@Override
public void onSpawn() {
setPeek(peek);

View File

@ -15,6 +15,10 @@ public class SnowmanTrait extends Trait {
super("snowmantrait");
}
public boolean isDerp() {
return derp;
}
@Override
public void run() {
if (npc.getEntity() instanceof Snowman) {
@ -22,6 +26,10 @@ public class SnowmanTrait extends Trait {
}
}
public void setDerp(boolean derp) {
this.derp = derp;
}
public boolean toggleDerp() {
return this.derp = !this.derp;
}

View File

@ -21,6 +21,18 @@ public class TropicalFishTrait extends Trait {
super("tropicalfishtrait");
}
public DyeColor getBodyColor() {
return bodyColor;
}
public Pattern getPattern() {
return pattern;
}
public DyeColor getPatternColor() {
return patternColor;
}
@Override
public void run() {
if (npc.isSpawned() && npc.getEntity() instanceof TropicalFish) {

View File

@ -17,6 +17,14 @@ public class VillagerTrait extends Trait {
super("villagertrait");
}
public int getLevel() {
return level;
}
public Villager.Type getType() {
return type;
}
@Override
public void run() {
if (!(npc.getEntity() instanceof Villager))