Raxen/src/main/java/gq/unurled/raxen/commands/admin/SpawnEntity.java
unurled ce3c1d547c 0.4.9
remade attribute system, made everything work
2022-04-05 18:07:37 +02:00

58 lines
2.1 KiB
Java

package gq.unurled.raxen.commands.admin;
import gq.unurled.raxen.Raxen;
import gq.unurled.raxen.components.entity.other.EntityNamespacedKey;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
import static gq.unurled.raxen.components.entity.other.EntityUtils.setNameSpacedKeys;
import static gq.unurled.raxen.utils.Utils.*;
public class SpawnEntity implements TabExecutor {
private Raxen main;
private EntityNamespacedKey namespacedKey;
public SpawnEntity(Raxen main) {
this.main = main;
this.namespacedKey = new EntityNamespacedKey(main);
}
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (!(sender instanceof Player)) {
log(colorString("<red>Console can't execute this command!"));
return false;
}
Player player = (Player) sender;
if (!player.hasPermission("raxen.entityspawn.cmd")) {
player.sendMessage(noPerms());
return false;
}
//example command : /entityspawn ZOMBIE "&cHello folks" 50 200
EntityType type = EntityType.valueOf(args[0]);
Entity e = player.getWorld().spawnEntity(player.getLocation(), type, false);
setNameSpacedKeys(e, "<red>Name", 100, 100,0,50,0,100,0,100,0);
e.customName(colorTextComp(args[1]));
e.setCustomNameVisible(true);
return false;
}
@Override
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
List<String> list = new ArrayList<>();
for (EntityType type : EntityType.values()) {
list.add(type.name());
}
return list;
}
}