Why isn't this code working [java]

Status
This thread has been locked.

Hymart

Setup Specialist
Banned
Feedback score
7
Posts
175
Reactions
163
Resources
0
Maybe I just don't understand schedulers. But this is flashing an error message bruh and I can't diagnose that crap.

t65WJnP.png


uPHU07G.png
 
Banned forever. Reason: Admitting to Scamming
PebbleHost
High performance, consistent uptime and fast support. Minecraft hosting that just works.

Hymart

Setup Specialist
Banned
Feedback score
7
Posts
175
Reactions
163
Resources
0
Might be cause I'm casting the plugin to the plugin class.
 
Banned forever. Reason: Admitting to Scamming

Ghast

Founding Father of Hypocrisy - https://artemis.ac
Supreme
Feedback score
54
Posts
2,096
Reactions
3,285
Resources
79
Dmed on discord.
 

Kieraaaan

Plugin Developer
Premium
Feedback score
7
Posts
463
Reactions
222
Resources
0
Maybe I just don't understand schedulers. But this is flashing an error message bruh and I can't diagnose that crap.

t65WJnP.png


uPHU07G.png
Could you indent the code please? Press Control + Shift + F
 

Hymart

Setup Specialist
Banned
Feedback score
7
Posts
175
Reactions
163
Resources
0
upload_2019-6-9_13-55-28.png
 

Attachments

  • upload_2019-6-9_13-55-28.png
    upload_2019-6-9_13-55-28.png
    56.6 KB · Views: 60
Banned forever. Reason: Admitting to Scamming

Hymart

Setup Specialist
Banned
Feedback score
7
Posts
175
Reactions
163
Resources
0
Change active = true to active == true for starters

In this case it doesn't effect the functionality bruh[DOUBLEPOST=1560085077][/DOUBLEPOST]
Change active = true to active == true for starters

Actually, it breaks it entirely.
upload_2019-6-9_13-57-54.png
 

Attachments

  • upload_2019-6-9_13-57-54.png
    upload_2019-6-9_13-57-54.png
    4 KB · Views: 62
Banned forever. Reason: Admitting to Scamming

Kieraaaan

Plugin Developer
Premium
Feedback score
7
Posts
463
Reactions
222
Resources
0
In this case it doesn't effect the functionality bruh[DOUBLEPOST=1560085077][/DOUBLEPOST]

Actually, it breaks it entirely.
View attachment 231102
This should work, you had some useless if statements so I removed them.
Code:
if (!(sender instanceof Player)) return true;
Player player = (Player) sender;
if (!player.hasPermission("timedflight.15m")) return true;
if (!active) {
    player.setAllowFlight(true);
    player.setFlying(true);
    player.sendMessage("asda");
    active = true;
    new BukkitRunnable() {
        @Override
        public void run() {
            player.setFlying(false);
            player.sendMessage("asda");
        }
    }.runTaskLater(plugin, 9000L);
} else {
    if (player.getAllowFlight()) {
        player.setAllowFlight(false);
        player.sendMessage("");
    }
}
EDIT: You shouldn't have a global boolean in the class because that can be changed by anyone. Use a HashMap<UUID, Boolean> to store the player's UUID and a boolean to see if they're flying or not.[DOUBLEPOST=1560085409][/DOUBLEPOST]
In this case it doesn't effect the functionality bruh[DOUBLEPOST=1560085077][/DOUBLEPOST]

Actually, it breaks it entirely.
View attachment 231102
He meant in the if statement, you had
Code:
if (active = true)
which you need to change to
Code:
if (active == true)
OR better, use
Code:
if (active)
 
Last edited:

Hymart

Setup Specialist
Banned
Feedback score
7
Posts
175
Reactions
163
Resources
0
This should work, you had some useless if statements so I removed them.
Code:
if (!(sender instanceof Player)) return true;
Player player = (Player) sender;
if (!player.hasPermission("timedflight.15m")) return true;
if (!active) {
    player.setAllowFlight(true);
    player.setFlying(true);
    player.sendMessage("asda");
    active = true;
    new BukkitRunnable() {
        @Override
        public void run() {
            player.setFlying(false);
            player.sendMessage("asda");
        }
    }.runTaskLater(plugin, 9000L);
} else {
    if (player.getAllowFlight()) {
        player.setAllowFlight(false);
        player.sendMessage("");
    }
}
EDIT: You shouldn't have a global boolean in the class because that can be changed by anyone. Use a HashMap<UUID, Boolean> to store the player's UUID and a boolean to see if they're flying or not.[DOUBLEPOST=1560085409][/DOUBLEPOST]
He meant in the if statement, you had
Code:
if (active = true)
which you need to change to
Code:
if (active == true)
OR better, use
Code:
if (active)

That gives this error:
 
Banned forever. Reason: Admitting to Scamming

Kieraaaan

Plugin Developer
Premium
Feedback score
7
Posts
463
Reactions
222
Resources
0
That gives this error:

yeah because you need to use your own plugin instance.

change plugin for this in the runnable bit.
 
Last edited:

Kieraaaan

Plugin Developer
Premium
Feedback score
7
Posts
463
Reactions
222
Resources
0

Kieraaaan

Plugin Developer
Premium
Feedback score
7
Posts
463
Reactions
222
Resources
0
you think I have the effort or motivation to read through a million docs.
Well you're never going to learn by copying what other people write in YouTube tutorials.
Notice the word "copy". If you're not going to read through the docs and are going to watch YouTube videos, at least pause them and understand what the person is writing. Don't just copy or you won't learn anything.
 

Hymart

Setup Specialist
Banned
Feedback score
7
Posts
175
Reactions
163
Resources
0
Well you're never going to learn by copying what other people write in YouTube tutorials.
Notice the word "copy". If you're not going to read through the docs and are going to watch YouTube videos, at least pause them and understand what the person is writing. Don't just copy or you won't learn anything.

trust me mate, if this monstrosity was from a tutorial I doubt it would be so defective and shitly laid out.
 
Banned forever. Reason: Admitting to Scamming

GazpachoYT

Feedback score
7
Posts
27
Reactions
12
Resources
0
Line 32[DOUBLEPOST=1560086916][/DOUBLEPOST]Why are you doing if(active == true)? just change it to if(active) / if(!active)
 

Kieraaaan

Plugin Developer
Premium
Feedback score
7
Posts
463
Reactions
222
Resources
0
Line 32[DOUBLEPOST=1560086916][/DOUBLEPOST]Why are you doing if(active == true)? just change it to if(active) / if(!active)
Umm, you just repeated what’s already been said :tup: nice one
 
Status
This thread has been locked.
Top