Skip to content

Commit

Permalink
Merge branch 'master' of github.com:CitizensDev/Citizens2
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Mar 1, 2020
2 parents 95ab688 + ad69b48 commit 87c2a88
Show file tree
Hide file tree
Showing 22 changed files with 229 additions and 41 deletions.
45 changes: 16 additions & 29 deletions main/src/main/java/net/citizensnpcs/Settings.java
Expand Up @@ -67,15 +67,12 @@ public enum Setting {
CHAT_MAX_NUMBER_OF_TARGETS("npc.chat.options.max-number-of-targets-to-show", 2),
CHAT_MULTIPLE_TARGETS_FORMAT("npc.chat.options.multiple-targets-format",
"<target>|, <target>| & <target>| & others"),
CHAT_RANGE("npc.chat.options.range", 5),
CHECK_MINECRAFT_VERSION("advanced.check-minecraft-version", true),
DEBUG_FILE("general.debug-file", ""),
DEBUG_MODE("general.debug-mode", false),
CHAT_RANGE("npc.chat.options.range", 5), CHECK_MINECRAFT_VERSION("advanced.check-minecraft-version", true),
DEBUG_FILE("general.debug-file", ""), DEBUG_MODE("general.debug-mode", false),
DEBUG_PATHFINDING("general.debug-pathfinding", false),
DEFAULT_DISTANCE_MARGIN("npc.pathfinding.default-distance-margin", 2),
DEFAULT_LOOK_CLOSE("npc.default.look-close.enabled", false),
DEFAULT_LOOK_CLOSE_RANGE("npc.default.look-close.range", 5),
DEFAULT_NPC_LIMIT("npc.limits.default-limit", 10),
DEFAULT_LOOK_CLOSE_RANGE("npc.default.look-close.range", 5), DEFAULT_NPC_LIMIT("npc.limits.default-limit", 10),
DEFAULT_PATH_DISTANCE_MARGIN("npc.pathfinding.default-path-distance-margin", 1),
DEFAULT_PATHFINDER_UPDATE_PATH_RATE("npc.pathfinding.update-path-rate", 20),
DEFAULT_PATHFINDING_RANGE("npc.default.pathfinding.range", 25F),
Expand All @@ -95,43 +92,33 @@ public void loadFromKey(DataKey root) {
value = list;
}
},
DISABLE_TABLIST("npc.tablist.disable", true),
ERROR_COLOUR("general.color-scheme.message-error", "<c>"),
DISABLE_TABLIST("npc.tablist.disable", true), ERROR_COLOUR("general.color-scheme.message-error", "<c>"),
HIGHLIGHT_COLOUR("general.color-scheme.message-highlight", "<e>"),
KEEP_CHUNKS_LOADED("npc.chunks.always-keep-loaded", false),
LOCALE("general.translation.locale", ""),
KEEP_CHUNKS_LOADED("npc.chunks.always-keep-loaded", false), LOCALE("general.translation.locale", ""),
MAX_CONTROLLABLE_GROUND_SPEED("npc.controllable.max-ground-speed", 0.5),
MAX_NPC_LIMIT_CHECKS("npc.limits.max-permission-checks", 100),
MAX_NPC_SKIN_RETRIES("npc.skins.max-retries", -1),
MAX_PACKET_ENTRIES("npc.limits.max-packet-entries", 15),
MAX_SPEED("npc.limits.max-speed", 100),
MAX_TEXT_RANGE("npc.chat.options.max-text-range", 500),
MAX_NPC_SKIN_RETRIES("npc.skins.max-retries", -1), MAX_PACKET_ENTRIES("npc.limits.max-packet-entries", 15),
MAX_SPEED("npc.limits.max-speed", 100), MAX_TEXT_RANGE("npc.chat.options.max-text-range", 500),
MAXIMUM_ASTAR_ITERATIONS("npc.pathfinding.maximum-new-pathfinder-iterations", 50000),
MESSAGE_COLOUR("general.color-scheme.message", "<a>"),
NEW_PATHFINDER_OPENS_DOORS("npc.pathfinding.new-finder-open-doors", false),
NPC_ATTACK_DISTANCE("npc.pathfinding.attack-range", 1.75 * 1.75),
NPC_COST("economy.npc.cost", 100D),
NPC_ATTACK_DISTANCE("npc.pathfinding.attack-range", 1.75 * 1.75), NPC_COST("economy.npc.cost", 100D),
NPC_SKIN_RETRY_DELAY("npc.skins.retry-delay", 120),
NPC_SKIN_ROTATION_UPDATE_DEGREES("npc.skins.rotation-update-degrees", 90f),
NPC_SKIN_USE_LATEST("npc.skins.use-latest-by-default", false),
NPC_SKIN_VIEW_DISTANCE("npc.skins.view-distance", 100D),
PACKET_UPDATE_DELAY("npc.packets.update-delay", 30),
NPC_SKIN_VIEW_DISTANCE("npc.skins.view-distance", 100D), PACKET_UPDATE_DELAY("npc.packets.update-delay", 30),
QUICK_SELECT("npc.selection.quick-select", false),
REMOVE_PLAYERS_FROM_PLAYER_LIST("npc.player.remove-from-list", true),
SAVE_TASK_DELAY("storage.save-task.delay", 20 * 60 * 60),
SELECTION_ITEM("npc.selection.item", "stick"),
SAVE_TASK_DELAY("storage.save-task.delay", 20 * 60 * 60), SELECTION_ITEM("npc.selection.item", "stick"),
SELECTION_MESSAGE("npc.selection.message", "<b>You selected <a><npc><b>!"),
SERVER_OWNS_NPCS("npc.server-ownership", false),
STORAGE_FILE("storage.file", "saves.yml"),
STORAGE_TYPE("storage.type", "yaml"),
SUBPLUGIN_FOLDER("subplugins.folder", "plugins"),
SERVER_OWNS_NPCS("npc.server-ownership", false), STORAGE_FILE("storage.file", "saves.yml"),
STORAGE_TYPE("storage.type", "yaml"), SUBPLUGIN_FOLDER("subplugins.folder", "plugins"),
TALK_CLOSE_MAXIMUM_COOLDOWN("npc.text.max-talk-cooldown", 5),
TALK_CLOSE_MINIMUM_COOLDOWN("npc.text.min-talk-cooldown", 10),
TALK_ITEM("npc.text.talk-item", "book"),
TELEPORT_DELAY("npc.teleport-delay", -1),
USE_BOAT_CONTROLS("npc.controllable.use-boat-controls", true),
TALK_CLOSE_MINIMUM_COOLDOWN("npc.text.min-talk-cooldown", 10), TALK_ITEM("npc.text.talk-item", "book"),
TELEPORT_DELAY("npc.teleport-delay", -1), USE_BOAT_CONTROLS("npc.controllable.use-boat-controls", true),
USE_NEW_PATHFINDER("npc.pathfinding.use-new-finder", false),
USE_SCOREBOARD_TEAMS("npc.player-scoreboard-teams.enable", true);
USE_SCOREBOARD_TEAMS("npc.player-scoreboard-teams.enable", true),
DISABLE_LOOKCLOSE_WHILE_NAVIGATING("npc.default.look-close.disable-while-navigating", true);

