2011-03-30 06:03:21 +02:00
|
|
|
package com.earth2me.essentials.commands;
|
|
|
|
|
2013-10-16 21:59:39 +02:00
|
|
|
import com.earth2me.essentials.CommandSource;
|
2011-06-13 15:05:11 +02:00
|
|
|
import com.earth2me.essentials.Trade;
|
2011-03-30 06:03:21 +02:00
|
|
|
import com.earth2me.essentials.User;
|
2015-06-05 04:32:36 +02:00
|
|
|
import com.earth2me.essentials.utils.FloatUtil;
|
2017-06-11 02:17:43 +02:00
|
|
|
import com.google.common.collect.Lists;
|
2011-11-18 18:42:26 +01:00
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.Server;
|
2017-06-11 02:17:43 +02:00
|
|
|
import org.bukkit.World;
|
2011-12-07 02:12:36 +01:00
|
|
|
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
2011-03-30 06:03:21 +02:00
|
|
|
|
2017-06-11 02:17:43 +02:00
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
|
|
|
|
2015-04-15 06:06:16 +02:00
|
|
|
import static com.earth2me.essentials.I18n.tl;
|
|
|
|
|
2011-03-30 06:03:21 +02:00
|
|
|
|
2015-04-15 06:06:16 +02:00
|
|
|
public class Commandtppos extends EssentialsCommand {
|
|
|
|
public Commandtppos() {
|
|
|
|
super("tppos");
|
|
|
|
}
|
2011-03-30 06:03:21 +02:00
|
|
|
|
2015-04-15 06:06:16 +02:00
|
|
|
@Override
|
|
|
|
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
|
|
|
|
if (args.length < 3) {
|
|
|
|
throw new NotEnoughArgumentsException();
|
|
|
|
}
|
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-07-17 00:36:10 +02:00
|
|
|
final double x = args[0].startsWith("~") ? user.getLocation().getX() + (args[0].length() > 1 ? Integer.parseInt(args[0].substring(1)) : 0) : Integer.parseInt(args[0]);
|
|
|
|
final double y = args[1].startsWith("~") ? user.getLocation().getY() + (args[1].length() > 1 ? Integer.parseInt(args[1].substring(1)) : 0) : Integer.parseInt(args[1]);
|
|
|
|
final double z = args[2].startsWith("~") ? user.getLocation().getZ() + (args[2].length() > 1 ? Integer.parseInt(args[2].substring(1)) : 0) : Integer.parseInt(args[2]);
|
2015-04-15 06:06:16 +02:00
|
|
|
final Location loc = new Location(user.getWorld(), x, y, z, user.getLocation().getYaw(), user.getLocation().getPitch());
|
2015-07-17 01:09:19 +02:00
|
|
|
if (args.length == 4) {
|
2017-12-25 08:08:08 +01:00
|
|
|
World w = ess.getWorld(args[3]);
|
|
|
|
if (user.getWorld() != w && ess.getSettings().isWorldTeleportPermissions() && !user.isAuthorized("essentials.worlds." + w.getName())) {
|
|
|
|
throw new Exception(tl("noPerm", "essentials.worlds." + w.getName()));
|
|
|
|
}
|
|
|
|
loc.setWorld(w);
|
2015-04-15 06:06:16 +02:00
|
|
|
}
|
|
|
|
if (args.length > 4) {
|
2015-11-25 18:25:34 +01:00
|
|
|
loc.setYaw((FloatUtil.parseFloat(args[3]) + 360) % 360);
|
2015-06-05 04:32:36 +02:00
|
|
|
loc.setPitch(FloatUtil.parseFloat(args[4]));
|
2015-04-15 06:06:16 +02:00
|
|
|
}
|
2015-07-17 01:09:19 +02:00
|
|
|
if (args.length > 5) {
|
2017-12-25 08:08:08 +01:00
|
|
|
World w = ess.getWorld(args[5]);
|
|
|
|
if (user.getWorld() != w && ess.getSettings().isWorldTeleportPermissions() && !user.isAuthorized("essentials.worlds." + w.getName())) {
|
|
|
|
throw new Exception(tl("noPerm", "essentials.worlds." + w.getName()));
|
|
|
|
}
|
|
|
|
loc.setWorld(w);
|
2015-07-17 01:09:19 +02:00
|
|
|
}
|
2015-04-15 06:06:16 +02:00
|
|
|
if (x > 30000000 || y > 30000000 || z > 30000000 || x < -30000000 || y < -30000000 || z < -30000000) {
|
|
|
|
throw new NotEnoughArgumentsException(tl("teleportInvalidLocation"));
|
|
|
|
}
|
|
|
|
final Trade charge = new Trade(this.getName(), ess);
|
|
|
|
charge.isAffordableFor(user);
|
|
|
|
user.sendMessage(tl("teleporting", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
|
2020-06-24 10:52:25 +02:00
|
|
|
user.getAsyncTeleport().teleport(loc, charge, TeleportCause.COMMAND, getNewExceptionFuture(user.getSource(), commandLabel));
|
2020-08-16 23:40:58 +02:00
|
|
|
|
|
|
|
throw new NoChargeException();
|
2015-04-15 06:06:16 +02:00
|
|
|
}
|
2012-04-02 03:47:10 +02: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 {
|
|
|
|
if (args.length < 4) {
|
|
|
|
throw new NotEnoughArgumentsException();
|
|
|
|
}
|
2012-04-02 03:47:10 +02:00
|
|
|
|
2015-04-15 06:06:16 +02:00
|
|
|
User user = getPlayer(server, args, 0, true, false);
|
2015-07-17 00:36:10 +02:00
|
|
|
final double x = args[1].startsWith("~") ? user.getLocation().getX() + (args[1].length() > 1 ? Integer.parseInt(args[1].substring(1)) : 0) : Integer.parseInt(args[1]);
|
|
|
|
final double y = args[2].startsWith("~") ? user.getLocation().getY() + (args[2].length() > 1 ? Integer.parseInt(args[2].substring(1)) : 0) : Integer.parseInt(args[2]);
|
|
|
|
final double z = args[3].startsWith("~") ? user.getLocation().getZ() + (args[3].length() > 1 ? Integer.parseInt(args[3].substring(1)) : 0) : Integer.parseInt(args[3]);
|
2015-04-15 06:06:16 +02:00
|
|
|
final Location loc = new Location(user.getWorld(), x, y, z, user.getLocation().getYaw(), user.getLocation().getPitch());
|
2015-07-19 00:02:21 +02:00
|
|
|
if (args.length == 5) {
|
|
|
|
loc.setWorld(ess.getWorld(args[4]));
|
2015-07-17 01:09:19 +02:00
|
|
|
}
|
2015-07-19 00:02:21 +02:00
|
|
|
if (args.length > 5) {
|
2015-10-31 21:47:04 +01:00
|
|
|
loc.setYaw((FloatUtil.parseFloat(args[4]) + 360) % 360);
|
2015-07-17 01:09:19 +02:00
|
|
|
loc.setPitch(FloatUtil.parseFloat(args[5]));
|
2015-04-15 06:06:16 +02:00
|
|
|
}
|
2015-07-19 00:02:21 +02:00
|
|
|
if (args.length > 6) {
|
|
|
|
loc.setWorld(ess.getWorld(args[6]));
|
2015-04-15 06:06:16 +02:00
|
|
|
}
|
|
|
|
if (x > 30000000 || y > 30000000 || z > 30000000 || x < -30000000 || y < -30000000 || z < -30000000) {
|
|
|
|
throw new NotEnoughArgumentsException(tl("teleportInvalidLocation"));
|
|
|
|
}
|
|
|
|
sender.sendMessage(tl("teleporting", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
|
|
|
|
user.sendMessage(tl("teleporting", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
|
2020-06-24 10:52:25 +02:00
|
|
|
user.getAsyncTeleport().teleport(loc, null, TeleportCause.COMMAND, getNewExceptionFuture(user.getSource(), commandLabel));
|
2015-04-15 06:06:16 +02:00
|
|
|
}
|
2017-06-11 02:17:43 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected List<String> getTabCompleteOptions(Server server, User user, String commandLabel, String[] args) {
|
|
|
|
if (args.length == 1 || args.length == 2 || args.length == 3) {
|
|
|
|
return Lists.newArrayList("~0");
|
|
|
|
} else if (args.length == 4 || args.length == 5) {
|
|
|
|
return Lists.newArrayList("0");
|
|
|
|
} else if (args.length == 6) {
|
|
|
|
List<String> worlds = Lists.newArrayList();
|
|
|
|
for (World world : server.getWorlds()) {
|
|
|
|
worlds.add(world.getName());
|
|
|
|
}
|
|
|
|
return worlds;
|
|
|
|
} else {
|
|
|
|
return Collections.emptyList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected List<String> getTabCompleteOptions(Server server, CommandSource sender, String commandLabel, String[] args) {
|
|
|
|
if (args.length == 1) {
|
|
|
|
return getPlayers(server, sender);
|
|
|
|
} else if (args.length == 2 || args.length == 3 || args.length == 4) {
|
|
|
|
return Lists.newArrayList("~0");
|
|
|
|
} else if (args.length == 5 || args.length == 6) {
|
|
|
|
return Lists.newArrayList("0");
|
|
|
|
} else if (args.length == 7) {
|
|
|
|
List<String> worlds = Lists.newArrayList();
|
|
|
|
for (World world : server.getWorlds()) {
|
|
|
|
worlds.add(world.getName());
|
|
|
|
}
|
|
|
|
return worlds;
|
|
|
|
} else {
|
|
|
|
return Collections.emptyList();
|
|
|
|
}
|
|
|
|
}
|
2017-12-25 08:08:08 +01:00
|
|
|
}
|