2011-03-30 04:03:21 +00:00
|
|
|
package com.earth2me.essentials.commands;
|
|
|
|
|
2012-12-20 20:01:43 +00:00
|
|
|
import com.earth2me.essentials.ChargeException;
|
2011-11-21 01:55:26 +00:00
|
|
|
import static com.earth2me.essentials.I18n._;
|
2011-06-13 13:05:11 +00:00
|
|
|
import com.earth2me.essentials.Trade;
|
2011-03-30 04:03:21 +00:00
|
|
|
import com.earth2me.essentials.User;
|
2011-11-18 17:42:26 +00:00
|
|
|
import org.bukkit.Server;
|
2011-12-07 01:12:36 +00:00
|
|
|
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
2011-03-30 04:03:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
public class Commandtpaccept extends EssentialsCommand
|
|
|
|
{
|
|
|
|
public Commandtpaccept()
|
|
|
|
{
|
|
|
|
super("tpaccept");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2011-11-15 21:47:02 +00:00
|
|
|
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
|
2011-03-30 04:03:21 +00: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 21:07:30 +00:00
|
|
|
|
2011-11-15 21:47:02 +00:00
|
|
|
final User target = user.getTeleportRequest();
|
2012-03-20 13:26:49 +00:00
|
|
|
|
2012-03-20 14:32:11 +00:00
|
|
|
if (target == null || !target.isOnline())
|
|
|
|
{
|
|
|
|
throw new Exception(_("noPendingRequest"));
|
|
|
|
}
|
|
|
|
|
2012-03-27 14:28:40 +00:00
|
|
|
if (user.isTpRequestHere() && ((!target.isAuthorized("essentials.tpahere") && !target.isAuthorized("essentials.tpaall"))
|
|
|
|
|| (user.getWorld() != target.getWorld() && ess.getSettings().isWorldTeleportPermissions()
|
2012-09-08 21:50:20 +00:00
|
|
|
&& !user.isAuthorized("essentials.worlds." + user.getWorld().getName()))))
|
2012-03-20 14:32:11 +00:00
|
|
|
{
|
|
|
|
throw new Exception(_("noPendingRequest"));
|
|
|
|
}
|
|
|
|
|
2012-03-27 14:28:40 +00:00
|
|
|
if (!user.isTpRequestHere() && (!target.isAuthorized("essentials.tpa")
|
2012-03-20 14:32:11 +00:00
|
|
|
|| (user.getWorld() != target.getWorld() && ess.getSettings().isWorldTeleportPermissions()
|
2012-09-08 21:50:20 +00:00
|
|
|
&& !user.isAuthorized("essentials.worlds." + target.getWorld().getName()))))
|
2012-03-20 14:32:11 +00:00
|
|
|
{
|
|
|
|
throw new Exception(_("noPendingRequest"));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args.length > 0 && !target.getName().contains(args[0]))
|
2012-01-29 04:59:30 +00:00
|
|
|
{
|
|
|
|
throw new Exception(_("noPendingRequest"));
|
|
|
|
}
|
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 21:07:30 +00:00
|
|
|
|
2011-12-08 23:43:09 +00:00
|
|
|
long timeout = ess.getSettings().getTpaAcceptCancellation();
|
|
|
|
if (timeout != 0 && (System.currentTimeMillis() - user.getTeleportRequestTime()) / 1000 > timeout)
|
|
|
|
{
|
|
|
|
user.requestTeleport(null, false);
|
|
|
|
throw new Exception(_("requestTimedOut"));
|
|
|
|
}
|
|
|
|
|
2011-11-15 21:47:02 +00:00
|
|
|
final Trade charge = new Trade(this.getName(), ess);
|
2011-11-21 01:55:26 +00:00
|
|
|
user.sendMessage(_("requestAccepted"));
|
|
|
|
target.sendMessage(_("requestAcceptedFrom", user.getDisplayName()));
|
2011-11-15 21:47:02 +00:00
|
|
|
|
2012-12-20 20:01:43 +00:00
|
|
|
try
|
2011-03-30 04:03:21 +00:00
|
|
|
{
|
2012-12-20 20:01:43 +00:00
|
|
|
if (user.isTpRequestHere())
|
|
|
|
{
|
|
|
|
target.getTeleport().teleportToMe(user, charge, TeleportCause.COMMAND);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
target.getTeleport().teleport(user, charge, TeleportCause.COMMAND);
|
|
|
|
}
|
2011-03-30 04:03:21 +00:00
|
|
|
}
|
2012-12-20 20:01:43 +00:00
|
|
|
catch (ChargeException ex)
|
2011-03-30 04:03:21 +00:00
|
|
|
{
|
2012-12-20 20:01:43 +00:00
|
|
|
user.sendMessage(_("pendingTeleportCancelled"));
|
|
|
|
ess.showError(target, ex, commandLabel);
|
2011-03-30 04:03:21 +00: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 21:07:30 +00:00
|
|
|
user.requestTeleport(null, false);
|
2012-09-29 02:59:31 +00:00
|
|
|
throw new NoChargeException();
|
2011-03-30 04:03:21 +00:00
|
|
|
}
|
|
|
|
}
|