Hi there guys !
Quite a long time ago, I posted a request here where I asked if it would be possible to create a Dice Roll plugin. Since that time, I began to code and today I tried to do this plugin by myself. Everything’s fine, except for a little detail…
I wanted to broadcast the result 50 blocks around the player who entered the command, but I can’t even seem to find how to broadcast it on the server. I arrived to send it to the player, but there’s no point if only him/her can see it !
So, I would like to know how do you guys can do it ^x^’ ! I’m quite new to this, so I’m sorry if it seems a little silly for a question.
Hope one of you will answer me ^^ !
To those who’d need to see my code, it actually looks like this (I give you here the “disfunctional one”, which needs to send a message to everyone 50 blocks around .x. Please don’t mind the french !) :
The command class :
package Salveria;
import org.spongepowered.api.Server;
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.command.spec.CommandExecutor;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.format.TextColors;
import org.spongepowered.api.text.format.TextStyles;
public class SalveRollExecutor implements CommandExecutor {
public static double random() {
double random;
random = Math.random() * 20 + 1;
if (random == 21)
random = Math.random() * 20 + 1;
return random;
}
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
if(!(src instanceof Player)) {
src.sendMessage(Text.of("C'est un joueur qui doit lancer la commande !"));
return CommandResult.success();
}
Player player = (Player)src;
Server server = (Server)src;
int tirage = (int) random();
server.get().broadcastMessage(Text.of(TextColors.WHITE, server.getPlayer(player.getUniqueId()), " a Roll un ", TextColors.RED, TextStyles.BOLD, tirage, TextStyles.NONE, TextColors.WHITE, " !"));
server.get
return CommandResult.success();
}
}
The main class :
package Salveria;
import org.spongepowered.api.Game;
import org.spongepowered.api.command.spec.CommandSpec;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.game.state.GameInitializationEvent;
import org.spongepowered.api.plugin.Plugin;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.event.command.SendCommandEvent;
import javax.inject.Inject;
@Plugin(id = “rollplugin”, name=“SalveRollia”, version = “1.0”)
public class SalveRoll {
@Inject
Game game;
@Listener
public void onInit(GameInitializationEvent e) {
CommandSpec RollCmd = CommandSpec.builder()
.description(Text.of("Commande de Roll pour Salveria"))
.executor(new SalveRollExecutor())
.build();
game.getCommandManager().register(this, RollCmd, "roll");
}
}