Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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.

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 )

  • Author

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.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.