protected String path;
protected Object value;
Expand Down
23 changes: 16 additions & 7 deletions main/src/main/java/net/citizensnpcs/trait/LookClose.java
Expand Up @@ -52,8 +52,8 @@ public LookClose() {
}

/**
* Returns whether the target can be seen. Will use realistic line of sight if {@link #setRealisticLooking(boolean)}
* is true.
* Returns whether the target can be seen. Will use realistic line of sight if
* {@link #setRealisticLooking(boolean)} is true.
*/
public boolean canSeeTarget() {
return realisticLooking && npc.getEntity() instanceof LivingEntity
Expand Down Expand Up @@ -107,8 +107,9 @@ private boolean hasInvalidTarget() {

private boolean isPluginVanished(Player player) {
for (MetadataValue meta : player.getMetadata("vanished")) {
if (meta.asBoolean())
if (meta.asBoolean()) {
return true;
}
}
return false;
}
Expand Down Expand Up @@ -139,8 +140,12 @@ private void randomLook() {

@Override
public void run() {
if (!enabled || !npc.isSpawned() || npc.getNavigator().isNavigating())
if (!enabled || !npc.isSpawned()) {
return;
}
if (npc.getNavigator().isNavigating() && Setting.DISABLE_LOOKCLOSE_WHILE_NAVIGATING.asBoolean()) {
return;
}
// TODO: remove in a later version, defaults weren't saving properly
if (randomPitchRange == null || randomPitchRange.length != 2) {
randomPitchRange = new float[] { -10, 0 };
Expand All @@ -152,7 +157,9 @@ public void run() {
if (hasInvalidTarget()) {
findNewTarget();
}
if (lookingAt == null && enableRandomLook && t <= 0) {
if (npc.getNavigator().isNavigating()) {
npc.getNavigator().setPaused(lookingAt != null);
} else if (lookingAt == null && enableRandomLook && t <= 0) {
randomLook();
t = randomLookDelay;
}
Expand All @@ -172,7 +179,8 @@ public void save(DataKey key) {
}

/**
* 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.
*/
public void setRandomLook(boolean enableRandomLook) {
this.enableRandomLook = enableRandomLook;
Expand Down Expand Up @@ -201,7 +209,8 @@ public void setRange(int range) {
}

/**
* Enables/disables realistic looking (using line of sight checks). More computationally expensive.
* Enables/disables realistic looking (using line of sight checks). More
* computationally expensive.
*/
public void setRealisticLooking(boolean realistic) {
this.realisticLooking = realistic;
Expand Down
@@ -0,0 +1,31 @@
package net.citizensnpcs.trait.versioned;

import org.bukkit.DyeColor;
import org.bukkit.entity.Shulker;
import org.bukkit.entity.Snowman;

import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.trait.TraitName;
import net.citizensnpcs.util.NMS;

@TraitName("snowmantrait")
public class SnowmanTrait extends Trait {
@Persist("derp")
private boolean derp;

public SnowmanTrait() {
super("snowmantrait");
}

@Override
public void run() {
if (npc.getEntity() instanceof Snowman) {
((Snowman) npc.getEntity()).setDerp(derp);
}
}

public boolean toggleDerp() {
return this.derp = !this.derp;
}
}
2 changes: 2 additions & 0 deletions main/src/main/java/net/citizensnpcs/util/Messages.java
Expand Up @@ -370,4 +370,6 @@ public class Messages {
public static final String ZOMBIE_VILLAGER_PROFESSION_SET = "citizens.commands.npc.zombiemod.villager-profession-set";
public static final String ZOMBIE_VILLAGER_SET = "citizens.commands.npc.zombiemod.villager-set";
public static final String ZOMBIE_VILLAGER_UNSET = "citizens.commands.npc.zombiemod.villager-unset";
public static final String SNOWMAN_DERP_SET = "citizens.commands.npc.snowman.derp-set";
public static final String SNOWMAN_DERP_STOPPED = "citizens.commands.npc.snowman.derp-stopped";
}
2 changes: 2 additions & 0 deletions main/src/main/resources/messages_en.properties
Expand Up @@ -183,6 +183,8 @@ citizens.commands.npc.sound.set=[[{0}]]''s sounds are now: ambient - [[{1}]] hur
citizens.commands.npc.sound.info=[[{0}]]''s sounds are: ambient - [[{1}]] hurt - [[{2}]] and death - [[{3}]].<br><br>Valid sounds are {4}.
citizens.commands.npc.skeletontype.set={0}''s skeleton type set to [[{1}]].
citizens.commands.npc.skeletontype.invalid-type=Invalid skeleton type. Try one of the following: [[{0}]].
citizens.commands.npc.snowman.derp-set=[[{0}]] is now in derp mode.
citizens.commands.npc.snowman.derp-stopped=[[{0}]] is no longer in derp mode.
citizens.commands.npc.spawn.already-spawned=[[{0}]] is already spawned at another location. Use ''/npc tphere'' to teleport the NPC to your location.
citizens.commands.npc.spawn.missing-npc-id=No NPC with the ID {0} exists.
citizens.commands.npc.spawn.no-location=No stored location available - command must be used ingame.
Expand Down
Expand Up @@ -21,6 +21,7 @@
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.trait.versioned.BossBarTrait;
import net.citizensnpcs.trait.versioned.ShulkerTrait;
import net.citizensnpcs.trait.versioned.SnowmanTrait;
import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.Util;

Expand Down Expand Up @@ -90,4 +91,27 @@ public void shulker(CommandContext args, CommandSender sender, NPC npc) throws C
throw new CommandUsageException();
}
}

@Command(
aliases = { "npc" },
usage = "snowman (-d[erp])",
desc = "Sets snowman modifiers.",
modifiers = { "snowman" },
min = 1,
max = 1,
flags = "d",
permission = "citizens.npc.snowman")
@Requirements(selected = true, ownership = true, types = { EntityType.SNOWMAN })
public void snowman(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
SnowmanTrait trait = npc.getTrait(SnowmanTrait.class);
boolean hasArg = false;
if (args.hasFlag('d')) {
boolean isDerp = trait.toggleDerp();
Messaging.sendTr(sender, isDerp ? Messages.SNOWMAN_DERP_SET : Messages.SNOWMAN_DERP_STOPPED, npc.getName());
hasArg = true;
}
if (!hasArg) {
throw new CommandUsageException();
}
}
}
Expand Up @@ -145,6 +145,7 @@
import net.citizensnpcs.npc.skin.SkinnableEntity;
import net.citizensnpcs.trait.versioned.BossBarTrait;
import net.citizensnpcs.trait.versioned.ShulkerTrait;
import net.citizensnpcs.trait.versioned.SnowmanTrait;
import net.citizensnpcs.util.BoundingBox;
import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.NMS;
Expand Down Expand Up @@ -542,6 +543,7 @@ public boolean isValid(org.bukkit.entity.Entity entity) {
public void load(CommandManager commands) {
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(BossBarTrait.class));
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(ShulkerTrait.class));
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(SnowmanTrait.class));
commands.register(Commands.class);
}

Expand Down
Expand Up @@ -21,7 +21,7 @@ public PlayerControllerLook(EntityHumanNPC entityinsentient) {
public void a() {
if (!NMSImpl.isNavigationFinished(this.a.getNavigation()))
return;
this.a.pitch = 0.0F;
// this.a.pitch = 0.0F;
if (this.d) {
this.d = false;

Expand Down
Expand Up @@ -23,6 +23,7 @@
import net.citizensnpcs.trait.versioned.BossBarTrait;
import net.citizensnpcs.trait.versioned.LlamaTrait;
import net.citizensnpcs.trait.versioned.ShulkerTrait;
import net.citizensnpcs.trait.versioned.SnowmanTrait;
import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.Util;

Expand Down Expand Up @@ -122,4 +123,27 @@ public void shulker(CommandContext args, CommandSender sender, NPC npc) throws C
throw new CommandUsageException();
}
}

@Command(
aliases = { "npc" },
usage = "snowman (-d[erp])",
desc = "Sets snowman modifiers.",
modifiers = { "snowman" },
min = 1,
max = 1,
flags = "d",
permission = "citizens.npc.snowman")
@Requirements(selected = true, ownership = true, types = { EntityType.SNOWMAN })
public void snowman(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
SnowmanTrait trait = npc.getTrait(SnowmanTrait.class);
boolean hasArg = false;
if (args.hasFlag('d')) {
boolean isDerp = trait.toggleDerp();
Messaging.sendTr(sender, isDerp ? Messages.SNOWMAN_DERP_SET : Messages.SNOWMAN_DERP_STOPPED, npc.getName());
hasArg = true;
}
if (!hasArg) {
throw new CommandUsageException();
}
}
}
Expand Up @@ -162,6 +162,7 @@
import net.citizensnpcs.trait.versioned.BossBarTrait;
import net.citizensnpcs.trait.versioned.LlamaTrait;
import net.citizensnpcs.trait.versioned.ShulkerTrait;
import net.citizensnpcs.trait.versioned.SnowmanTrait;
import net.citizensnpcs.util.BoundingBox;
import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.NMS;
Expand Down Expand Up @@ -583,6 +584,7 @@ public void load(CommandManager manager) {
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(BossBarTrait.class));
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(ShulkerTrait.class));
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(LlamaTrait.class));
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(SnowmanTrait.class));
manager.register(Commands.class);
}

