mirror of
https://github.com/essentials/Essentials.git
synced 2025-08-19 04:52:30 +02:00
[Feature] pweather command
This commit is contained in:
@@ -0,0 +1,185 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.DescParseTickFormat;
|
||||
import static com.earth2me.essentials.I18n._;
|
||||
import com.earth2me.essentials.User;
|
||||
import java.util.*;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.WeatherType;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
public class Commandpweather extends EssentialsCommand
|
||||
{
|
||||
public static final Set<String> getAliases = new HashSet<String>();
|
||||
public static final Map<String, WeatherType> weatherAliases = new HashMap<String, WeatherType>();
|
||||
|
||||
static
|
||||
{
|
||||
getAliases.add("get");
|
||||
getAliases.add("list");
|
||||
getAliases.add("show");
|
||||
getAliases.add("display");
|
||||
weatherAliases.put("sun", WeatherType.CLEAR);
|
||||
weatherAliases.put("clear", WeatherType.CLEAR);
|
||||
weatherAliases.put("storm", WeatherType.DOWNFALL);
|
||||
weatherAliases.put("thunder", WeatherType.DOWNFALL);
|
||||
}
|
||||
|
||||
public Commandpweather()
|
||||
{
|
||||
super("pweather");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
|
||||
{
|
||||
// Which Players(s) / Users(s) are we interested in?
|
||||
String userSelector = null;
|
||||
if (args.length == 2)
|
||||
{
|
||||
userSelector = args[1];
|
||||
}
|
||||
Set<User> users = getUsers(server, sender, userSelector);
|
||||
|
||||
if (args.length == 0)
|
||||
{
|
||||
getUsersWeather(sender, users);
|
||||
return;
|
||||
}
|
||||
|
||||
if (getAliases.contains(args[0]))
|
||||
{
|
||||
getUsersWeather(sender, users);
|
||||
return;
|
||||
}
|
||||
|
||||
User user = ess.getUser(sender);
|
||||
if (user != null && (!users.contains(user) || users.size() > 1)&& !user.isAuthorized("essentials.pweather.others"))
|
||||
{
|
||||
user.sendMessage(_("pWeatherOthersPermission"));
|
||||
return;
|
||||
}
|
||||
|
||||
setUsersWeather(sender, users, args[0].toLowerCase());
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to get the time and inform
|
||||
*/
|
||||
private void getUsersWeather(final CommandSender sender, final Collection<User> users)
|
||||
{
|
||||
if (users.size() > 1)
|
||||
{
|
||||
sender.sendMessage(_("pWeatherPlayers"));
|
||||
}
|
||||
|
||||
for (User user : users)
|
||||
{
|
||||
if (user.getPlayerWeather() == null)
|
||||
{
|
||||
sender.sendMessage(_("pWeatherNormal", user.getName()));
|
||||
}
|
||||
else
|
||||
{
|
||||
sender.sendMessage(_("pWeatherCurrent", user.getName(), user.getPlayerWeather().toString().toLowerCase(Locale.ENGLISH)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to set the time and inform of the change
|
||||
*/
|
||||
private void setUsersWeather(final CommandSender sender, final Collection<User> users, final String weatherType ) throws Exception
|
||||
{
|
||||
|
||||
final StringBuilder msg = new StringBuilder();
|
||||
for (User user : users)
|
||||
{
|
||||
if (msg.length() > 0)
|
||||
{
|
||||
msg.append(", ");
|
||||
}
|
||||
|
||||
msg.append(user.getName());
|
||||
}
|
||||
|
||||
if (weatherType.equalsIgnoreCase("reset"))
|
||||
{
|
||||
for (User user : users)
|
||||
{
|
||||
user.resetPlayerWeather();
|
||||
}
|
||||
|
||||
sender.sendMessage(_("pWeatherReset", msg));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!weatherAliases.containsKey(weatherType))
|
||||
{
|
||||
throw new NotEnoughArgumentsException(_("pWeatherInvalidAlias"));
|
||||
}
|
||||
|
||||
for (User user : users)
|
||||
{
|
||||
user.setPlayerWeather(weatherAliases.get(weatherType));
|
||||
}
|
||||
sender.sendMessage(_("pWeatherSet", weatherType, msg.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to parse an argument of the type "users(s) selector"
|
||||
*/
|
||||
private Set<User> getUsers(final Server server, final CommandSender sender, final String selector) throws Exception
|
||||
{
|
||||
final Set<User> users = new TreeSet<User>(new UserNameComparator());
|
||||
// If there is no selector we want the sender itself. Or all users if sender isn't a user.
|
||||
if (selector == null)
|
||||
{
|
||||
final User user = ess.getUser(sender);
|
||||
if (user == null)
|
||||
{
|
||||
for (Player player : server.getOnlinePlayers())
|
||||
{
|
||||
users.add(ess.getUser(player));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
users.add(user);
|
||||
}
|
||||
return users;
|
||||
}
|
||||
|
||||
// Try to find the user with name = selector
|
||||
User user = null;
|
||||
final List<Player> matchedPlayers = server.matchPlayer(selector);
|
||||
if (!matchedPlayers.isEmpty())
|
||||
{
|
||||
user = ess.getUser(matchedPlayers.get(0));
|
||||
}
|
||||
|
||||
if (user != null)
|
||||
{
|
||||
users.add(user);
|
||||
}
|
||||
// If that fails, Is the argument something like "*" or "all"?
|
||||
else if (selector.equalsIgnoreCase("*") || selector.equalsIgnoreCase("all"))
|
||||
{
|
||||
for (Player player : server.getOnlinePlayers())
|
||||
{
|
||||
users.add(ess.getUser(player));
|
||||
}
|
||||
}
|
||||
// We failed to understand the world target...
|
||||
else
|
||||
{
|
||||
throw new Exception(_("playerNotFound"));
|
||||
}
|
||||
|
||||
return users;
|
||||
}
|
||||
}
|
@@ -524,3 +524,10 @@ playerBanIpAddress=\u00a76Player\u00a7c {0} \u00a76banned IP address {1}\u00a76.
|
||||
noPotionEffectPerm=\u00a74You do not have permission to apply potion effect \u00a7c{0} \u00a74to this potion.
|
||||
invalidPotionMeta=\u00a74Invalid potion meta: \u00a7c{0}\u00a74.
|
||||
balanceOther=\u00a7aBalance of {0}\u00a7a:\u00a7c {1}
|
||||
pWeatherCurrent=\u00a7c{0}\u00a76''s weather is\u00a7c {1}\u00a76.
|
||||
pWeatherNormal=\u00a7c{0}\u00a76''s weather is normal and matches the server.
|
||||
pWeatherOthersPermission=\u00a74You are not authorized to set other players' weather.
|
||||
pWeatherPlayers=\u00a76These players have their own weather:\u00a7r
|
||||
pWeatherReset=\u00a76Player weather has been reset for: \u00a7c{0}
|
||||
pWeatherSet=\u00a76Player weather is set to \u00a7c{0}\u00a76 for: \u00a7c{1}.
|
||||
pWeatherInvalidAlias=\u00a74Invalid weather type
|
||||
|
@@ -527,3 +527,10 @@ playerBanIpAddress=\u00a76Player\u00a7c {0} \u00a76banned IP address {1}\u00a76.
|
||||
noPotionEffectPerm=\u00a74You do not have permission to apply potion effect \u00a7c{0} \u00a74to this potion.
|
||||
invalidPotionMeta=\u00a74Invalid potion meta: \u00a7c{0}\u00a74.
|
||||
balanceOther=\u00a7aBalance of {0}\u00a7a:\u00a7c {1}
|
||||
pWeatherCurrent=\u00a7c{0}\u00a76''s weather is\u00a7c {1}\u00a76.
|
||||
pWeatherNormal=\u00a7c{0}\u00a76''s weather is normal and matches the server.
|
||||
pWeatherOthersPermission=\u00a74You are not authorized to set other players' weather.
|
||||
pWeatherPlayers=\u00a76These players have their own weather:\u00a7r
|
||||
pWeatherReset=\u00a76Player weather has been reset for: \u00a7c{0}
|
||||
pWeatherSet=\u00a76Player weather is set to \u00a7c{0}\u00a76 for: \u00a7c{1}.
|
||||
pWeatherInvalidAlias=\u00a74Invalid weather type
|
||||
|
@@ -524,3 +524,10 @@ playerBanIpAddress=\u00a76Player\u00a7c {0} \u00a76banned IP address {1}\u00a76.
|
||||
noPotionEffectPerm=\u00a74You do not have permission to apply potion effect \u00a7c{0} \u00a74to this potion.
|
||||
invalidPotionMeta=\u00a74Invalid potion meta: \u00a7c{0}\u00a74.
|
||||
balanceOther=\u00a7aBalance of {0}\u00a7a:\u00a7c {1}
|
||||
pWeatherCurrent=\u00a7c{0}\u00a76''s weather is\u00a7c {1}\u00a76.
|
||||
pWeatherNormal=\u00a7c{0}\u00a76''s weather is normal and matches the server.
|
||||
pWeatherOthersPermission=\u00a74You are not authorized to set other players' weather.
|
||||
pWeatherPlayers=\u00a76These players have their own weather:\u00a7r
|
||||
pWeatherReset=\u00a76Player weather has been reset for: \u00a7c{0}
|
||||
pWeatherSet=\u00a76Player weather is set to \u00a7c{0}\u00a76 for: \u00a7c{1}.
|
||||
pWeatherInvalidAlias=\u00a74Invalid weather type
|
||||
|
@@ -524,3 +524,10 @@ playerBanIpAddress=\u00a76Player\u00a7c {0} \u00a76banned IP address {1}\u00a76.
|
||||
noPotionEffectPerm=\u00a74You do not have permission to apply potion effect \u00a7c{0} \u00a74to this potion.
|
||||
invalidPotionMeta=\u00a74Invalid potion meta: \u00a7c{0}\u00a74.
|
||||
balanceOther=\u00a7aBalance of {0}\u00a7a:\u00a7c {1}
|
||||
pWeatherCurrent=\u00a7c{0}\u00a76''s weather is\u00a7c {1}\u00a76.
|
||||
pWeatherNormal=\u00a7c{0}\u00a76''s weather is normal and matches the server.
|
||||
pWeatherOthersPermission=\u00a74You are not authorized to set other players' weather.
|
||||
pWeatherPlayers=\u00a76These players have their own weather:\u00a7r
|
||||
pWeatherReset=\u00a76Player weather has been reset for: \u00a7c{0}
|
||||
pWeatherSet=\u00a76Player weather is set to \u00a7c{0}\u00a76 for: \u00a7c{1}.
|
||||
pWeatherInvalidAlias=\u00a74Invalid weather type
|
||||
|
@@ -524,3 +524,10 @@ playerBanIpAddress=\u00a76Player\u00a7c {0} \u00a76banned IP address {1}\u00a76.
|
||||
noPotionEffectPerm=\u00a74You do not have permission to apply potion effect \u00a7c{0} \u00a74to this potion.
|
||||
invalidPotionMeta=\u00a74Invalid potion meta: \u00a7c{0}\u00a74.
|
||||
balanceOther=\u00a7aBalance of {0}\u00a7a:\u00a7c {1}
|
||||
pWeatherCurrent=\u00a7c{0}\u00a76''s weather is\u00a7c {1}\u00a76.
|
||||
pWeatherNormal=\u00a7c{0}\u00a76''s weather is normal and matches the server.
|
||||
pWeatherOthersPermission=\u00a74You are not authorized to set other players' weather.
|
||||
pWeatherPlayers=\u00a76These players have their own weather:\u00a7r
|
||||
pWeatherReset=\u00a76Player weather has been reset for: \u00a7c{0}
|
||||
pWeatherSet=\u00a76Player weather is set to \u00a7c{0}\u00a76 for: \u00a7c{1}.
|
||||
pWeatherInvalidAlias=\u00a74Invalid weather type
|
||||
|
@@ -524,3 +524,10 @@ playerBanIpAddress=\u00a76Player\u00a7c {0} \u00a76banned IP address {1}\u00a76.
|
||||
noPotionEffectPerm=\u00a74You do not have permission to apply potion effect \u00a7c{0} \u00a74to this potion.
|
||||
invalidPotionMeta=\u00a74Invalid potion meta: \u00a7c{0}\u00a74.
|
||||
balanceOther=\u00a7aBalance of {0}\u00a7a:\u00a7c {1}
|
||||
pWeatherCurrent=\u00a7c{0}\u00a76''s weather is\u00a7c {1}\u00a76.
|
||||
pWeatherNormal=\u00a7c{0}\u00a76''s weather is normal and matches the server.
|
||||
pWeatherOthersPermission=\u00a74You are not authorized to set other players' weather.
|
||||
pWeatherPlayers=\u00a76These players have their own weather:\u00a7r
|
||||
pWeatherReset=\u00a76Player weather has been reset for: \u00a7c{0}
|
||||
pWeatherSet=\u00a76Player weather is set to \u00a7c{0}\u00a76 for: \u00a7c{1}.
|
||||
pWeatherInvalidAlias=\u00a74Invalid weather type
|
||||
|
@@ -524,3 +524,10 @@ playerBanIpAddress=\u00a76Player\u00a7c {0} \u00a76banned IP address {1}\u00a76.
|
||||
noPotionEffectPerm=\u00a74You do not have permission to apply potion effect \u00a7c{0} \u00a74to this potion.
|
||||
invalidPotionMeta=\u00a74Invalid potion meta: \u00a7c{0}\u00a74.
|
||||
balanceOther=\u00a7aBalance of {0}\u00a7a:\u00a7c {1}
|
||||
pWeatherCurrent=\u00a7c{0}\u00a76''s weather is\u00a7c {1}\u00a76.
|
||||
pWeatherNormal=\u00a7c{0}\u00a76''s weather is normal and matches the server.
|
||||
pWeatherOthersPermission=\u00a74You are not authorized to set other players' weather.
|
||||
pWeatherPlayers=\u00a76These players have their own weather:\u00a7r
|
||||
pWeatherReset=\u00a76Player weather has been reset for: \u00a7c{0}
|
||||
pWeatherSet=\u00a76Player weather is set to \u00a7c{0}\u00a76 for: \u00a7c{1}.
|
||||
pWeatherInvalidAlias=\u00a74Invalid weather type
|
||||
|
@@ -524,3 +524,10 @@ playerBanIpAddress=\u00a76Player\u00a7c {0} \u00a76banned IP address {1}\u00a76.
|
||||
noPotionEffectPerm=\u00a74You do not have permission to apply potion effect \u00a7c{0} \u00a74to this potion.
|
||||
invalidPotionMeta=\u00a74Invalid potion meta: \u00a7c{0}\u00a74.
|
||||
balanceOther=\u00a7aBalance of {0}\u00a7a:\u00a7c {1}
|
||||
pWeatherCurrent=\u00a7c{0}\u00a76''s weather is\u00a7c {1}\u00a76.
|
||||
pWeatherNormal=\u00a7c{0}\u00a76''s weather is normal and matches the server.
|
||||
pWeatherOthersPermission=\u00a74You are not authorized to set other players' weather.
|
||||
pWeatherPlayers=\u00a76These players have their own weather:\u00a7r
|
||||
pWeatherReset=\u00a76Player weather has been reset for: \u00a7c{0}
|
||||
pWeatherSet=\u00a76Player weather is set to \u00a7c{0}\u00a76 for: \u00a7c{1}.
|
||||
pWeatherInvalidAlias=\u00a74Invalid weather type
|
||||
|
@@ -524,3 +524,10 @@ playerBanIpAddress=\u00a76Player\u00a7c {0} \u00a76banned IP address {1}\u00a76.
|
||||
noPotionEffectPerm=\u00a74You do not have permission to apply potion effect \u00a7c{0} \u00a74to this potion.
|
||||
invalidPotionMeta=\u00a74Invalid potion meta: \u00a7c{0}\u00a74.
|
||||
balanceOther=\u00a7aBalance of {0}\u00a7a:\u00a7c {1}
|
||||
pWeatherCurrent=\u00a7c{0}\u00a76''s weather is\u00a7c {1}\u00a76.
|
||||
pWeatherNormal=\u00a7c{0}\u00a76''s weather is normal and matches the server.
|
||||
pWeatherOthersPermission=\u00a74You are not authorized to set other players' weather.
|
||||
pWeatherPlayers=\u00a76These players have their own weather:\u00a7r
|
||||
pWeatherReset=\u00a76Player weather has been reset for: \u00a7c{0}
|
||||
pWeatherSet=\u00a76Player weather is set to \u00a7c{0}\u00a76 for: \u00a7c{1}.
|
||||
pWeatherInvalidAlias=\u00a74Invalid weather type
|
||||
|
@@ -524,3 +524,10 @@ playerBanIpAddress=\u00a76Player\u00a7c {0} \u00a76banned IP address {1}\u00a76.
|
||||
noPotionEffectPerm=\u00a74You do not have permission to apply potion effect \u00a7c{0} \u00a74to this potion.
|
||||
invalidPotionMeta=\u00a74Invalid potion meta: \u00a7c{0}\u00a74.
|
||||
balanceOther=\u00a7aBalance of {0}\u00a7a:\u00a7c {1}
|
||||
pWeatherCurrent=\u00a7c{0}\u00a76''s weather is\u00a7c {1}\u00a76.
|
||||
pWeatherNormal=\u00a7c{0}\u00a76''s weather is normal and matches the server.
|
||||
pWeatherOthersPermission=\u00a74You are not authorized to set other players' weather.
|
||||
pWeatherPlayers=\u00a76These players have their own weather:\u00a7r
|
||||
pWeatherReset=\u00a76Player weather has been reset for: \u00a7c{0}
|
||||
pWeatherSet=\u00a76Player weather is set to \u00a7c{0}\u00a76 for: \u00a7c{1}.
|
||||
pWeatherInvalidAlias=\u00a74Invalid weather type
|
||||
|
@@ -524,3 +524,10 @@ playerBanIpAddress=\u00a77Gracz\u00a7c {0} \u00a77zostal zbanowany na adres IP {
|
||||
noPotionEffectPerm=\u00a74Nie masz praw by dodac efekt \u00a7c{0} \u00a74tej miksturze.
|
||||
invalidPotionMeta=\u00a74Niepoprawna wartosc mikstury: \u00a7c{0}\u00a74.
|
||||
balanceOther=\u00a7aBalance of {0}\u00a7a:\u00a7c {1}
|
||||
pWeatherCurrent=\u00a7c{0}\u00a76''s weather is\u00a7c {1}\u00a76.
|
||||
pWeatherNormal=\u00a7c{0}\u00a76''s weather is normal and matches the server.
|
||||
pWeatherOthersPermission=\u00a74You are not authorized to set other players' weather.
|
||||
pWeatherPlayers=\u00a76These players have their own weather:\u00a7r
|
||||
pWeatherReset=\u00a76Player weather has been reset for: \u00a7c{0}
|
||||
pWeatherSet=\u00a76Player weather is set to \u00a7c{0}\u00a76 for: \u00a7c{1}.
|
||||
pWeatherInvalidAlias=\u00a74Invalid weather type
|
||||
|
@@ -524,3 +524,10 @@ playerBanIpAddress=\u00a76Player\u00a7c {0} \u00a76banned IP address {1}\u00a76.
|
||||
noPotionEffectPerm=\u00a74You do not have permission to apply potion effect \u00a7c{0} \u00a74to this potion.
|
||||
invalidPotionMeta=\u00a74Invalid potion meta: \u00a7c{0}\u00a74.
|
||||
balanceOther=\u00a7aBalance of {0}\u00a7a:\u00a7c {1}
|
||||
pWeatherCurrent=\u00a7c{0}\u00a76''s weather is\u00a7c {1}\u00a76.
|
||||
pWeatherNormal=\u00a7c{0}\u00a76''s weather is normal and matches the server.
|
||||
pWeatherOthersPermission=\u00a74You are not authorized to set other players' weather.
|
||||
pWeatherPlayers=\u00a76These players have their own weather:\u00a7r
|
||||
pWeatherReset=\u00a76Player weather has been reset for: \u00a7c{0}
|
||||
pWeatherSet=\u00a76Player weather is set to \u00a7c{0}\u00a76 for: \u00a7c{1}.
|
||||
pWeatherInvalidAlias=\u00a74Invalid weather type
|
||||
|
@@ -524,3 +524,10 @@ playerBanIpAddress=\u00a76Player\u00a7c {0} \u00a76banned IP address {1}\u00a76.
|
||||
noPotionEffectPerm=\u00a74You do not have permission to apply potion effect \u00a7c{0} \u00a74to this potion.
|
||||
invalidPotionMeta=\u00a74Invalid potion meta: \u00a7c{0}\u00a74.
|
||||
balanceOther=\u00a7aBalance of {0}\u00a7a:\u00a7c {1}
|
||||
pWeatherCurrent=\u00a7c{0}\u00a76''s weather is\u00a7c {1}\u00a76.
|
||||
pWeatherNormal=\u00a7c{0}\u00a76''s weather is normal and matches the server.
|
||||
pWeatherOthersPermission=\u00a74You are not authorized to set other players' weather.
|
||||
pWeatherPlayers=\u00a76These players have their own weather:\u00a7r
|
||||
pWeatherReset=\u00a76Player weather has been reset for: \u00a7c{0}
|
||||
pWeatherSet=\u00a76Player weather is set to \u00a7c{0}\u00a76 for: \u00a7c{1}.
|
||||
pWeatherInvalidAlias=\u00a74Invalid weather type
|
||||
|
@@ -282,6 +282,10 @@ commands:
|
||||
description: Adjust player's client time. Add @ prefix to fix.
|
||||
usage: /<command> [list|reset|day|night|dawn|17:30|4pm|4000ticks] [player|*]
|
||||
aliases: [playertime,eplayertime,eptime]
|
||||
pweather:
|
||||
description: Adjust a player's weather
|
||||
usage: /<command> [list|reset|storm|sun|clear] [player|*]
|
||||
aliases: [playerweather,eplayerweather,epweather]
|
||||
r:
|
||||
description: Quickly reply to the last player to message you.
|
||||
usage: /<command> <message>
|
||||
|
Reference in New Issue
Block a user