Solved Essentials API help

Discussion in 'Plugin Development' started by Takedown, Jan 5, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    Takedown

    So im working on a pvp plugin so that when you run the command "/pvp" it is going to teleport you to the specified pvp area. I also have it so it turns your gamemode into survival and your fly mode off. I cant seem to figure out how to implement essentials and have it turn your godmode off and your vanish off. This is what I have for godmode but when I run the /pvp command it just gives me an error. If someone could help me out with godmode and vanish that would be great!
    Code:
    package me.takedown.pvp;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.GameMode;
    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import net.ess3.api.events.GodStatusChangeEvent;
    
    import com.earth2me.essentials.CommandSource;
    import com.earth2me.essentials.User;
    import com.earth2me.essentials.UserData;
    
    import org.bukkit.Server;
    
    import com.earth2me.essentials.Essentials;
    import com.earth2me.essentials.commands.Commandvanish;
    
    public class pvp extends JavaPlugin{
    
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            Player p = (Player) sender;
            if (cmd.getName().equalsIgnoreCase("setpvp")) {
            getConfig().set("pvp.world", p.getLocation().getWorld().getName());
            getConfig().set("pvp.x", p.getLocation().getX());
            getConfig().set("pvp.y", p.getLocation().getY());
            getConfig().set("pvp.z", p.getLocation().getZ());
            saveConfig();
            p.sendMessage(ChatColor.GREEN + "PvP spawn set!");
            return true;
        }
            Essentials ess = (Essentials) Bukkit.getPluginManager().getPlugin("Essentials");
            if (cmd.getName().equalsIgnoreCase("pvp")) {
            if (getConfig().getConfigurationSection("pvp") == null) {
                p.sendMessage(ChatColor.RED + "The PvP spawn has not yet been set!");
                return true;
            }
            World w = Bukkit.getServer().getWorld(getConfig().getString("pvp.world"));
            double x = getConfig().getDouble("pvp.x");
            double y = getConfig().getDouble("pvp.y");
            double z = getConfig().getDouble("pvp.z");
            p.teleport(new Location(w, x, y, z));
            p.setGameMode(GameMode.SURVIVAL);
            p.setFlying(false);
            boolean enabled = !((User) p).isGodModeEnabled();
            ((User) p).setGodModeEnabled(false);
            p.sendMessage(ChatColor.GREEN + "Welcome to PvP! You are now ready to fight!");
           
            }
        return true;
    }
    }
    
     
  2. Offline

    uksspy

    @Takedown
    when I run the /pvp command it just gives me an error.

    You should post that error. The point of stack-traces (errors) is to help developers, like yourself, solve the problem.
     
  3. Offline

    Takedown

    Oh sorry, The error message from console:


    org.bukkit.command.CommandException: Unhandled exception executing command 'pvp'
    in plugin pvp v1
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[cod
    ing.jar:git-Bukkit-1.7.9-R0.2-17-g3833911-b3106jnks]
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:18
    0) ~[coding.jar:git-Bukkit-1.7.9-R0.2-17-g3833911-b3106jnks]
    at org.bukkit.craftbukkit.v1_7_R4.CraftServer.dispatchCommand(CraftServe
    r.java:740) ~[coding.jar:git-Bukkit-1.7.9-R0.2-17-g3833911-b3106jnks]
    at net.minecraft.server.v1_7_R4.PlayerConnection.handleCommand(PlayerCon
    nection.java:957) [coding.jar:git-Bukkit-1.7.9-R0.2-17-g3833911-b3106jnks]
    at net.minecraft.server.v1_7_R4.PlayerConnection.a(PlayerConnection.java
    :818) [coding.jar:git-Bukkit-1.7.9-R0.2-17-g3833911-b3106jnks]
    at net.minecraft.server.v1_7_R4.PacketPlayInChat.a(PacketPlayInChat.java
    :28) [coding.jar:git-Bukkit-1.7.9-R0.2-17-g3833911-b3106jnks]
    at net.minecraft.server.v1_7_R4.PacketPlayInChat.handle(PacketPlayInChat
    .java:47) [coding.jar:git-Bukkit-1.7.9-R0.2-17-g3833911-b3106jnks]
    at net.minecraft.server.v1_7_R4.NetworkManager.a(NetworkManager.java:157
    ) [coding.jar:git-Bukkit-1.7.9-R0.2-17-g3833911-b3106jnks]
    at net.minecraft.server.v1_7_R4.ServerConnection.c(SourceFile:134) [codi
    ng.jar:git-Bukkit-1.7.9-R0.2-17-g3833911-b3106jnks]
    at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:6
    67) [coding.jar:git-Bukkit-1.7.9-R0.2-17-g3833911-b3106jnks]
    at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:2
    58) [coding.jar:git-Bukkit-1.7.9-R0.2-17-g3833911-b3106jnks]
    at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:5
    58) [coding.jar:git-Bukkit-1.7.9-R0.2-17-g3833911-b3106jnks]
    at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java
    :469) [coding.jar:git-Bukkit-1.7.9-R0.2-17-g3833911-b3106jnks]
    at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:6
    28) [coding.jar:git-Bukkit-1.7.9-R0.2-17-g3833911-b3106jnks]
    Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.v1_7_R4.entity.C
    raftPlayer cannot be cast to com.earth2me.essentials.User
    at me.takedown.pvp.pvp.onCommand(pvp.java:50) ~[?:?]
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[cod
    ing.jar:git-Bukkit-1.7.9-R0.2-17-g3833911-b3106jnks]
    ... 13 more
     
  4. Offline

    Permeer

    Remove

    Code:
            ((User) p).setGodModeEnabled(false);
    Put

    Code:
    Essentials ess = (Essentials) Bukkit.getPluginManager().getPlugin("Essentials");
    
    ess.getUser(p).setGodModeEnabled(false);
     
    Takedown likes this.
  5. Offline

    Takedown

    Thanks! Alot.
     
Thread Status:
Not open for further replies.

Share This Page