mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-12-25 02:27:33 +01:00
Allow the use of the warp command from the console
This commit is contained in:
parent
375636cd36
commit
d264c26310
@ -18,6 +18,6 @@ public class Commandsuicide extends EssentialsCommand
|
||||
user.setHealth(0);
|
||||
user.sendMessage(Util.i18n("suicideMessage"));
|
||||
ess.broadcastMessage(user,
|
||||
Util.format("suicideSuccess",user.getDisplayName()));
|
||||
Util.format("suicideSuccess", user.getDisplayName()));
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import com.earth2me.essentials.Warps;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
|
||||
public class Commandwarp extends EssentialsCommand
|
||||
@ -28,33 +29,7 @@ public class Commandwarp extends EssentialsCommand
|
||||
{
|
||||
throw new Exception(Util.i18n("warpListPermission"));
|
||||
}
|
||||
|
||||
Warps warps = ess.getWarps();
|
||||
if (warps.isEmpty())
|
||||
{
|
||||
throw new Exception(Util.i18n("noWarpsDefined"));
|
||||
}
|
||||
final List<String> warpNameList = new ArrayList<String>(warps.getWarpNames());
|
||||
final Iterator<String> iterator = warpNameList.iterator();
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
final String warpName = iterator.next();
|
||||
if (ess.getSettings().getPerWarpPermission() && !user.isAuthorized("essentials.warp." + warpName))
|
||||
{
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
int page = 1;
|
||||
if (args.length > 0)
|
||||
{
|
||||
page = Integer.parseInt(args[0]);
|
||||
}
|
||||
if (warpNameList.size() > WARPS_PER_PAGE)
|
||||
{
|
||||
user.sendMessage(Util.format("warpsCount", warpNameList.size(), page, (int)Math.ceil(warpNameList.size() / (double)WARPS_PER_PAGE)));
|
||||
}
|
||||
final int warpPage = (page - 1) * WARPS_PER_PAGE;
|
||||
user.sendMessage(Util.joinList(warpNameList.subList(warpPage, warpPage+Math.min(warpNameList.size() - warpPage, WARPS_PER_PAGE))));
|
||||
warpList(user, args);
|
||||
throw new NoChargeException();
|
||||
}
|
||||
if (args.length > 0)
|
||||
@ -75,6 +50,57 @@ public class Commandwarp extends EssentialsCommand
|
||||
}
|
||||
}
|
||||
|
||||
public void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception
|
||||
{
|
||||
if (args.length < 2 || args[0].matches("[0-9]+"))
|
||||
{
|
||||
warpList(null, args);
|
||||
throw new NoChargeException();
|
||||
}
|
||||
User otherUser = ess.getUser(server.getPlayer(args[1]));
|
||||
if (otherUser == null)
|
||||
{
|
||||
throw new Exception(Util.i18n("playerNotFound"));
|
||||
}
|
||||
warpUser(otherUser, args[0]);
|
||||
throw new NoChargeException();
|
||||
|
||||
}
|
||||
|
||||
private void warpList(User user, String[] args) throws Exception
|
||||
{
|
||||
Warps warps = ess.getWarps();
|
||||
if (warps.isEmpty())
|
||||
{
|
||||
throw new Exception(Util.i18n("noWarpsDefined"));
|
||||
}
|
||||
final List<String> warpNameList = new ArrayList<String>(warps.getWarpNames());
|
||||
|
||||
if (user != null)
|
||||
{
|
||||
final Iterator<String> iterator = warpNameList.iterator();
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
final String warpName = iterator.next();
|
||||
if (ess.getSettings().getPerWarpPermission() && !user.isAuthorized("essentials.warp." + warpName))
|
||||
{
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
int page = 1;
|
||||
if (args.length > 0)
|
||||
{
|
||||
page = Integer.parseInt(args[0]);
|
||||
}
|
||||
if (warpNameList.size() > WARPS_PER_PAGE)
|
||||
{
|
||||
user.sendMessage(Util.format("warpsCount", warpNameList.size(), page, (int)Math.ceil(warpNameList.size() / (double)WARPS_PER_PAGE)));
|
||||
}
|
||||
final int warpPage = (page - 1) * WARPS_PER_PAGE;
|
||||
user.sendMessage(Util.joinList(warpNameList.subList(warpPage, warpPage + Math.min(warpNameList.size() - warpPage, WARPS_PER_PAGE))));
|
||||
}
|
||||
|
||||
private void warpUser(User user, String name) throws Exception
|
||||
{
|
||||
Trade charge = new Trade(this.getName(), ess);
|
||||
|
Loading…
Reference in New Issue
Block a user