Skip to content

Commit

Permalink
Merge pull request #13 from juliarn/development
Browse files Browse the repository at this point in the history
Update 1.1-RELEASE
  • Loading branch information
juliarn authored Apr 30, 2020
2 parents 9b90afd + 62ad478 commit 4d97d1c
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 32 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Maven
<dependency>
<groupId>com.github.juliarn</groupId>
<artifactId>npc-lib</artifactId>
<version>1.0-RELEASE</version>
<version>1.1-RELEASE</version>
</dependency>
```

Expand All @@ -29,7 +29,7 @@ maven {
url 'https://jitpack.io'
}
compile group: 'com.github.juliarn', name: 'npc-lib', version: '1.0-RELEASE'
compile group: 'com.github.juliarn', name: 'npc-lib', version: '1.1-RELEASE'
```

Add ProtocolLib as dependency to your plugin.yml. It could look like this:
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.github.juliarn</groupId>
<artifactId>npc-lib</artifactId>
<version>1.0-RELEASE</version>
<version>1.1-RELEASE</version>
<packaging>jar</packaging>

<properties>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/github/juliarn/npc/NPC.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class NPC {

private boolean imitatePlayer;

private SpawnCustomizer spawnCustomizer;
private final SpawnCustomizer spawnCustomizer;

private NPC(Set<ProfileProperty> profileProperties, WrappedGameProfile gameProfile, Location location, boolean lookAtPlayer, boolean imitatePlayer, SpawnCustomizer spawnCustomizer) {
this.gameProfile = gameProfile;
Expand Down Expand Up @@ -174,7 +174,7 @@ public static class Builder {

private Set<ProfileProperty> profileProperties;

private String name;
private final String name;

private UUID textureUUID;

Expand Down
20 changes: 10 additions & 10 deletions src/main/java/com/github/juliarn/npc/NPCPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@

public class NPCPool implements Listener {

private JavaPlugin javaPlugin;
private final JavaPlugin javaPlugin;

private int spawnDistance;
private final double spawnDistance;

private int actionDistance;
private final double actionDistance;

private Map<Integer, NPC> npcMap = new ConcurrentHashMap<>();
private final Map<Integer, NPC> npcMap = new ConcurrentHashMap<>();

/**
* Creates a new NPC pool which handles events, spawning and destruction of the NPCs for players
Expand All @@ -59,8 +59,8 @@ public NPCPool(@NotNull JavaPlugin javaPlugin, int spawnDistance, int actionDist

this.javaPlugin = javaPlugin;

this.spawnDistance = spawnDistance;
this.actionDistance = actionDistance;
this.spawnDistance = spawnDistance * spawnDistance;
this.actionDistance = actionDistance * actionDistance;

Bukkit.getPluginManager().registerEvents(this, javaPlugin);

Expand All @@ -82,7 +82,7 @@ public void onPacketReceiving(PacketEvent event) {

Bukkit.getScheduler().runTask(javaPlugin, () ->
Bukkit.getPluginManager().callEvent(
new PlayerNPCInteractEvent(event.getPlayer(), npc, PlayerNPCInteractEvent.Action.fromProtocolLib(action))
new PlayerNPCInteractEvent(event.getPlayer(), npc, action)
));
}
}
Expand All @@ -95,7 +95,7 @@ private void npcTick() {
for (Player player : ImmutableList.copyOf(Bukkit.getOnlinePlayers())) {

for (NPC npc : this.npcMap.values()) {
double distance = npc.getLocation().distance(player.getLocation());
double distance = npc.getLocation().distanceSquared(player.getLocation());

if (distance >= this.spawnDistance && npc.isShownFor(player)) {
npc.hide(player);
Expand Down Expand Up @@ -143,7 +143,7 @@ public void handleSneak(PlayerToggleSneakEvent event) {
Player player = event.getPlayer();

this.npcMap.values().stream()
.filter(npc -> npc.isImitatePlayer() && npc.isShownFor(player) && npc.getLocation().distance(player.getLocation()) <= this.actionDistance)
.filter(npc -> npc.isImitatePlayer() && npc.isShownFor(player) && npc.getLocation().distanceSquared(player.getLocation()) <= this.actionDistance)
.forEach(npc -> npc.metadata().queueSneaking(event.isSneaking()).send(player));
}

Expand All @@ -153,7 +153,7 @@ public void handleClick(PlayerInteractEvent event) {

if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK) {
this.npcMap.values().stream()
.filter(npc -> npc.isImitatePlayer() && npc.isShownFor(player) && npc.getLocation().distance(player.getLocation()) <= this.actionDistance)
.filter(npc -> npc.isImitatePlayer() && npc.isShownFor(player) && npc.getLocation().distanceSquared(player.getLocation()) <= this.actionDistance)
.forEach(npc -> npc.animation().queue(AnimationModifier.EntityAnimation.SWING_MAIN_ARM).send(player));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ public class PlayerNPCInteractEvent extends PlayerEvent {

private static final HandlerList HANDLER_LIST = new HandlerList();

private NPC npc;
private final NPC npc;

private Action action;
private final EnumWrappers.EntityUseAction action;

public PlayerNPCInteractEvent(@NotNull Player who, @NotNull NPC npc, @NotNull Action action) {
public PlayerNPCInteractEvent(@NotNull Player who, @NotNull NPC npc, @NotNull EnumWrappers.EntityUseAction action) {
super(who);
this.npc = npc;
this.action = action;
Expand All @@ -33,7 +33,7 @@ public NPC getNPC() {
}

@NotNull
public Action getAction() {
public EnumWrappers.EntityUseAction getAction() {
return action;
}

Expand All @@ -43,14 +43,4 @@ public HandlerList getHandlers() {
return HANDLER_LIST;
}

public enum Action {
RIGHT_CLICKED,
LEFT_CLICKED;

public static Action fromProtocolLib(EnumWrappers.EntityUseAction protocolLibAction) {
return protocolLibAction == EnumWrappers.EntityUseAction.ATTACK ? LEFT_CLICKED : RIGHT_CLICKED;
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public enum EntityAnimation {
CRITICAL_EFFECT(4),
MAGIC_CRITICAL_EFFECT(5);

private int id;
private final int id;

EntityAnimation(int id) {
this.id = id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

public class MetadataModifier extends NPCModifier {

private List<WrappedWatchableObject> metadata = new ArrayList<>();
private final List<WrappedWatchableObject> metadata = new ArrayList<>();

public MetadataModifier(@NotNull NPC npc) {
super(npc);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class NPCModifier {

protected NPC npc;

private List<PacketContainer> packetContainers = new CopyOnWriteArrayList<>();
private final List<PacketContainer> packetContainers = new CopyOnWriteArrayList<>();

public NPCModifier(@NotNull NPC npc) {
this.npc = npc;
Expand Down

0 comments on commit 4d97d1c

Please sign in to comment.