Expand Down
Expand Up @@ -21,7 +21,7 @@ public PlayerControllerLook(EntityHumanNPC entityinsentient) {
public void a() {
if (!NMSImpl.isNavigationFinished(this.a.getNavigation()))
return;
this.a.pitch = 0.0F;
// this.a.pitch = 0.0F;
if (this.d) {
this.d = false;

Expand Down
Expand Up @@ -25,6 +25,7 @@
import net.citizensnpcs.trait.versioned.LlamaTrait;
import net.citizensnpcs.trait.versioned.ParrotTrait;
import net.citizensnpcs.trait.versioned.ShulkerTrait;
import net.citizensnpcs.trait.versioned.SnowmanTrait;
import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.Util;

Expand Down Expand Up @@ -151,4 +152,27 @@ public void shulker(CommandContext args, CommandSender sender, NPC npc) throws C
throw new CommandUsageException();
}
}

@Command(
aliases = { "npc" },
usage = "snowman (-d[erp])",
desc = "Sets snowman modifiers.",
modifiers = { "snowman" },
min = 1,
max = 1,
flags = "d",
permission = "citizens.npc.snowman")
@Requirements(selected = true, ownership = true, types = { EntityType.SNOWMAN })
public void snowman(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
SnowmanTrait trait = npc.getTrait(SnowmanTrait.class);
boolean hasArg = false;
if (args.hasFlag('d')) {
boolean isDerp = trait.toggleDerp();
Messaging.sendTr(sender, isDerp ? Messages.SNOWMAN_DERP_SET : Messages.SNOWMAN_DERP_STOPPED, npc.getName());
hasArg = true;
}
if (!hasArg) {
throw new CommandUsageException();
}
}
}
Expand Up @@ -164,6 +164,7 @@
import net.citizensnpcs.trait.versioned.LlamaTrait;
import net.citizensnpcs.trait.versioned.ParrotTrait;
import net.citizensnpcs.trait.versioned.ShulkerTrait;
import net.citizensnpcs.trait.versioned.SnowmanTrait;
import net.citizensnpcs.util.BoundingBox;
import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.NMS;
Expand Down Expand Up @@ -587,6 +588,7 @@ public void load(CommandManager manager) {
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(ParrotTrait.class));
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(BossBarTrait.class));
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(ShulkerTrait.class));
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(SnowmanTrait.class));
manager.register(Commands.class);
}

Expand Down
Expand Up @@ -21,7 +21,7 @@ public PlayerControllerLook(EntityHumanNPC entityinsentient) {
public void a() {
if (!NMSImpl.isNavigationFinished(this.a.getNavigation()))
return;
this.a.pitch = 0.0F;
// this.a.pitch = 0.0F;
if (this.d) {
this.d = false;

Expand Down

0 comments on commit 87c2a88

Please sign in to comment.