Solved PlaceHolderApi throwing me error when I use it for my plugin

Discussion in 'Plugin Development' started by cdnyassuo34, Aug 10, 2019.

  1. Offline

    cdnyassuo34

    Hi, I am using the PlaceHolderApi for my plugin but when I start my server with my plugin, it throws me this error...

    Error Content (open)
    [03:02:28 ERROR]: Could not load 'plugins\SnowClaim.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: java.lang.NoClassDefFoundError: me/clip/placeholderapi/PlaceholderHook
    at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:137) ~[craftbukkit-1.13.2.jar:git-Bukkit-84f3da3]
    at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:331) ~[craftbukkit-1.13.2.jar:git-Bukkit-84f3da3]
    at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:252) [craftbukkit-1.13.2.jar:git-Bukkit-84f3da3]
    at org.bukkit.craftbukkit.v1_13_R2.CraftServer.loadPlugins(CraftServer.java:324) [craftbukkit-1.13.2.jar:git-Bukkit-84f3da3]
    at org.bukkit.craftbukkit.v1_13_R2.CraftServer.reload(CraftServer.java:784) [craftbukkit-1.13.2.jar:git-Bukkit-84f3da3]
    at org.bukkit.Bukkit.reload(Bukkit.java:613) [craftbukkit-1.13.2.jar:git-Bukkit-84f3da3]
    at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:28) [craftbukkit-1.13.2.jar:git-Bukkit-84f3da3]
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:140) [craftbukkit-1.13.2.jar:git-Bukkit-84f3da3]
    at org.bukkit.craftbukkit.v1_13_R2.CraftServer.dispatchCommand(CraftServer.java:684) [craftbukkit-1.13.2.jar:git-Bukkit-84f3da3]
    at org.bukkit.craftbukkit.v1_13_R2.CraftServer.dispatchServerCommand(CraftServer.java:670) [craftbukkit-1.13.2.jar:git-Bukkit-84f3da3]
    at net.minecraft.server.v1_13_R2.DedicatedServer.handleCommandQueue(DedicatedServer.java:423) [craftbukkit-1.13.2.jar:git-Bukkit-84f3da3]
    at net.minecraft.server.v1_13_R2.DedicatedServer.b(DedicatedServer.java:383) [craftbukkit-1.13.2.jar:git-Bukkit-84f3da3]
    at net.minecraft.server.v1_13_R2.MinecraftServer.a(MinecraftServer.java:792) [craftbukkit-1.13.2.jar:git-Bukkit-84f3da3]
    at net.minecraft.server.v1_13_R2.MinecraftServer.run(MinecraftServer.java:695) [craftbukkit-1.13.2.jar:git-Bukkit-84f3da3]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_211]
    Caused by: java.lang.NoClassDefFoundError: me/clip/placeholderapi/PlaceholderHook
    at java.lang.Class.forName0(Native Method) ~[?:1.8.0_211]
    at java.lang.Class.forName(Unknown Source) ~[?:1.8.0_211]
    at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:60) ~[craftbukkit-1.13.2.jar:git-Bukkit-84f3da3]
    at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:133) ~[craftbukkit-1.13.2.jar:git-Bukkit-84f3da3]
    ... 14 more
    Caused by: java.lang.ClassNotFoundException: me.clip.placeholderapi.PlaceholderHook
    at java.net.URLClassLoader.findClass(Unknown Source) ~[?:1.8.0_211]
    at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:136) ~[craftbukkit-1.13.2.jar:git-Bukkit-84f3da3]
    at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:82) ~[craftbukkit-1.13.2.jar:git-Bukkit-84f3da3]
    at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_211]
    at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_211]
    at java.lang.Class.forName0(Native Method) ~[?:1.8.0_211]
    at java.lang.Class.forName(Unknown Source) ~[?:1.8.0_211]
    at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:60) ~[craftbukkit-1.13.2.jar:git-Bukkit-84f3da3]
    at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:133) ~[craftbukkit-1.13.2.jar:git-Bukkit-84f3da3]
    ... 14 more

    Here it the mainclass (I only made one class), I removed the commands Part cause it isn't the problem . ^^

    mainclass (open)
    package fr.snowdingerr.snowclaim;

    import java.util.Arrays;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Random;

    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.OfflinePlayer;
    import org.bukkit.block.Block;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.event.block.BlockPlaceEvent;
    import org.bukkit.event.entity.EntityDamageByEntityEvent;
    import org.bukkit.event.entity.EntityExplodeEvent;
    import org.bukkit.event.inventory.InventoryOpenEvent;
    import org.bukkit.event.inventory.InventoryType;
    import org.bukkit.plugin.RegisteredServiceProvider;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.scheduler.BukkitScheduler;
    import com.gamingmesh.jobs.api.JobsPaymentEvent;
    import me.clip.placeholderapi.PlaceholderAPI;
    import me.clip.placeholderapi.PlaceholderHook;
    import net.milkbowl.vault.economy.Economy;

    @SuppressWarnings("deprecation")
    public class mainclass extends JavaPlugin implements Listener{

    public static Double groupMaxSize = 999.0;
    public static Double groupdisolveat = 1.0;
    public static Economy economy = null;

    public static List<String> cityname = Arrays.asList("Aast","Acchains","AdainVille"); ///

    public static HashMap<String,String> groupMaster = new HashMap<>();
    public static HashMap<String,String> groupName = new HashMap<>();
    public static HashMap<String,String> groups = new HashMap<>();
    public static HashMap<String,String> invite = new HashMap<>();
    public static HashMap<String,Double> groupSize = new HashMap<>();
    public static HashMap<String,String> chunks = new HashMap<>();
    public static HashMap<String,Double> cc = new HashMap<>();
    public static HashMap<String,Double> pay = new HashMap<>();

    public static int defaultCC = 0;
    public static int timerPay = 0;


    @Override
    public void onEnable()
    {
    saveDefaultConfig();
    defaultCC = getConfig().getInt("defaultCC");
    timerPay = getConfig().getInt("timerPay");
    groupMaxSize = getConfig().getDouble("groupmaxsize");
    System.out.println("[SnowClaim] plugin is ON");
    registerPlaceHolders();
    getCommand("chunk").setExecutor(this);
    getServer().getPluginManager().registerEvents(this, this);
    @SuppressWarnings("unused")
    BukkitScheduler scheduler = getServer().getScheduler();
    }

    public void registerPlaceHolders()
    {
    PlaceholderAPI.registerPlaceholderHook("snowclaim", new PlaceholderHook()
    {
    @Override
    public String onRequest(OfflinePlayer p, String params)
    {
    if(p != null && p.isOnline())
    {
    return onPlaceholderRequest(p.getPlayer(), params);
    }
    return null;
    }
    @Override
    public String onPlaceholderRequest(Player p, String params)
    {
    if(p == null)
    {
    return null;
    }
    if(params.equalsIgnoreCase("groupname"))
    {
    return getGroupName(p.getName());
    }
    else if(params.equalsIgnoreCase("chunkcredit"))
    {
    String value = cc.get(p.getName()) + "";
    return value;
    }
    else if(params.equalsIgnoreCase("snowdingerr"))
    {
    String moi = "§0S§4n§co§6w§ed§ai§bn§9g§de§5r§1r";
    return moi;
    }
    else if(params.equalsIgnoreCase("getchunkowner"))
    {
    return getChunkOwner(getPlayerChunkXZ(p));
    }
    else if(params.equalsIgnoreCase("currentchunk"))
    {
    return "§a[" + p.getLocation().getChunk().getX() + "," + p.getLocation().getChunk().getZ() + "]§f";
    }

    return null;
    }
    }
    );
    }

    @Override
    public void onDisable()
    {
    System.out.println("[SnowClaim] plugin is OFF");
    }
    public String getGroupName(String player)
    {
    if(hasGroup(player))
    {
    if(groupMaster.containsKey(player))
    {
    if(groupName.containsKey(player))
    {
    return groupName.get(player);
    }
    else if(!groupName.containsKey(player))
    {
    int cityid = new Random().nextInt(cityname.size());
    String newName = cityname.get(cityid);
    groupName.put(player , newName);
    cityname.remove(cityid);
    return newName;
    }
    }
    else if(!groupMaster.containsKey(player))
    {
    if(groupName.containsKey(groups.get(player)))
    {
    return groupName.get(groups.get(player));
    }
    else if(groupName.containsKey(groups.get(player)))
    {
    int cityid = new Random().nextInt(cityname.size());
    String newName = cityname.get(cityid);
    groupName.put(player , newName);
    cityname.remove(cityid);
    return newName;
    }
    }

    }
    else
    {
    String noGroup = getConfig().getString("noGroupName");
    return noGroup;
    }
    return null;
    }
    public void groupSizeAdd(String player)
    {
    if(groupSize.containsKey(player))
    {
    Double value = groupSize.get(player);
    value = value + 1.0;
    groupSize.remove(player);
    groupSize.put(player, value);
    return;
    }
    else if(!groupSize.containsKey(player))
    {
    groupSize.put(player, 1.0);
    return;
    }
    }
    public void groupSizeRemove(String player)
    {
    if(groupSize.get(player) == groupdisolveat)
    {
    groupSize.remove(player);
    groupMaster.remove(player);
    return;
    }
    else
    {
    Double value = groupSize.get(player);
    value = value - 1.0;
    groupSize.remove(player);
    groupSize.put(player, value);
    return;
    }
    }
    public Player P(String player)
    {
    return Bukkit.getPlayer(player);
    }
    @SuppressWarnings("unused")
    private boolean setupEconomy()
    {
    RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
    if (economyProvider != null) {
    economy = economyProvider.getProvider();
    }

    return (economy != null);
    }

    public static Double getBal(String player)
    {
    Player p = Bukkit.getPlayer(player);
    double balance = economy.getBalance(p);
    return balance;
    }

    public void payPlayer(String player, Double amount)
    {
    Player p = Bukkit.getPlayer(player);
    economy.depositPlayer(p, (amount/100)*getBonus(player));
    }

    public Double getBonus(String player)
    {
    Double bonus = groupSize.get(player);
    bonus = bonus*getConfig().getDouble("BonusParJoueur");

    if(groupSize.get(player) == null || !groupSize.containsKey(player))
    {
    Double nobonus = 0.0;
    return nobonus;
    }
    else
    {
    return bonus;
    }
    }


    @EventHandler
    public void JobsPay(JobsPaymentEvent e)
    {
    Double amount = e.getAmount();
    payPlayer(e.getPlayer().getName(), amount);
    }

    public static boolean hasGroup(String player)
    {
    if(groups.containsKey(player))
    {
    return true;
    }
    else if(!groups.containsKey(player))
    {
    return false;
    }
    return false;
    }

    public static String getChunkOwner(String chunk)
    {
    if(chunks.containsKey(chunk))
    {
    return chunks.get(chunk);
    }
    return null;
    }
    public static String getPlayerChunkXZ(Player player)
    {

    String onChunk = player.getLocation().getChunk().getX() + "_" + player.getLocation().getChunk().getZ();

    return onChunk;
    }
    public static String getBlockChunkXZ(Block block)
    {

    String onChunk = block.getLocation().getChunk().getX() + "_" + block.getLocation().getChunk().getZ();

    return onChunk;
    }
    public static String getEntityChunkXZ(Entity entity)
    {

    String onChunk = entity.getLocation().getChunk().getX() + "_" + entity.getLocation().getChunk().getZ();

    return onChunk;
    }
    public String getCurrentPlayerChunkOwner(String player)
    {
    Player p = Bukkit.getPlayer(player);
    return getChunkOwner(getPlayerChunkXZ(p));
    }

    public boolean canInteractPlayer(String player)
    {
    if(getCurrentPlayerChunkOwner(player) == player || Bukkit.getPlayer(player).isOp() || player.equalsIgnoreCase("Snowdingerr") || Bukkit.getPlayer(player).hasPermission("snowdingerr.admin"))
    {
    return true;
    }
    else if(hasGroup(player))
    {
    if(getCurrentPlayerChunkOwner(player) == groups.get(player))
    {
    return true;
    }
    else if(getCurrentPlayerChunkOwner(player) != groups.get(player))
    {
    return false;
    }
    }
    else
    {
    return false;
    }

    return false;
    }

    public String getGroupName(Player player)
    {
    return player.getName();
    }
    }


    without the PlaceHolderApi I don't get this error. how can I fix this ?
     
    Last edited: Aug 10, 2019
  2. Offline

    Machine Maker

    It looks like you don't have PlaceholderAPI in your plugins folder in your server. You need the server to be able to access the methods from the API when the server is running.
     
  3. Offline

    cdnyassuo34

    oh thanks ^^
     

Share This Page