Help (Whats wrong with my code?

Status
This thread has been locked.

Suspicions

Banned
Feedback score
0
Posts
4
Reactions
0
Resources
0
So I am making a plugin and when I run the command nothing, happens. I used to have just the FM class and it worked fine, then I added the "getCommand("fm").setExecutor(new FM)", and know it does work here are some images.

They are the classes.
808c8cbf1e35b385d99b23a50080d6d2.png


This is the FM.java
5577b9d65e888c2c428aec7e772c892f.png


This is the Main.java
0efccaba5f9ef6707eb5ddbb8a236da6.png


This is the plugin.yml
22efa65f0737cf18015d97711fd105d2.png


<Please help I need to fix this ASAP>
 
PebbleHost
High performance, consistent uptime and fast support. Minecraft hosting that just works.

Stockfish

Sometimes a software developer
Premium
Feedback score
2
Posts
185
Reactions
100
Resources
0
Code:
if(sender instanceof Player) {
}
Player p = (Player) sender;
You're basically saying if the sender of the given command is a player, do nothing.
EDIT: You did the same thing with the command /fm. You messed up the brackets.
 

Suspicions

Banned
Feedback score
0
Posts
4
Reactions
0
Resources
0
Ah, thanks[DOUBLEPOST=1472665701][/DOUBLEPOST]It still doesn't work I got rid of the if(sender instanceof Player) {[DOUBLEPOST=1472665737][/DOUBLEPOST]Can you show me how the brackets should look?
 
Banned forever. Reason: Scamming (https://builtbybit.com/threads/youtoggling-scam-report.130438/)

Tyler

Developer
Supreme
Feedback score
14
Posts
2,589
Reactions
2,238
Resources
0
Ah, thanks[DOUBLEPOST=1472665701][/DOUBLEPOST]It still doesn't work I got rid of the if(sender instanceof Player) {[DOUBLEPOST=1472665737][/DOUBLEPOST]Can you show me how the brackets should look?
The ones for checking if the command is "fm" should be around what you want it do to for that command.
 

Nagi

PM Only - No Skype
Supreme
Feedback score
12
Posts
535
Reactions
679
Resources
0
Ah, thanks[DOUBLEPOST=1472665701][/DOUBLEPOST]It still doesn't work I got rid of the if(sender instanceof Player) {[DOUBLEPOST=1472665737][/DOUBLEPOST]Can you show me how the brackets should look?
Code:
if(true) {
    // Run Code Inside Here
}

What you did was...
Code:
if(true) {
    // Where's the code?
}
// Oh it's here, outside the brackets...
 

Suspicions

Banned
Feedback score
0
Posts
4
Reactions
0
Resources
0
Kappa
Here is updates version its still doesnt work
e599dd2d1cd5fe28fdcae3be1811bce0.png
 
Banned forever. Reason: Scamming (https://builtbybit.com/threads/youtoggling-scam-report.130438/)

Nagi

PM Only - No Skype
Supreme
Feedback score
12
Posts
535
Reactions
679
Resources
0
Probably going to get yelled at by someone... but here you go...

Code:
package com.kthisiscvpv.practice;

import java.util.HashMap;
import java.util.UUID;

import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;

public class FM implements CommandExecutor {

    private HashMap<UUID, Long> cooldowns = new HashMap<UUID, Long>();

    private int COOLDOWN_TIME = 30 * 60 * 1000; // Milliseconds -> 30 minutes
    private int EFFECT_TIME = 20 * 60 * 10; // Bukkit Ticks -> 10 minutes

    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
        if (cmd.getName().equalsIgnoreCase("fm")) {
            if (!(sender instanceof Player)) { // Check if the sender isn't a Player
                sender.sendMessage("You must be a Player to execute this command!");
                return true;
            }

            Player p = (Player) sender;

            if (!p.hasPermission("sc.fm")) { // Check if the sender doesn't have permissions to use the command.
                p.sendMessage(ChatColor.RED + "You do not have permission to use this command.");
                return true;
            }

            if (cooldowns.containsKey(p.getUniqueId())) { // Check if the sender is on cooldown.
                long time = cooldowns.get(p.getUniqueId());
               
                if (time > System.currentTimeMillis()) { // Check if the cooldown is valid.
                    long secondsLeft = (time - System.currentTimeMillis()) / 1000L;
                    p.sendMessage(ChatColor.RED + "You cannot use this command for another " + ChatColor.YELLOW + secondsLeft + " seconds" + ChatColor.RED + ".");
                    return true;
                }
            }

            cooldowns.put(p.getUniqueId(), System.currentTimeMillis() + COOLDOWN_TIME); // Refresh their cooldown.
            p.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, EFFECT_TIME, 9));
            p.sendMessage(ChatColor.LIGHT_PURPLE + "Fast Mining has been enabled! You now have haste for 10 minutes.");

        }
        return false;
    }

}
 

Stockfish

Sometimes a software developer
Premium
Feedback score
2
Posts
185
Reactions
100
Resources
0
Nagi You ninja'd me right when I was almost finished writing a pseudocode for him to use. No cookie for you.
 

Suspicions

Banned
Feedback score
0
Posts
4
Reactions
0
Resources
0
Kappa, will that code work?[DOUBLEPOST=1472671604][/DOUBLEPOST]THANKS KAPPA HELPED ALOT!
 
Banned forever. Reason: Scamming (https://builtbybit.com/threads/youtoggling-scam-report.130438/)

Tyler

Developer
Supreme
Feedback score
14
Posts
2,589
Reactions
2,238
Resources
0
Kappa, will that code work?
It should, in your plugin.yml how many spaces did you use? Looks like 4 before the command, I usually do it like this:
Code:
commands:
  fm: # 2 spaces before
    description:  blah blah # 4 spaces before
Could be part of the problem, but I'm sure you would get console errors when your plugin starts if that is the case. Try out Kappa's code.
 

Turttles

Feedback score
0
Posts
15
Reactions
4
Resources
0
It should, in your plugin.yml how many spaces did you use? Looks like 4 before the command, I usually do it like this:
Code:
commands:
  fm: # 2 spaces before
    description:  blah blah # 4 spaces before
Could be part of the problem, but I'm sure you would get console errors when your plugin starts if that is the case. Try out Kappa's code.

It's never mattered to me. I think most Spigot API programmers write their plugin.yml files in the format you have posted.

Quick note to the OP, when you want to use an if statement(ie.
if (!(sender instanceof Player)) { ), I find it always easiest to negate it(as shown before). It makes balancing brackets much easier, and overall allows for a clean codebase.

So example,
Code:
 if(!player.hasPermission("somethinghere")) {
//do something for NOT having perms
} else {
//why did I do an else statement? who knows. 
}

This is just a personal preference, but it's one I've taught to a few people and they tend to prefer it more.
 

Guusz

Full-Stack Web Developer
Premium
Feedback score
0
Posts
248
Reactions
138
Resources
0
Yeah and the OP didn't learn good enough yet.
 

Turttles

Feedback score
0
Posts
15
Reactions
4
Resources
0
Yeah and the OP didn't learn good enough yet.
hence why I said learning is a process. we all start places. tbh, a LOT of so called 'java programmers' on this site started by watching spigot tutorials on youtube, not knowing anything about other programming languages. lol.
 
Status
This thread has been locked.
Top