Bugs with ProtocolLib Dependency (Maven)
AhmadOnallah opened this issue ยท 0 comments
Hello I am new to coding Minecraft Plugins, I have hard time using ProtocolLib Dependency and I have done the Steps although in the Console it says "Cannot resolve symbol 'comphenix'" , I have installed the Commands in Plugin.yml and pom.xml and Restarted.
Plugin Version: 1.20.2
POM.XML:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>me.molon</groupId>
<artifactId>GiantSurtur</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>GiantSurtur</name>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<repositories>
<repository>
<id>spigotmc-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
<repository>
<id>dmulloy2-repo</id>
<url>https://repo.dmulloy2.net/repository/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.20.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId>
<version>5.1.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
Plugin.yml
name: GiantSurtur
version: '${project.version}'
main: me.molon.giantsurtur.GiantSurtur
api-version: '1.20'
depend: [ ProtocolLib ]
Current Code:
package me.molon.giantsurtur;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Zombie;
import org.bukkit.Material;
import org.bukkit.ChatColor;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.ProtocolManager;
import com.comphenix.protocol.wrappers.EnumWrappers;
import com.comphenix.protocol.wrappers.WrappedAttribute;
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject;
import org.bukkit.Color;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
public class GiantSurtur extends JavaPlugin implements CommandExecutor, Listener {
@Override
public void onEnable() {
getServer().getPluginManager().registerEvents(this, this);
this.getCommand("Surturspawn").setExecutor(this);
protocolManager = ProtocolLibrary.getProtocolManager();
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (cmd.getName().equalsIgnoreCase("Surturspawn")) {
Zombie zombie = (Zombie) sender.getWorld().spawnEntity(sender.getLocation(), EntityType.GIANT);
zombie.setCustomName(ChatColor.RED + "Surtur");
EntityEquipment equipment = zombie.getEquipment();
equipment.setItemInMainHand(new ItemStack(Material.IRON_SWORD));
ItemStack redLeatherHelmet = new ItemStack(Material.LEATHER_HELMET);
ItemStack redLeatherChestplate = new ItemStack(Material.LEATHER_CHESTPLATE);
ItemStack redLeatherLeggings = new ItemStack(Material.LEATHER_LEGGINGS);
ItemStack redLeatherBoots = new ItemStack(Material.LEATHER_BOOTS);
redLeatherHelmet = setLeatherArmorColor(redLeatherHelmet, Color.RED);
redLeatherChestplate = setLeatherArmorColor(redLeatherChestplate, Color.RED);
redLeatherLeggings = setLeatherArmorColor(redLeatherLeggings, Color.RED);
redLeatherBoots = setLeatherArmorColor(redLeatherBoots, Color.RED);
equipment.setHelmet(redLeatherHelmet);
equipment.setChestplate(redLeatherChestplate);
equipment.setLeggings(redLeatherLeggings);
equipment.setBoots(redLeatherBoots);
if (ProtocolLibrary.getProtocolManager().getMinecraftVersion().isAtLeast(ProtocolManager.MinecraftVersion.MINECRAFT_1_9)) {
setCustomAttributes(zombie);
}
return true;
}
return false;
}
@EventHandler
public void onPluginEnable(PluginEnableEvent event) {
if (event.getPlugin().getName().equals("ProtocolLib")) {
getLogger().info("ProtocolLib is enabled.");
}
}
private ItemStack setLeatherArmorColor(ItemStack itemStack, Color color) {
LeatherArmorMeta meta = (LeatherArmorMeta) itemStack.getItemMeta();
meta.setColor(color);
itemStack.setItemMeta(meta);
return itemStack;
}
private void setCustomAttributes(LivingEntity entity) {
WrappedDataWatcher watcher = WrappedDataWatcher.getEntityWatcher(entity);
WrappedDataWatcherObject armor = new WrappedDataWatcherObject(13, WrappedDataWatcher.Registry.get(Byte.class), (byte) 1);
watcher.setObject(armor, (byte) 1);
WrappedDataWatcherObject mainHandItem = new WrappedDataWatcherObject(16, WrappedDataWatcher.Registry.get(Byte.class), (byte) 1);
watcher.setObject(mainHandItem, (byte) 1);
WrappedDataWatcherObject maxHealth = new WrappedDataWatcherObject(6, WrappedDataWatcher.Registry.get(Float.class), 200.0f);
watcher.setObject(maxHealth, 200.0f);
WrappedDataWatcherObject health = new WrappedDataWatcherObject(7, WrappedDataWatcher.Registry.get(Float.class), 200.0f);
watcher.setObject(health, 200.0f);
WrappedDataWatcherObject movementSpeed = new WrappedDataWatcherObject(0, WrappedDataWatcher.Registry.get(Float.class), 0.4f);
watcher.setObject(movementSpeed, 0.4f);
ProtocolLibrary.getProtocolManager().sendServerPacket(entity, ProtocolLibrary.getProtocolManager().getEntityPacketWatcher().getEntityMetadata(entity));
}
}