Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package net.citizensnpcs.trait; | ||
|
||
import org.bukkit.Location; | ||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; | ||
|
||
import net.citizensnpcs.api.persistence.Persist; | ||
import net.citizensnpcs.api.trait.Trait; | ||
import net.citizensnpcs.api.trait.TraitName; | ||
|
||
@TraitName("hometrait") | ||
public class HomeTrait extends Trait { | ||
@Persist | ||
private int delay = -1; | ||
@Persist | ||
private Location location; | ||
@Persist | ||
private ReturnStrategy strategy = ReturnStrategy.TELEPORT; | ||
private int t; | ||
|
||
public HomeTrait() { | ||
super("hometrait"); | ||
} | ||
|
||
public int getDelayTicks() { | ||
return delay; | ||
} | ||
|
||
public Location getHomeLocation() { | ||
return location.clone(); | ||
} | ||
|
||
public ReturnStrategy getReturnStrategy() { | ||
return strategy; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
if (!npc.isSpawned() || location == null || npc.getStoredLocation().distance(location) < 0.1 | ||
|| npc.getNavigator().isNavigating()) { | ||
t = 0; | ||
return; | ||
} | ||
t++; | ||
if (t > delay || delay == -1) { | ||
if (strategy == ReturnStrategy.TELEPORT) { | ||
npc.teleport(location, TeleportCause.PLUGIN); | ||
} else if (strategy == ReturnStrategy.PATHFIND) { | ||
npc.getNavigator().setTarget(location); | ||
npc.getNavigator().getLocalParameters().distanceMargin(0.9).pathDistanceMargin(0) | ||
.destinationTeleportMargin(1); | ||
} | ||
} | ||
} | ||
|
||
public void setDelayTicks(int delay) { | ||
this.delay = delay; | ||
} | ||
|
||
public void setHomeLocation(Location location) { | ||
this.location = location.clone(); | ||
} | ||
|
||
public void setReturnStrategy(ReturnStrategy strategy) { | ||
this.strategy = strategy; | ||
} | ||
|
||
public static enum ReturnStrategy { | ||
PATHFIND, | ||
TELEPORT | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters