2011-03-19 23:39:51 +01:00
|
|
|
package com.earth2me.essentials.commands;
|
|
|
|
|
2013-10-16 21:59:39 +02:00
|
|
|
import com.earth2me.essentials.CommandSource;
|
2021-06-09 03:04:30 +02:00
|
|
|
import com.earth2me.essentials.ISettings;
|
2011-03-19 23:39:51 +01:00
|
|
|
import com.earth2me.essentials.User;
|
2024-02-04 03:13:18 +01:00
|
|
|
import com.earth2me.essentials.utils.AdventureUtil;
|
2013-06-08 23:31:19 +02:00
|
|
|
import com.earth2me.essentials.utils.DateUtil;
|
2021-01-08 21:43:32 +01:00
|
|
|
import com.earth2me.essentials.utils.EnumUtil;
|
2021-02-05 20:39:20 +01:00
|
|
|
import com.google.common.collect.Iterables;
|
2015-10-28 16:27:10 +01:00
|
|
|
import net.ess3.api.events.JailStatusChangeEvent;
|
2011-11-18 18:42:26 +01:00
|
|
|
import org.bukkit.Server;
|
2021-01-08 21:43:32 +01:00
|
|
|
import org.bukkit.Statistic;
|
2020-07-22 01:22:20 +02:00
|
|
|
import org.bukkit.event.player.PlayerTeleportEvent;
|
2011-03-19 23:39:51 +01:00
|
|
|
|
2017-06-11 02:17:43 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
2020-06-24 10:52:25 +02:00
|
|
|
import java.util.concurrent.CompletableFuture;
|
2021-10-23 21:18:51 +02:00
|
|
|
import java.util.logging.Level;
|
2017-06-11 02:17:43 +02:00
|
|
|
|
2024-02-03 21:38:14 +01:00
|
|
|
import static com.earth2me.essentials.I18n.tlLiteral;
|
2015-04-15 06:06:16 +02:00
|
|
|
|
|
|
|
public class Commandtogglejail extends EssentialsCommand {
|
2021-01-08 21:43:32 +01:00
|
|
|
private static final Statistic PLAY_ONE_TICK = EnumUtil.getStatistic("PLAY_ONE_MINUTE", "PLAY_ONE_TICK");
|
|
|
|
|
2015-04-15 06:06:16 +02:00
|
|
|
public Commandtogglejail() {
|
|
|
|
super("togglejail");
|
|
|
|
}
|
2011-03-19 23:39:51 +01:00
|
|
|
|
2015-04-15 06:06:16 +02:00
|
|
|
@Override
|
|
|
|
public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception {
|
2020-08-11 20:09:22 +02:00
|
|
|
if (args.length == 0) {
|
2015-04-15 06:06:16 +02:00
|
|
|
throw new NotEnoughArgumentsException();
|
|
|
|
}
|
2011-03-19 23:39:51 +01:00
|
|
|
|
2015-04-15 06:06:16 +02: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 23:07:30 +02:00
|
|
|
|
2021-02-05 20:39:20 +01:00
|
|
|
mainCommand:
|
|
|
|
if (!player.isJailed()) {
|
2015-04-15 06:06:16 +02:00
|
|
|
if (!player.getBase().isOnline()) {
|
|
|
|
if (sender.isPlayer() && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.togglejail.offline")) {
|
2024-02-03 21:38:14 +01:00
|
|
|
sender.sendTl("mayNotJailOffline");
|
2015-04-15 06:06:16 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2020-08-11 20:09:22 +02:00
|
|
|
|
|
|
|
if (player.isAuthorized("essentials.jail.exempt")) {
|
2024-02-03 21:38:14 +01:00
|
|
|
sender.sendTl("mayNotJail");
|
2020-08-11 20:09:22 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-02-05 20:39:20 +01:00
|
|
|
final String jailName;
|
|
|
|
if (args.length > 1) {
|
|
|
|
jailName = args[1];
|
|
|
|
} else if (ess.getJails().getCount() == 1) {
|
|
|
|
jailName = Iterables.get(ess.getJails().getList(), 0);
|
|
|
|
} else {
|
|
|
|
break mainCommand;
|
|
|
|
}
|
|
|
|
// Check if jail exists
|
|
|
|
ess.getJails().getJail(jailName);
|
|
|
|
|
2020-08-11 20:09:22 +02:00
|
|
|
final JailStatusChangeEvent event = new JailStatusChangeEvent(player, sender.isPlayer() ? ess.getUser(sender.getPlayer()) : null, true);
|
2015-10-28 16:27:10 +01:00
|
|
|
ess.getServer().getPluginManager().callEvent(event);
|
|
|
|
|
|
|
|
if (!event.isCancelled()) {
|
2021-01-08 21:43:32 +01:00
|
|
|
long displayTime = 0;
|
2020-06-24 10:52:25 +02:00
|
|
|
long preTimeDiff = 0;
|
|
|
|
if (args.length > 2) {
|
|
|
|
final String time = getFinalArg(args, 2);
|
2021-01-08 21:43:32 +01:00
|
|
|
displayTime = DateUtil.parseDateDiff(time, true);
|
|
|
|
preTimeDiff = DateUtil.parseDateDiff(time, true, ess.getSettings().isJailOnlineTime());
|
2020-06-24 10:52:25 +02:00
|
|
|
}
|
|
|
|
final long timeDiff = preTimeDiff;
|
2021-01-08 21:43:32 +01:00
|
|
|
final long finalDisplayTime = displayTime;
|
2020-10-03 19:46:05 +02:00
|
|
|
final CompletableFuture<Boolean> future = getNewExceptionFuture(sender, commandLabel);
|
2020-06-24 10:52:25 +02:00
|
|
|
future.thenAccept(success -> {
|
|
|
|
if (success) {
|
|
|
|
player.setJailed(true);
|
2024-02-03 21:38:14 +01:00
|
|
|
player.sendTl("userJailed");
|
2020-06-24 10:52:25 +02:00
|
|
|
player.setJail(null);
|
2021-02-05 20:39:20 +01:00
|
|
|
player.setJail(jailName);
|
2020-06-24 10:52:25 +02:00
|
|
|
if (args.length > 2) {
|
|
|
|
player.setJailTimeout(timeDiff);
|
2021-02-16 14:56:57 +01:00
|
|
|
// 50 MSPT (milliseconds per tick)
|
2021-01-08 21:43:32 +01:00
|
|
|
player.setOnlineJailedTime(ess.getSettings().isJailOnlineTime() ? ((player.getBase().getStatistic(PLAY_ONE_TICK)) + (timeDiff / 50)) : 0);
|
2020-06-24 10:52:25 +02:00
|
|
|
}
|
2021-10-23 21:18:51 +02:00
|
|
|
|
2024-02-03 21:38:14 +01:00
|
|
|
final String tlKey;
|
|
|
|
final Object[] objects;
|
|
|
|
if (timeDiff > 0) {
|
|
|
|
tlKey = "jailNotifyJailedFor";
|
|
|
|
objects = new Object[]{player.getName(), DateUtil.formatDateDiff(finalDisplayTime)};
|
|
|
|
sender.sendTl("playerJailedFor", player.getName(), DateUtil.formatDateDiff(finalDisplayTime));
|
|
|
|
} else {
|
|
|
|
tlKey = "jailNotifyJailed";
|
|
|
|
objects = new Object[]{player.getName(), sender.getSender().getName()};
|
|
|
|
sender.sendTl("playerJailed", player.getName());
|
|
|
|
}
|
|
|
|
|
2024-02-04 03:13:18 +01:00
|
|
|
ess.getLogger().log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral(tlKey, objects)));
|
2024-02-03 21:38:14 +01:00
|
|
|
ess.broadcastTl(null, "essentials.jail.notify", tlKey, objects);
|
2020-06-24 10:52:25 +02:00
|
|
|
}
|
|
|
|
});
|
2015-10-28 16:27:10 +01:00
|
|
|
if (player.getBase().isOnline()) {
|
2021-02-05 20:39:20 +01:00
|
|
|
ess.getJails().sendToJail(player, jailName, future);
|
2015-10-28 16:27:10 +01:00
|
|
|
} else {
|
2020-06-24 10:52:25 +02:00
|
|
|
future.complete(true);
|
2015-10-28 16:27:10 +01:00
|
|
|
}
|
2015-04-15 06:06:16 +02: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 23:07:30 +02:00
|
|
|
|
2015-04-15 06:06:16 +02:00
|
|
|
if (args.length >= 2 && player.isJailed() && !args[1].equalsIgnoreCase(player.getJail())) {
|
2024-02-03 21:38:14 +01:00
|
|
|
sender.sendTl("jailAlreadyIncarcerated", player.getJail());
|
2015-04-15 06:06:16 +02: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 23:07:30 +02:00
|
|
|
|
2015-04-15 06:06:16 +02:00
|
|
|
if (args.length >= 2 && player.isJailed() && args[1].equalsIgnoreCase(player.getJail())) {
|
2021-02-16 14:56:57 +01:00
|
|
|
final String unparsedTime = getFinalArg(args, 2);
|
|
|
|
final long displayTimeDiff = DateUtil.parseDateDiff(unparsedTime, true);
|
|
|
|
final long timeDiff = DateUtil.parseDateDiff(unparsedTime, true, ess.getSettings().isJailOnlineTime());
|
2015-04-15 06:06:16 +02:00
|
|
|
player.setJailTimeout(timeDiff);
|
2021-02-16 14:56:57 +01:00
|
|
|
player.setOnlineJailedTime(ess.getSettings().isJailOnlineTime() ? ((player.getBase().getStatistic(PLAY_ONE_TICK)) + (timeDiff / 50)) : 0);
|
2024-02-03 21:38:14 +01:00
|
|
|
sender.sendTl("jailSentenceExtended", DateUtil.formatDateDiff(displayTimeDiff));
|
2021-10-23 21:18:51 +02:00
|
|
|
|
2024-02-03 21:38:14 +01:00
|
|
|
final String tlKey = "jailNotifySentenceExtended";
|
|
|
|
final Object[] objects = new Object[]{player.getName(), DateUtil.formatDateDiff(displayTimeDiff), sender.getSender().getName()};
|
2024-02-04 03:13:18 +01:00
|
|
|
ess.getLogger().log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral(tlKey, objects)));
|
2024-02-03 21:38:14 +01:00
|
|
|
ess.broadcastTl(null, "essentials.jail.notify", tlKey, objects);
|
2015-04-15 06:06:16 +02: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 23:07:30 +02:00
|
|
|
|
2015-04-15 06:06:16 +02:00
|
|
|
if (args.length == 1 || (args.length == 2 && args[1].equalsIgnoreCase(player.getJail()))) {
|
|
|
|
if (!player.isJailed()) {
|
|
|
|
throw new NotEnoughArgumentsException();
|
|
|
|
}
|
2020-08-11 20:09:22 +02:00
|
|
|
|
|
|
|
final JailStatusChangeEvent event = new JailStatusChangeEvent(player, sender.isPlayer() ? ess.getUser(sender.getPlayer()) : null, false);
|
2015-10-28 16:27:10 +01:00
|
|
|
ess.getServer().getPluginManager().callEvent(event);
|
|
|
|
|
|
|
|
if (!event.isCancelled()) {
|
|
|
|
player.setJailed(false);
|
|
|
|
player.setJailTimeout(0);
|
2024-02-03 21:38:14 +01:00
|
|
|
player.sendTl("jailReleasedPlayerNotify");
|
2015-10-28 16:27:10 +01:00
|
|
|
player.setJail(null);
|
2021-06-09 03:04:30 +02:00
|
|
|
if (player.getBase().isOnline()) {
|
2020-10-03 19:46:05 +02:00
|
|
|
final CompletableFuture<Boolean> future = getNewExceptionFuture(sender, commandLabel);
|
2020-06-24 10:52:25 +02:00
|
|
|
future.thenAccept(success -> {
|
|
|
|
if (success) {
|
2024-02-03 21:38:14 +01:00
|
|
|
sender.sendTl("jailReleased", player.getName());
|
2020-06-24 10:52:25 +02:00
|
|
|
}
|
|
|
|
});
|
2021-06-09 03:04:30 +02:00
|
|
|
if (ess.getSettings().getTeleportWhenFreePolicy() == ISettings.TeleportWhenFreePolicy.BACK) {
|
|
|
|
player.getAsyncTeleport().back(future);
|
|
|
|
future.exceptionally(e -> {
|
|
|
|
player.getAsyncTeleport().respawn(null, PlayerTeleportEvent.TeleportCause.PLUGIN, new CompletableFuture<>());
|
2024-02-03 21:38:14 +01:00
|
|
|
sender.sendTl("jailReleased", player.getName());
|
2021-06-09 03:04:30 +02:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
} else if (ess.getSettings().getTeleportWhenFreePolicy() == ISettings.TeleportWhenFreePolicy.SPAWN) {
|
|
|
|
player.getAsyncTeleport().respawn(null, PlayerTeleportEvent.TeleportCause.PLUGIN, future);
|
|
|
|
}
|
2020-06-24 10:52:25 +02:00
|
|
|
return;
|
2015-10-28 16:27:10 +01:00
|
|
|
}
|
2024-02-03 21:38:14 +01:00
|
|
|
sender.sendTl("jailReleased", player.getName());
|
2015-04-15 06:06:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-06-11 02:17:43 +02: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 19:46:05 +02:00
|
|
|
} catch (final Exception e) {
|
2017-06-11 02:17:43 +02:00
|
|
|
return Collections.emptyList();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return COMMON_DATE_DIFFS;
|
|
|
|
}
|
|
|
|
}
|
2011-03-19 23:39:51 +01:00
|
|
|
}
|