0
votes

I am doing a teleportation plugin. Is there any fix to this?

When loading it on my server, I get this error:

[15:46:39 ERROR]: Could not load 'plugins\RTeleport.jar' in folder 'plugins' org.bukkit.plugin.InvalidPluginException: Cannot find main class `me.roofer.RTel eport' at org.bukkit.plugin.java.PluginClassLoader.(PluginClassLoader.jav a:42) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks] at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.j ava:127) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks] at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager. java:328) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks] at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager .java:251) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks] at org.bukkit.craftbukkit.v1_7_R4.CraftServer.loadPlugins(CraftServer.ja va:364) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks] at org.bukkit.craftbukkit.v1_7_R4.CraftServer.(CraftServer.java:32 6) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks] at net.minecraft.server.v1_7_R4.PlayerList.(PlayerList.java:68) [c raftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks] at net.minecraft.server.v1_7_R4.DedicatedPlayerList.(SourceFile:14 ) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks] at net.minecraft.server.v1_7_R4.DedicatedServer.init(DedicatedServer.jav a:133) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks] at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java :436) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks] at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:6 28) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks] Caused by: java.lang.ClassNotFoundException: me.roofer.RTeleport at java.net.URLClassLoader$1.run(Unknown Source) ~[?:1.8.0_25] at java.net.URLClassLoader$1.run(Unknown Source) ~[?:1.8.0_25] at java.security.AccessController.doPrivileged(Native Method) ~[?:1.8.0_ 25] at java.net.URLClassLoader.findClass(Unknown Source) ~[?:1.8.0_25] at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader. java:77) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks] at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader. java:62) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks] at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_25] at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_25] at java.lang.Class.forName0(Native Method) ~[?:1.8.0_25] at java.lang.Class.forName(Unknown Source) ~[?:1.8.0_25] at org.bukkit.plugin.java.PluginClassLoader.(PluginClassLoader.jav a:40) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks] ... 10 more

Here is the code. There are no warnings and the config.yml file is fine.

package me.roofer.RTeleport;

import java.util.UUID;
import java.util.logging.Logger;

import me.roofer.RTeleport.RTeleport;

import org.bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin;

public class RTelport extends JavaPlugin {
    public Logger logger = Logger.getLogger("rtp");   
    public RTeleport plugin;

    @Override
    public void onDisable() {
        PluginDescriptionFile pdfFile = this.getDescription();
        getLogger().info(pdfFile.getName() + " has been disabled!");
    }
    @Override
    public void onEnable() {
        PluginDescriptionFile pdfFile = this.getDescription();
        getLogger().info(pdfFile.getName() + " has been Enabled!");
    }
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
        Player player = (Player) sender;
        if(player.hasPermission("rteleport.*")){
            if(commandLabel.equalsIgnoreCase("rtp")){
                player.sendMessage(ChatColor.RED + "NOT ENOUGH ARGUMENTS!");
            }else if(args.length == 1){
                Player targetPlayer = player.getServer().getPlayer(UUID.fromString(args[0]));
                Location location = targetPlayer.getLocation();
                player.teleport(location);
                player.sendMessage(ChatColor.DARK_AQUA + "Teleportation commensing... ");
            }
        }
        return false;
    }
}
2
You could use Player.teleport(Entity) instead. - spongebob

2 Answers

1
votes

Set the main: key in the plugin.yml file to the full name of the main class, including the package.

main: me.roofer.RTeleport.RTeleport


I suggest you to follow the naming conventions and put the packages in lowercase.

0
votes

In the your plugin.yml file, you say that the main package is me.roofer.RTeleport.RTeleport but the class that you provided is called RTelport. Try changing the package name in your plugin.yml to me.roofer.RTeleport.RTelport or change your class name to RTeleport.

Also, it is recommended to not use public Logger logger = Logger.getLogger("rtp"); as this can cause issues. Instead, try using public Logger logger = Bukkit.getLogger();

Also, you have assumed that the sender is a player. To avoid any errors, try changing your onCommand method to this:

public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
    if(!(sender instanceof Player)){
        sender.sendMessage(ChatColor.RED + "You must be a player to do that!");
        return true;
    }
    Player player = (Player) sender;
    if(player.hasPermission("rteleport.*")){
        if(commandLabel.equalsIgnoreCase("rtp")){
            if(args.length != 1){
                player.sendMessage(ChatColor.RED + "Incorrect arguments!");
                return true;
            }
            else{
                Player targetPlayer = player.getServer().getPlayer(UUID.fromString(args[0]));
                if(targetPlayer == null){
                    player.sendMessage(ChatColor.RED + "Could not find player!");
                    return true;
                }
                player.teleport(targetPlayer);
                player.sendMessage(ChatColor.DARK_AQUA + "Teleportation commencing... ");
                return true;
            }
        }
    }
    return false;
}

By adding the return true; statements, this stops the code from progressing and prevents some errors that could occur.

Also, you should check to see if the player exists before teleporting. If the player is not online, then it would throw errors.

The above code fixes all of it.