2011-03-19 22:39:51 +00:00
|
|
|
package com.earth2me.essentials.commands;
|
|
|
|
|
2013-10-16 19:59:39 +00:00
|
|
|
import com.earth2me.essentials.CommandSource;
|
2011-03-19 22:39:51 +00:00
|
|
|
import com.earth2me.essentials.User;
|
2013-06-08 21:31:19 +00:00
|
|
|
import com.earth2me.essentials.utils.DateUtil;
|
2015-10-28 15:27:10 +00:00
|
|
|
import net.ess3.api.events.JailStatusChangeEvent;
|
2011-11-18 17:42:26 +00:00
|
|
|
import org.bukkit.Server;
|
2020-07-21 23:22:20 +00:00
|
|
|
import org.bukkit.event.player.PlayerTeleportEvent;
|
2011-03-19 22:39:51 +00:00
|
|
|
|
2017-06-11 00:17:43 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
2020-06-24 08:52:25 +00:00
|
|
|
import java.util.concurrent.CompletableFuture;
|
2017-06-11 00:17:43 +00:00
|
|
|
|
2015-04-15 04:06:16 +00:00
|
|
|
import static com.earth2me.essentials.I18n.tl;
|
|
|
|
|
|
|
|
public class Commandtogglejail extends EssentialsCommand {
|
|
|
|
public Commandtogglejail() {
|
|
|
|
super("togglejail");
|
|
|
|
}
|
2011-03-19 22:39:51 +00:00
|
|
|
|
2015-04-15 04:06:16 +00:00
|
|
|
@Override
|
|
|
|
public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception {
|
2020-08-11 18:09:22 +00:00
|
|
|
if (args.length == 0) {
|
2015-04-15 04:06:16 +00:00
|
|
|
throw new NotEnoughArgumentsException();
|
|
|
|
}
|
2011-03-19 22:39:51 +00:00
|
|
|
|
2015-04-15 04:06:16 +00:00
|
|
|
final User player = getPlayer(server, args, 0, true, true);
|
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
|
|
|
|
2015-04-15 04:06:16 +00:00
|
|
|
if (args.length >= 2 && !player.isJailed()) {
|
|
|
|
if (!player.getBase().isOnline()) {
|
|
|
|
if (sender.isPlayer() && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.togglejail.offline")) {
|
|
|
|
sender.sendMessage(tl("mayNotJailOffline"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2020-08-11 18:09:22 +00:00
|
|
|
|
|
|
|
if (player.isAuthorized("essentials.jail.exempt")) {
|
|
|
|
sender.sendMessage(tl("mayNotJail"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
final JailStatusChangeEvent event = new JailStatusChangeEvent(player, sender.isPlayer() ? ess.getUser(sender.getPlayer()) : null, true);
|
2015-10-28 15:27:10 +00:00
|
|
|
ess.getServer().getPluginManager().callEvent(event);
|
|
|
|
|
|
|
|
if (!event.isCancelled()) {
|
2020-06-24 08:52:25 +00:00
|
|
|
long preTimeDiff = 0;
|
|
|
|
if (args.length > 2) {
|
|
|
|
final String time = getFinalArg(args, 2);
|
|
|
|
preTimeDiff = DateUtil.parseDateDiff(time, true);
|
|
|
|
|
|
|
|
}
|
|
|
|
final long timeDiff = preTimeDiff;
|
2020-10-03 17:46:05 +00:00
|
|
|
final CompletableFuture<Boolean> future = getNewExceptionFuture(sender, commandLabel);
|
2020-06-24 08:52:25 +00:00
|
|
|
future.thenAccept(success -> {
|
|
|
|
if (success) {
|
|
|
|
player.setJailed(true);
|
|
|
|
player.sendMessage(tl("userJailed"));
|
|
|
|
player.setJail(null);
|
|
|
|
player.setJail(args[1]);
|
|
|
|
if (args.length > 2) {
|
|
|
|
player.setJailTimeout(timeDiff);
|
|
|
|
}
|
2020-10-03 17:46:05 +00:00
|
|
|
sender.sendMessage(timeDiff > 0 ? tl("playerJailedFor", player.getName(), DateUtil.formatDateDiff(timeDiff)) : tl("playerJailed", player.getName()));
|
2020-06-24 08:52:25 +00:00
|
|
|
}
|
|
|
|
});
|
2015-10-28 15:27:10 +00:00
|
|
|
if (player.getBase().isOnline()) {
|
2020-06-24 08:52:25 +00:00
|
|
|
ess.getJails().sendToJail(player, args[1], future);
|
2015-10-28 15:27:10 +00:00
|
|
|
} else {
|
|
|
|
// Check if jail exists
|
|
|
|
ess.getJails().getJail(args[1]);
|
2020-06-24 08:52:25 +00:00
|
|
|
future.complete(true);
|
2015-10-28 15:27:10 +00:00
|
|
|
}
|
2015-04-15 04:06:16 +00:00
|
|
|
}
|
|
|
|
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 21:07:30 +00:00
|
|
|
|
2015-04-15 04:06:16 +00:00
|
|
|
if (args.length >= 2 && player.isJailed() && !args[1].equalsIgnoreCase(player.getJail())) {
|
|
|
|
sender.sendMessage(tl("jailAlreadyIncarcerated", player.getJail()));
|
|
|
|
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 21:07:30 +00:00
|
|
|
|
2015-04-15 04:06:16 +00:00
|
|
|
if (args.length >= 2 && player.isJailed() && args[1].equalsIgnoreCase(player.getJail())) {
|
2020-08-11 18:09:22 +00:00
|
|
|
final long timeDiff = DateUtil.parseDateDiff(getFinalArg(args, 2), true);
|
2015-04-15 04:06:16 +00:00
|
|
|
player.setJailTimeout(timeDiff);
|
|
|
|
sender.sendMessage(tl("jailSentenceExtended", DateUtil.formatDateDiff(timeDiff)));
|
|
|
|
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 21:07:30 +00:00
|
|
|
|
2015-04-15 04:06:16 +00:00
|
|
|
if (args.length == 1 || (args.length == 2 && args[1].equalsIgnoreCase(player.getJail()))) {
|
|
|
|
if (!player.isJailed()) {
|
|
|
|
throw new NotEnoughArgumentsException();
|
|
|
|
}
|
2020-08-11 18:09:22 +00:00
|
|
|
|
|
|
|
final JailStatusChangeEvent event = new JailStatusChangeEvent(player, sender.isPlayer() ? ess.getUser(sender.getPlayer()) : null, false);
|
2015-10-28 15:27:10 +00:00
|
|
|
ess.getServer().getPluginManager().callEvent(event);
|
|
|
|
|
|
|
|
if (!event.isCancelled()) {
|
|
|
|
player.setJailed(false);
|
|
|
|
player.setJailTimeout(0);
|
|
|
|
player.sendMessage(tl("jailReleasedPlayerNotify"));
|
|
|
|
player.setJail(null);
|
2020-07-21 23:22:20 +00:00
|
|
|
if (player.getBase().isOnline() && ess.getSettings().isTeleportBackWhenFreedFromJail()) {
|
2020-10-03 17:46:05 +00:00
|
|
|
final CompletableFuture<Boolean> future = getNewExceptionFuture(sender, commandLabel);
|
2020-06-24 08:52:25 +00:00
|
|
|
player.getAsyncTeleport().back(future);
|
|
|
|
future.thenAccept(success -> {
|
|
|
|
if (success) {
|
|
|
|
sender.sendMessage(tl("jailReleased", player.getName()));
|
|
|
|
}
|
|
|
|
});
|
2020-07-21 23:22:20 +00:00
|
|
|
future.exceptionally(e -> {
|
|
|
|
player.getAsyncTeleport().respawn(null, PlayerTeleportEvent.TeleportCause.PLUGIN, new CompletableFuture<>());
|
|
|
|
sender.sendMessage(tl("jailReleased", player.getName()));
|
|
|
|
return false;
|
|
|
|
});
|
2020-06-24 08:52:25 +00:00
|
|
|
return;
|
2015-10-28 15:27:10 +00:00
|
|
|
}
|
|
|
|
sender.sendMessage(tl("jailReleased", player.getName()));
|
2015-04-15 04:06:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-06-11 00:17:43 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected List<String> getTabCompleteOptions(final Server server, final CommandSource sender, final String commandLabel, final String[] args) {
|
|
|
|
if (args.length == 1) {
|
|
|
|
return getPlayers(server, sender);
|
|
|
|
} else if (args.length == 2) {
|
|
|
|
try {
|
|
|
|
return new ArrayList<>(ess.getJails().getList());
|
2020-10-03 17:46:05 +00:00
|
|
|
} catch (final Exception e) {
|
2017-06-11 00:17:43 +00:00
|
|
|
return Collections.emptyList();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return COMMON_DATE_DIFFS;
|
|
|
|
}
|
|
|
|
}
|
2011-03-19 22:39:51 +00:00
|
|
|
}
|