Started the warp command

This commit is contained in:
sekwah41 2014-01-19 18:44:37 +00:00
parent 2ba2b6c61b
commit 23d1d2a209
3 changed files with 120 additions and 9 deletions

View File

@ -0,0 +1,66 @@
package com.sekwah.advancedportals;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import com.sekwah.advancedportals.destinations.Destination;
public class WarpCommand implements CommandExecutor, TabCompleter {
private AdvancedPortalsPlugin plugin;
public WarpCommand(AdvancedPortalsPlugin plugin) {
this.plugin = plugin;
plugin.getCommand("destination").setExecutor(this);
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String command, String[] args) {
if(args.length > 0){
if(Destination.warp(sender, args[0], false)){
sender.sendMessage("§a[§eAdvancedPortals§a] You have been warped to §e" + args[0] + ".");
}
else{
sender.sendMessage("§c[§7AdvancedPortals§c] The destination you tried to warp to does not exist!");
}
}
else{
sender.sendMessage("§c[§7AdvancedPortals§c] You need to type a destination after /" + command + "!");
}
return true;
}
@Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String command, String[] args) {
LinkedList<String> autoComplete = new LinkedList<String>();
if(sender.hasPermission("AdvancedPortals.CreatePortal")){
if(args.length == 1){
autoComplete.addAll(Arrays.asList("create", "goto", "redefine", "move", "rename", "remove"));
}
else if(args[0].toLowerCase().equals("create")){
}
}
Collections.sort(autoComplete);
for(Object result: autoComplete.toArray()){
if(!result.toString().startsWith(args[args.length - 1])){
autoComplete.remove(result);
}
}
return autoComplete;
}
}

View File

@ -5,6 +5,7 @@ import java.util.logging.Level;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
@ -86,7 +87,7 @@ public class Destination {
config.saveConfig();
}
public static boolean warp(Player player, String name){
public static boolean warp(Player player, String name, boolean senderror){
ConfigAccessor config = new ConfigAccessor(plugin, "Destinations.yml");
if(config.getConfig().getString(name + ".world") != null){
Location loc = player.getLocation();
@ -104,8 +105,7 @@ public class Destination {
Entity riding = player.getVehicle();
if (!c.isLoaded()) c.load();
if(player.getVehicle() != null){
player.sendMessage("§c[§7AdvancedPortals§c] You cannot currently teleport while riding");
riding.setPassenger(null);
riding.eject();
riding.teleport(loc);
player.teleport(loc);
riding.setPassenger(player);
@ -118,18 +118,60 @@ public class Destination {
return true;
}
else{
player.sendMessage("§cThe destination you are trying to warp to seems to be linked to a world that doesn't exist!");
plugin.getLogger().log(Level.SEVERE, "The destination '" + name + "' is linked to the world "
+ config.getConfig().getString(name + ".world") + " which doesnt seem to exist any more!");
if(senderror){
player.sendMessage("§cThe destination you are trying to warp to seems to be linked to a world that doesn't exist!");
plugin.getLogger().log(Level.SEVERE, "The destination '" + name + "' is linked to the world "
+ config.getConfig().getString(name + ".world") + " which doesnt seem to exist any more!");
}
return false;
}
}
else{
player.sendMessage("§cThere has been a problem warping you to the selected destination!");
plugin.getLogger().log(Level.SEVERE, "The destination '" + name + "' has just had a warp "
+ "attempt and either the data is corrupt or that destination doesn't exist!");
if(senderror){
player.sendMessage("§cThere has been a problem warping you to the selected destination!");
plugin.getLogger().log(Level.SEVERE, "The destination '" + name + "' has just had a warp "
+ "attempt and either the data is corrupt or that destination doesn't exist!");
}
return false;
}
}
/**
* Same as other warp but changes sender to player for you.
*
* @param sender
* @param name
* @return
*/
public static boolean warp(Player player, String name) {
return warp(player, name, true);
}
/**
* Same as other warp but changes sender to player for you.
*
* @param sender
* @param name
* @return
*/
public static boolean warp(CommandSender sender, String name, boolean senderror) {
Player player = (Player)sender;
return warp(player, name, senderror);
}
/**
* Same as other warp but changes sender to player for you.
*
* @param sender
* @param name
* @return
*/
public static boolean warp(CommandSender sender, String name) {
Player player = (Player)sender;
return warp(player, name, true);
}
}

View File

@ -12,6 +12,9 @@ commands:
description: Can be used to access portal destinations.
aliases: [desti]
usage: /<command>
warp:
description: Used to warp to destinations.
usage: /<command>
permissions:
advancedportals.*:
description: Gives access to all portal commands