2011-03-19 23:39:51 +01:00
|
|
|
package com.earth2me.essentials.chat;
|
|
|
|
|
|
|
|
import com.earth2me.essentials.Essentials;
|
|
|
|
import com.earth2me.essentials.User;
|
2011-05-10 21:57:59 +02:00
|
|
|
import com.earth2me.essentials.Util;
|
2011-03-19 23:39:51 +01:00
|
|
|
import com.nijikokun.bukkit.Permissions.Permissions;
|
|
|
|
import java.util.logging.Logger;
|
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.Server;
|
2011-04-05 18:59:46 +02:00
|
|
|
import org.bukkit.World;
|
2011-03-19 23:39:51 +01:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.event.player.PlayerChatEvent;
|
|
|
|
import org.bukkit.event.player.PlayerEvent;
|
|
|
|
import org.bukkit.event.player.PlayerRespawnEvent;
|
|
|
|
|
|
|
|
|
|
|
|
public class EssentialsChatWorker
|
|
|
|
{
|
|
|
|
private static final Logger logger = Logger.getLogger("Minecraft");
|
|
|
|
|
|
|
|
public static void onPlayerRespawn(Server server, PlayerRespawnEvent event)
|
|
|
|
{
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 23:07:30 +02:00
|
|
|
User user = Essentials.getStatic().getUser(event.getPlayer());
|
2011-03-19 23:39:51 +01:00
|
|
|
updateDisplayName(user);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void onPlayerJoin(Server server, PlayerEvent event)
|
|
|
|
{
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 23:07:30 +02:00
|
|
|
User user = Essentials.getStatic().getUser(event.getPlayer());
|
2011-03-19 23:39:51 +01:00
|
|
|
updateDisplayName(user);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void updateDisplayName(User user)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
String group = user.getGroup();
|
|
|
|
try
|
|
|
|
{
|
|
|
|
String prefix = Permissions.Security.getGroupPrefix(user.getWorld().getName(), group).replace('&', '§').replace("{WORLDNAME}", user.getWorld().getName());
|
|
|
|
String suffix = Permissions.Security.getGroupSuffix(user.getWorld().getName(), group).replace('&', '§').replace("{WORLDNAME}", user.getWorld().getName());
|
2011-04-01 12:15:49 +02:00
|
|
|
|
2011-04-02 00:46:27 +02:00
|
|
|
user.setDisplayName(prefix + user.getNick() + suffix + (suffix.length() > 1 && suffix.substring(suffix.length() -2).equals("§") ? "" : "§f"));
|
2011-03-19 23:39:51 +01:00
|
|
|
}
|
|
|
|
catch (Throwable ex)
|
|
|
|
{
|
2011-05-10 21:57:59 +02:00
|
|
|
logger.warning(Util.format("missingPrefixSuffix", group));
|
2011-03-19 23:39:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Throwable ex)
|
|
|
|
{
|
2011-05-10 21:57:59 +02:00
|
|
|
logger.warning(Util.i18n("permissionsError"));
|
2011-03-19 23:39:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void onPlayerChat(Server server, PlayerChatEvent event)
|
|
|
|
{
|
2011-03-30 14:56:34 +02:00
|
|
|
if (event.isCancelled()) return;
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 23:07:30 +02:00
|
|
|
User user = Essentials.getStatic().getUser(event.getPlayer());
|
2011-03-19 23:39:51 +01:00
|
|
|
updateDisplayName(user);
|
|
|
|
|
|
|
|
if (user.isAuthorized("essentials.chat.color"))
|
|
|
|
event.setMessage(event.getMessage().replaceAll("&([0-9a-f])", "§$1"));
|
2011-03-30 14:56:34 +02:00
|
|
|
|
2011-06-06 01:56:52 +02:00
|
|
|
event.setFormat(Essentials.getStatic().getSettings().getChatFormat(user.getGroup()).replace('&', '§').replace("§§", "&").replace("{DISPLAYNAME}", "%1$s").replace("{GROUP}", user.getGroup()).replace("{MESSAGE}", "%2$s").replace("{WORLDNAME}", user.getWorld().getName()).replace("{SHORTWORLDNAME}", user.getWorld().getName().substring(0, 1).toUpperCase()));
|
2011-03-30 14:56:34 +02:00
|
|
|
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 23:07:30 +02:00
|
|
|
int radius = Essentials.getStatic().getSettings().getChatRadius();
|
2011-03-19 23:39:51 +01:00
|
|
|
if (radius < 1) return;
|
|
|
|
|
|
|
|
if (event.getMessage().startsWith("!") && event.getMessage().length() > 1)
|
|
|
|
{
|
|
|
|
if (user.isAuthorized("essentials.chat.shout"))
|
|
|
|
{
|
|
|
|
event.setMessage(event.getMessage().substring(1));
|
2011-05-10 21:57:59 +02:00
|
|
|
event.setFormat(Util.format("shoutFormat", event.getFormat()));
|
2011-03-19 23:39:51 +01:00
|
|
|
return;
|
|
|
|
}
|
2011-05-10 21:57:59 +02:00
|
|
|
user.sendMessage(Util.i18n("notAllowedToShout"));
|
2011-03-19 23:39:51 +01:00
|
|
|
event.setCancelled(true);
|
|
|
|
return;
|
|
|
|
}
|
2011-03-30 14:56:34 +02:00
|
|
|
|
2011-03-19 23:39:51 +01:00
|
|
|
if (event.getMessage().startsWith("?") && event.getMessage().length() > 1)
|
|
|
|
{
|
|
|
|
if (user.isAuthorized("essentials.chat.question"))
|
|
|
|
{
|
|
|
|
event.setMessage(event.getMessage().substring(1));
|
2011-05-10 21:57:59 +02:00
|
|
|
event.setFormat(Util.format("questionFormat", event.getFormat()));
|
2011-03-19 23:39:51 +01:00
|
|
|
return;
|
|
|
|
}
|
2011-05-10 21:57:59 +02:00
|
|
|
user.sendMessage(Util.i18n("notAllowedToQuestion"));
|
2011-03-19 23:39:51 +01:00
|
|
|
event.setCancelled(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
event.setCancelled(true);
|
2011-05-10 21:57:59 +02:00
|
|
|
logger.info(Util.format("localFormat", user.getName(), event.getMessage()));
|
2011-03-19 23:39:51 +01:00
|
|
|
|
|
|
|
Location loc = user.getLocation();
|
2011-04-05 18:59:46 +02:00
|
|
|
World w = loc.getWorld();
|
2011-03-19 23:39:51 +01:00
|
|
|
int x = loc.getBlockX();
|
|
|
|
int y = loc.getBlockY();
|
|
|
|
int z = loc.getBlockZ();
|
|
|
|
|
|
|
|
for (Player p : server.getOnlinePlayers())
|
|
|
|
{
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 23:07:30 +02:00
|
|
|
User u = Essentials.getStatic().getUser(p);
|
2011-05-15 14:27:23 +02:00
|
|
|
if (u.isIgnoredPlayer(user.getName()) && !user.isOp()) {
|
|
|
|
continue;
|
|
|
|
}
|
2011-03-19 23:39:51 +01:00
|
|
|
if (u != user && !u.isAuthorized("essentials.chat.spy"))
|
|
|
|
{
|
|
|
|
Location l = u.getLocation();
|
|
|
|
int dx = Math.abs(x - l.getBlockX());
|
|
|
|
int dy = Math.abs(y - l.getBlockY());
|
|
|
|
int dz = Math.abs(z - l.getBlockZ());
|
|
|
|
int delta = dx + dy + dz;
|
2011-04-05 18:59:46 +02:00
|
|
|
if (delta > radius || w != l.getWorld()) continue;
|
2011-03-19 23:39:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
u.sendMessage(String.format(event.getFormat(), user.getDisplayName(), event.getMessage()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|