Jump to content

Broadcast? And Op?


AndrewM16921

Recommended Posts

How do I broadcast a message to everyone on the server? If there isn't already functionality for that (though I imagine there is... somewhere), how would I get a list of all online players?

 

And, how do you determine if a player is opped? I saw something in CommandBase about command permission level. Not sure if that's involved in this, but I have no idea where to find that information. x.x

 

Also, as I am learning the api, I seem to have a lot of questions that seem trivial. I search through the code and checked the javadocs and still can't find answers a lot of the time. I hate resorting to ask a question as simple as this on the forum... what are other resources?

 

kthx.

Link to comment
Share on other sites

everything your looking for should be in the ServerConfigurationManager

 

to for example see if a player can use a command from a standard Player instance:

(EntityPlayerMP) playerVar..mcServer.getConfigurationManager().areCommandsAllowed(this.username);

 

this will ( on the server side ) cast player to the server sides multiplayer instance , get the server instance and then the configuration manager where it would return whether or not that player ( or any player with that name ) could use commands ( opped level ones, /me or /tell arnt included in that check )

Link to comment
Share on other sites

Alright, thanks. But say I need to determine if they're op for a non-command related thing, this is what I came up with... I think it'll work?

 

public class Util
{
public static boolean isOp(ICommandSender sender)
{
	return MinecraftServer.getServer().getConfigurationManager().getOps().contains(sender.getCommandSenderName());
}

public static EntityPlayerMP getPlayerExact(String username)
{
	return username == null ? null : MinecraftServer.getServer().getConfigurationManager().getPlayerForUsername(username);
}

public static EntityPlayerMP getPlayerBestMatch(String username)
{
	String bestMatch = null;
	for(String name : MinecraftServer.getServer().getAllUsernames())
	{
		if(name.equalsIgnoreCase(username))
		{
			bestMatch = name;
			break;
		}
		else
		{
			if(name.toLowerCase().startsWith(username.toLowerCase()))
			{
				bestMatch = name;
			}
		}
	}
	return getPlayerExact(bestMatch);
}

public static void broadcastMessage(String message)
{
	for(String name : MinecraftServer.getServer().getAllUsernames())
	{
		getPlayerExact(name).sendChatToPlayer(message);
	}
}

public static void sendInfo(ICommandSender sender, String message)
{
	sender.sendChatToPlayer(ChatFormat.YELLOW + message);
}

public static void sendError(ICommandSender sender, String message)
{
	sender.sendChatToPlayer(ChatFormat.RED + message);
}
}

 

Gonna test it out in a bit. But, yeah.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.