Updates to the Blacksmith Snapshot API
All checks were successful
KnarCraft/BlacksmithVisuals/pipeline/head This commit looks good
All checks were successful
KnarCraft/BlacksmithVisuals/pipeline/head This commit looks good
This commit is contained in:
parent
c013e3e65d
commit
f1f4526f9d
@ -6,7 +6,7 @@ effect.
|
|||||||
|
|
||||||
## Dependencies
|
## Dependencies
|
||||||
|
|
||||||
This plugins requires the following:
|
This plugin requires the following:
|
||||||
|
|
||||||
- [Blacksmith](https://www.spigotmc.org/resources/blacksmith.105938/)
|
- [Blacksmith](https://www.spigotmc.org/resources/blacksmith.105938/)
|
||||||
- [Citizens](https://www.spigotmc.org/resources/citizens.13811/) (also a dependency for Blacksmith)
|
- [Citizens](https://www.spigotmc.org/resources/citizens.13811/) (also a dependency for Blacksmith)
|
||||||
|
4
pom.xml
4
pom.xml
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>net.knarcraft</groupId>
|
<groupId>net.knarcraft</groupId>
|
||||||
<artifactId>BlacksmithVisuals</artifactId>
|
<artifactId>BlacksmithVisuals</artifactId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.1-SNAPSHOT</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>BlacksmithVisuals</name>
|
<name>BlacksmithVisuals</name>
|
||||||
@ -111,7 +111,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.knarcraft</groupId>
|
<groupId>net.knarcraft</groupId>
|
||||||
<artifactId>blacksmith</artifactId>
|
<artifactId>blacksmith</artifactId>
|
||||||
<version>1.1.2</version>
|
<version>1.1.3-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -11,6 +11,7 @@ import org.bukkit.SoundCategory;
|
|||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.TabExecutor;
|
import org.bukkit.command.TabExecutor;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@ -34,7 +35,8 @@ public class PlayTestSoundCommand implements TabExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (arguments.length < 2) {
|
Entity entity = npc.getEntity();
|
||||||
|
if (arguments.length < 2 || !npc.isSpawned() || entity == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,8 +64,7 @@ public class PlayTestSoundCommand implements TabExecutor {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
SoundData soundData = new SoundData(soundCategory, sound, volume, pitch, 0, true);
|
SoundHelper.playSound(entity, new SoundData(soundCategory, sound, volume, pitch, 0, true));
|
||||||
SoundHelper.playSound(npc.getEntity(), soundData);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,22 +80,22 @@ public class BlacksmithListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onReforgeSuccess(@NotNull BlacksmithReforgeSucceedEvent event) {
|
public void onReforgeSuccess(@NotNull BlacksmithReforgeSucceedEvent event) {
|
||||||
SoundHelper.playSound(event.getNpc().getEntity(), this.configurationManager.getSoundData(SoundIdentifier.REFORGING_SUCCESS));
|
SoundHelper.playSound(event.getEntity(), this.configurationManager.getSoundData(SoundIdentifier.REFORGING_SUCCESS));
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onSalvageSuccess(@NotNull ScrapperSalvageSucceedEvent event) {
|
public void onSalvageSuccess(@NotNull ScrapperSalvageSucceedEvent event) {
|
||||||
SoundHelper.playSound(event.getNpc().getEntity(), this.configurationManager.getSoundData(SoundIdentifier.SALVAGING_SUCCESS));
|
SoundHelper.playSound(event.getEntity(), this.configurationManager.getSoundData(SoundIdentifier.SALVAGING_SUCCESS));
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onReforgeFail(@NotNull BlacksmithReforgeFailEvent event) {
|
public void onReforgeFail(@NotNull BlacksmithReforgeFailEvent event) {
|
||||||
SoundHelper.playSound(event.getNpc().getEntity(), this.configurationManager.getSoundData(SoundIdentifier.REFORGING_FAILURE));
|
SoundHelper.playSound(event.getEntity(), this.configurationManager.getSoundData(SoundIdentifier.REFORGING_FAILURE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onSalvageFail(@NotNull ScrapperSalvageFailEvent event) {
|
public void onSalvageFail(@NotNull ScrapperSalvageFailEvent event) {
|
||||||
SoundHelper.playSound(event.getNpc().getEntity(), this.configurationManager.getSoundData(SoundIdentifier.SALVAGING_FAILURE));
|
SoundHelper.playSound(event.getEntity(), this.configurationManager.getSoundData(SoundIdentifier.SALVAGING_FAILURE));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -112,7 +112,7 @@ public class BlacksmithListener implements Listener {
|
|||||||
NPC npc = event.getNpc();
|
NPC npc = event.getNpc();
|
||||||
|
|
||||||
NPCPosition npcPosition = NPCPosition.getFromMaterial(event.getCraftingStation());
|
NPCPosition npcPosition = NPCPosition.getFromMaterial(event.getCraftingStation());
|
||||||
long delay = moveToWorkingPosition(npc, npcPosition);
|
long delay = moveToWorkingPosition(npc, event.getEntity(), npcPosition);
|
||||||
if (npc.hasTrait(LookClose.class)) {
|
if (npc.hasTrait(LookClose.class)) {
|
||||||
LookClose trait = npc.getTraitNullable(LookClose.class);
|
LookClose trait = npc.getTraitNullable(LookClose.class);
|
||||||
this.oldLookRanges.put(npc.getUniqueId(), trait.getRange());
|
this.oldLookRanges.put(npc.getUniqueId(), trait.getRange());
|
||||||
@ -120,17 +120,18 @@ public class BlacksmithListener implements Listener {
|
|||||||
}
|
}
|
||||||
long finishTime = event.getActionDurationTicks() - (2 * delay);
|
long finishTime = event.getActionDurationTicks() - (2 * delay);
|
||||||
|
|
||||||
scheduler.scheduleSyncDelayedTask(instance, () -> startWorkAnimation(npc.getEntity(),
|
scheduler.scheduleSyncDelayedTask(instance, () -> startWorkAnimation(event.getEntity(),
|
||||||
this.configurationManager.getSoundData(soundIdentifier), animationData, finishTime - 20, npcPosition), delay);
|
this.configurationManager.getSoundData(soundIdentifier), animationData, finishTime - 20, npcPosition), delay);
|
||||||
scheduler.scheduleSyncDelayedTask(instance, () -> moveBack(event.getNpc()), finishTime);
|
scheduler.scheduleSyncDelayedTask(instance, () -> moveBack(event.getNpc(), event.getEntity()), finishTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Moves an NPC back to its idle position
|
* Moves an NPC back to its idle position
|
||||||
*
|
*
|
||||||
* @param npc <p>The NPC to move</p>
|
* @param npc <p>The NPC to move</p>
|
||||||
|
* @param entity <p>The entity of the NPC</p>
|
||||||
*/
|
*/
|
||||||
private void moveBack(@NotNull NPC npc) {
|
private void moveBack(@NotNull NPC npc, @NotNull Entity entity) {
|
||||||
if (!npc.isSpawned()) {
|
if (!npc.isSpawned()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -156,7 +157,7 @@ public class BlacksmithListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(BlacksmithVisuals.getInstance(), () ->
|
Bukkit.getScheduler().scheduleSyncDelayedTask(BlacksmithVisuals.getInstance(), () ->
|
||||||
npc.getEntity().teleport(targetLocation), getWalkTime(npc.getEntity().getLocation(), targetLocation));
|
entity.teleport(targetLocation), getWalkTime(entity.getLocation(), targetLocation));
|
||||||
npc.getNavigator().setTarget(targetLocation);
|
npc.getNavigator().setTarget(targetLocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,10 +165,11 @@ public class BlacksmithListener implements Listener {
|
|||||||
* Moves a npc to its working position
|
* Moves a npc to its working position
|
||||||
*
|
*
|
||||||
* @param npc <p>The NPC to move</p>
|
* @param npc <p>The NPC to move</p>
|
||||||
|
* @param entity <p>The entity of the NPC</p>
|
||||||
* @param npcPosition <p>The npc position to move to</p>
|
* @param npcPosition <p>The npc position to move to</p>
|
||||||
* @return <p>The time the move will take</p>
|
* @return <p>The time the move will take</p>
|
||||||
*/
|
*/
|
||||||
private long moveToWorkingPosition(@NotNull NPC npc, @Nullable NPCPosition npcPosition) {
|
private long moveToWorkingPosition(@NotNull NPC npc, @NotNull Entity entity, @Nullable NPCPosition npcPosition) {
|
||||||
if (!npc.isSpawned() || npcPosition == null) {
|
if (!npc.isSpawned() || npcPosition == null) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -193,15 +195,15 @@ public class BlacksmithListener implements Listener {
|
|||||||
Location finalTargetLocation = targetLocation;
|
Location finalTargetLocation = targetLocation;
|
||||||
|
|
||||||
// Move NPC using Citizens path-finding
|
// Move NPC using Citizens path-finding
|
||||||
Location current = npc.getEntity().getLocation().clone();
|
Location current = entity.getLocation().clone();
|
||||||
npc.teleport(current.setDirection(targetLocation.toVector().subtract(current.toVector())), PlayerTeleportEvent.TeleportCause.PLUGIN);
|
npc.teleport(current.setDirection(targetLocation.toVector().subtract(current.toVector())), PlayerTeleportEvent.TeleportCause.PLUGIN);
|
||||||
|
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(BlacksmithVisuals.getInstance(), () -> npc.getNavigator().setTarget(finalTargetLocation), 2);
|
Bukkit.getScheduler().scheduleSyncDelayedTask(BlacksmithVisuals.getInstance(), () -> npc.getNavigator().setTarget(finalTargetLocation), 2);
|
||||||
|
|
||||||
// Teleport the NPC tp get it in the exact final location
|
// Teleport the NPC tp get it in the exact final location
|
||||||
long walkTime = getWalkTime(npc.getEntity().getLocation(), targetLocation);
|
long walkTime = getWalkTime(entity.getLocation(), targetLocation);
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(BlacksmithVisuals.getInstance(), () ->
|
Bukkit.getScheduler().scheduleSyncDelayedTask(BlacksmithVisuals.getInstance(), () ->
|
||||||
npc.getEntity().teleport(finalTargetLocation), walkTime);
|
entity.teleport(finalTargetLocation), walkTime);
|
||||||
return walkTime;
|
return walkTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user