fixed the godo and warp command, updated some messages and started the

list command
This commit is contained in:
sekwah41 2014-04-12 22:10:12 +01:00
parent 7c00efb011
commit 5509ec8d96
3 changed files with 81 additions and 9 deletions

View File

@ -5,6 +5,7 @@ import java.util.Collections;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
@ -60,26 +61,73 @@ public class DestinationCommand implements CommandExecutor, TabCompleter {
sender.sendMessage("§c[§7AdvancedPortals§c] The portal §e" + args[1] + "§c has been removed!"); sender.sendMessage("§c[§7AdvancedPortals§c] The portal §e" + args[1] + "§c has been removed!");
} }
else{ else{
sender.sendMessage("§c[§7AdvancedPortals§c] No portal by that name exists!"); sender.sendMessage("§c[§7AdvancedPortals§c] No portal by that name exists.");
} }
} }
else{ else{
sender.sendMessage("§c[§7AdvancedPortals§c] You need to state the name of the destination you wish to remove!"); sender.sendMessage("§c[§7AdvancedPortals§c] You need to state the name of the destination you wish to remove.");
} }
} }
else if(args[0].toLowerCase().equals("goto")) { else if(args[0].toLowerCase().equals("goto") || args[0].toLowerCase().equals("warp")) {
ConfigAccessor portalConfig = new ConfigAccessor(plugin, "Destinations.yml");
if(args.length > 1){ if(args.length > 1){
String posX = portalConfig.getConfig().getString(args[1] + ".pos1.X"); System.out.println(args[1]);
if(posX != null){ ConfigAccessor configDesti = new ConfigAccessor(plugin, "Destinations.yml");
if(configDesti.getConfig().getString(args[1] + ".world") != null){
Destination.warp(sender, args[1]); Destination.warp(sender, args[1]);
sender.sendMessage("§a[§eAdvancedPortals§a] You have been warped to §e" + args[1] + "§a.");
} }
else{ else{
sender.sendMessage("§c[§7AdvancedPortals§c] No portal by that name exists!"); sender.sendMessage("§c[§7AdvancedPortals§c] No destination by that name exists.");
} }
} }
else{ else{
sender.sendMessage("§c[§7AdvancedPortals§c] You need to state the name of the destination you wish to teleport to!"); sender.sendMessage("§c[§7AdvancedPortals§c] You need to state the name of the destination you wish to teleport to.");
}
}
else if(args[0].toLowerCase().equals("list")) {
List<String> destiList = Destination.destiList();
if(destiList.size() >= 1){
if(args.length > 1){
try
{
int page = Integer.parseInt(args[1]);
if(page * 5 >= destiList.size() - 5){ // add this if statement so that the user cant select a list page higher than the max
if((int) destiList.size() / 5 == destiList.size()){
}
}
sender.sendMessage("§a[§eAdvancedPortals§a] Showing destinations page 1 of 1");
for(int i = (page - 1) * 5; i < page * 5; i++){
if(i > destiList.size()){
break;
}
sender.sendMessage(" §e" + destiList.get(i));
}
return true;
}
catch(Exception e)
{
}
}
sender.sendMessage("§a[§eAdvancedPortals§a] Showing destinations page 1 of 1");
for(int i = 0; i < 5; i++){
if(i > destiList.size()){
break;
}
sender.sendMessage(" §e" + destiList.get(i));
}
sender.sendMessage("§a[§eAdvancedPortals§a] Showing destinations page 1 of 1");
for(int i = 0; i < 5; i++){
if(i > destiList.size()){
break;
}
sender.sendMessage(" §e" + destiList.get(i));
}
}
else{
sender.sendMessage("§c[§7AdvancedPortals§c] There are currently no defined destinations.");
} }
} }
} }

View File

@ -1,10 +1,17 @@
package com.sekwah.advancedportals.destinations; package com.sekwah.advancedportals.destinations;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.logging.Level; import java.util.logging.Level;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -174,4 +181,21 @@ public class Destination {
return warp(player, name, true); return warp(player, name, true);
} }
public static List<String> destiList(){
ConfigAccessor config = new ConfigAccessor(plugin, "Destinations.yml");
LinkedList<String> destiList = new LinkedList<String>();
Set<String> destiSet = config.getConfig().getKeys(false);
if(destiSet.size() > 0){;
for(Object desti: destiSet.toArray()){
destiSet.add(desti.toString());
}
}
Collections.sort(destiList);
return destiList;
}
} }