Flight plugin

player.setAllowFlight for sponge? how do i do it?

This is the sponge code:
package com.github.Lukamon24.testsponge.Commands;

import org.spongepowered.api.command.CommandException;
import org.spongepowered.api.command.CommandResult;
import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.command.args.CommandContext;
import org.spongepowered.api.entity.living.player.gamemode.GameModes;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.format.TextColor;
import org.spongepowered.api.entity.living.player.gamemode.GameMode;
import org.spongepowered.api.command.spec.CommandExecutor;
import org.spongepowered.api.command.source.ConsoleSource;
import org.spongepowered.api.entity.living.player.Player;

public class testfly implements CommandExecutor {

@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    if(src instanceof Player) {
        Player player = (Player) src;
        if(player.hasPermission("testsponge.fly")) {
            if(player.getGameModeData().equals(GameModes.SURVIVAL)) {
                player.setA
            }
        }
    } return CommandResult.success();
}

}

so I didn’t finish that setAllowFlight like we can do in bukkit but i don’t know how to do it in sponge

Take a look at the sponge docs. It would have told you about the keys system :wink:

A example of the key system is

player.offer(Keys.GAME_MODE, GameModes.CREATIVE);

I deliberately didnt give you your example. No spoonfeeding here

Oh and here is a easier way for getting from the keys system

Gamemode gamemode = player.get(Keys.GAME_MODE).get();

https://docs.spongepowered.org/stable/en/plugin/data/keys.html

1 Like

mmm then that setAllowFlight() thing?

tht’s actually a tasty knowledge :joy:

Im going to assume by your response that you understood it?..

No. Yes. But not that setAllowFlight() cuz u din’t tell meh abt that and am too lazy to read the whole doc, well kind of complex though but loved it

Lukamon1234#3823

I didnt tell you about it as spoon feeding is something i dont like to do. But ill give you another hint.

Keys has many options which your IDE (intelij, eclipse, etc) will suggest.

As for too lazy to read. If would had been quicker to read the documentation rather then wait for me to respond as your reading both anyway. You will also find that around 90% of programming is reading documentation

Lmao yes. Uh uh well okay thanks for your answer!

But it’s possible isn’t it? Just tell that

It is possible. Very easily possible

Yea got it about that keys

Oh and yeah can u tell something abt SpongeForge 1.16.5? Are there any dev releases for it? Can u give the link (if any)? If there’s no link for download and it’s in github i guess it’s this : GitHub - SpongePowered/Sponge: The SpongeAPI implementation targeting vanilla Minecraft and 3rd party platforms. but i guess this is just the api (API 8)
and i can’t seem to build it, It shows error in build.gradle.kts can u please check it out?

and thanks! Oh yeah and if u check the SpongeAPI gradle problem it would be appreciated :grin:

these are the errors:
Error 1: Error 1 - Pastebin.com
Error 2: Error 2 - Pastebin.com
Error 3 : Error 3 - Pastebin.com

So this okay? :
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
if(src instanceof Player) {
Player player = (Player) src;
if(player.hasPermission(“testsponge.fly”)) {
if(player.get(Keys.GAME_MODE).equals(GameModes.SURVIVAL)) {
player.offer(Keys.CAN_FLY, true);
}
}
} return CommandResult.success();
}
}

For api 8, i would recommend looking at the announcements on this forum. They provide a link to sponge forge and sponge vanilla builds of api 8. Personally I get my sponge Vannila from the github actions (just out of habbit)

I belive

.get(Key.ANYTHING)

returns a optional and therefore equals will not work on it. I would recommend doing something like this

.get(Key.GAME_MODE).map(gm -> gm.equals(GameMode.SURVIVAL)).orElse(false)

What this does is gets the gamemode as a optional, then the map means that if it is present then do this to the value, in this case compare it to survival. Map also returns a optional as it doesnt know if the original value was there or not. You then say orElse which means if it cant find the gamemode, then treat it as false.

Other then that it looks good

Also, if your pasting code, use markdown’s code blocks, makes my life so much easier

Use three ` with the name of the lanage next to it, on the next line paste your code, then add a new line with three ` again. Resulting in this

@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    if(src instanceof Player) {
        Player player = (Player) src;
        if(player.hasPermission(“testsponge.fly”)) {
             if(player.get(Keys.GAME_MODE).equals(GameModes.SURVIVAL)) {
                player.offer(Keys.CAN_FLY, true);
             }
          }
      }
    return CommandResult.success();
  }
}

If I was being really padantic, I would rewrite this code as the following

public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
  if((src instanceof Player)){
    src.sendMessage(Text
      .builder("player only command")
      .color(TextColors.RED)
      .build());
    return CommandResult.success();
  }
  if(player
    .get(Keys.GAME_MODE)
    .map(gm -> gm.equals(GameModes.SURVIVAL))
    .orElse(false)
  ){
      player.offer(Keys.CAN_FLY, true);
  }
  return CommandResult.success();
}

as this has less nested ‘ifs’ making it a lot easier to read