Added parsing placeholders in entities' name when pasting blueprints

Implements https://github.com/BentoBoxWorld/BentoBox/issues/898
Also adds a few nullability annotations
This commit is contained in:
Florian CUNY 2019-09-14 21:51:28 +02:00
parent 4206435d65
commit 115f434a30
2 changed files with 19 additions and 7 deletions

View File

@ -87,7 +87,7 @@ public class User {
* @return user - user
*/
@Nullable
public static User getInstance(UUID uuid) {
public static User getInstance(@Nullable UUID uuid) {
if (uuid == null) {
return null;
}

View File

@ -23,6 +23,7 @@ import org.bukkit.entity.Ageable;
import org.bukkit.entity.ChestedHorse;
import org.bukkit.entity.Horse;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Tameable;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
@ -135,7 +136,7 @@ public class BlueprintPaster {
count++;
}
while (pasteState.equals(PasteState.ENTITIES) && count < pasteSpeed && it3.hasNext()) {
pasteEntity(world, loc, it3.next());
pasteEntity(world, island, loc, it3.next());
count++;
}
// STATE SHIFT
@ -211,11 +212,11 @@ public class BlueprintPaster {
return blockData;
}
private void pasteEntity(World world, Location location, Entry<Vector, List<BlueprintEntity>> entry) {
private void pasteEntity(World world, Island island, Location location, Entry<Vector, List<BlueprintEntity>> entry) {
int x = location.getBlockX() + entry.getKey().getBlockX();
int y = location.getBlockY() + entry.getKey().getBlockY();
int z = location.getBlockZ() + entry.getKey().getBlockZ();
setEntity(new Location(world, x, y, z), entry.getValue());
setEntity(island, new Location(world, x, y, z), entry.getValue());
}
/**
@ -255,16 +256,28 @@ public class BlueprintPaster {
/**
* Sets any entity that is in this location
* @param island - Island
* @param location - location
* @param list - list of entities to paste
*/
private void setEntity(Location location, List<BlueprintEntity> list) {
private void setEntity(@Nullable Island island, Location location, List<BlueprintEntity> list) {
list.stream().filter(k -> k.getType() != null).forEach(k -> {
// Center, and just a bit high
Location center = location.add(new Vector(0.5, 0.5, 0.5));
LivingEntity e = (LivingEntity)location.getWorld().spawnEntity(center, k.getType());
if (k.getCustomName() != null) {
e.setCustomName(k.getCustomName());
String customName = k.getCustomName();
if (island != null) {
// Parse any placeholders in the entity's name, if the owner's connected (he should)
Player owner = User.getInstance(island.getOwner()).getPlayer();
if (owner != null) {
customName = plugin.getPlaceholdersManager().replacePlaceholders(owner, customName);
}
}
// Actually set the custom name
e.setCustomName(customName);
}
if (e instanceof Colorable && k.getColor() != null) {
((Colorable) e).setColor(k.getColor());
@ -298,7 +311,6 @@ public class BlueprintPaster {
/**
* Tracks the minimum and maximum block positions
* @param world - world
* @param l - location of block pasted
*/
private void updatePos(Location l) {