The rename command has been complete and the remove function in the

portal class has been recoded. Also the edit menu has been fixed as it
never used to show the complete positions.
This commit is contained in:
sekwah41 2014-06-04 15:52:24 +01:00
parent 5509ec8d96
commit 4846530568
3 changed files with 90 additions and 59 deletions

View File

@ -283,35 +283,38 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
else if(args[0].toLowerCase().equals("rename")) {
// not finished yet /
/**
ConfigAccessor portalConfig = new ConfigAccessor(plugin, "Portals.yml");
if(args.length > 1){
String posX = portalConfig.getConfig().getString(args[1] + ".pos1.X");
if(posX != null){
Portal.remove(args[1]);
sender.sendMessage("§a[§eAdvancedPortals§a] The portal §e" + args[1] + "§a has been removed!");
}
else{
sender.sendMessage("§c[§7AdvancedPortals§c] No portal by that name exists!");
}
}
else{
if(player.hasMetadata("selectedPortal")){
String portalName = player.getMetadata("selectedPortal").get(0).asString();
String posX = portalConfig.getConfig().getString(portalName + ".pos1.X");
if(posX != null){
Portal.remove(args[1]);
sender.sendMessage("§a[§eAdvancedPortals§a] The portal §7" + portalName + " has been removed!");
if(portalName.toLowerCase() != args[1].toLowerCase()){
String posX = portalConfig.getConfig().getString(portalName + ".pos1.X");
String newPortalPosX = portalConfig.getConfig().getString(args[1] + ".pos1.X");
if(posX != null && newPortalPosX == null){
Portal.rename(portalName, args[1]);
sender.sendMessage("§a[§eAdvancedPortals§a] The portal §e" + portalName + "§a has been renamed to §e" + args[1] + "§a.");
player.setMetadata("selectedPortal", new FixedMetadataValue(plugin, args[1]));
}
else if(newPortalPosX != null){
sender.sendMessage("§c[§7AdvancedPortals§c] There is already a portal with the name §e" + args[1] + "§c!");
}
else{
sender.sendMessage("§c[§7AdvancedPortals§c] The portal you had selected no longer seems to exist!");
player.removeMetadata("selectedPortal", plugin);
}
}
else{
sender.sendMessage("§c[§7AdvancedPortals§c] The portal you had selected no longer seems to exist!");
player.removeMetadata("selectedPortal", plugin);
sender.sendMessage("§c[§7AdvancedPortals§c] The portal you have selected is already called that!");
}
}
else{
sender.sendMessage("§c[§7AdvancedPortals§c] No portal has been defined or selected!");
}
}*/
}
else{
sender.sendMessage("§c[§7AdvancedPortals§c] You must select a portal first and then type §e/portal rename (new name)§c!");
}
}
else if(args[0].toLowerCase().equals("remove")) {
ConfigAccessor portalConfig = new ConfigAccessor(plugin, "Portals.yml");
@ -330,7 +333,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
String portalName = player.getMetadata("selectedPortal").get(0).asString();
String posX = portalConfig.getConfig().getString(portalName + ".pos1.X");
if(posX != null){
Portal.remove(args[1]);
Portal.remove(portalName);
sender.sendMessage("§c[§7AdvancedPortals§c] The portal §7" + portalName + " has been removed!");
}
else{
@ -406,8 +409,8 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
sender.sendMessage("");
sender.sendMessage("§a[§eAdvancedPortals§a] Editing: §e" + portalName);
sender.sendMessage(" §apos1§e: " + portalConfig.getConfig().getString(portalName + ".pos1.X"));
sender.sendMessage(" §apos2§e: " + portalConfig.getConfig().getString(portalName + ".pos2.X"));
sender.sendMessage(" §apos1§e: " + portalConfig.getConfig().getString(portalName + ".pos1.X") + ", " + portalConfig.getConfig().getString(portalName + ".pos1.Y") + ", " + portalConfig.getConfig().getString(portalName + ".pos1.Z"));
sender.sendMessage(" §apos2§e: " + portalConfig.getConfig().getString(portalName + ".pos2.X") + ", " + portalConfig.getConfig().getString(portalName + ".pos2.Y") + ", " + portalConfig.getConfig().getString(portalName + ".pos2.Z"));
String destination = portalConfig.getConfig().getString(portalName + ".destination");
if(destination != null){
@ -429,7 +432,8 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
Player player = (Player)sender;
IChatBaseComponent comp = ChatSerializer.a("{text:\"§aFunctions§e: \",extra:[{text:\"§eRemove\",hoverEvent:{action:show_text,value:\"Remove the selected portal\"},clickEvent:{action:run_command,value:\"/portal gui remove " + portalName + "\"}}"
+ ",{text:\" \"},{text:\"§eShow\",hoverEvent:{action:show_text,value:\"Show the selected portal\"},clickEvent:{action:run_command,value:\"/portal show " + portalName + "\"}}]}");
+ ",{text:\" \"},{text:\"§eShow\",hoverEvent:{action:show_text,value:\"Show the selected portal\"},clickEvent:{action:run_command,value:\"/portal show " + portalName + "\"}}"
+ ",{text:\" \"},{text:\"§eRename\",hoverEvent:{action:show_text,value:\"Change the name of the portal\"},clickEvent:{action:suggest_command,value:\"/portal rename \"}}]}");
PacketPlayOutChat packet = new PacketPlayOutChat(comp, true);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
sender.sendMessage("");

View File

@ -105,7 +105,7 @@ public class Listeners implements Listener {
public void run(){
finalplayer.removeMetadata("HasWarped", plugin);
}
}, 20);
}, 40);
}
}

View File

@ -144,19 +144,19 @@ public class Portal {
ConfigAccessor config = new ConfigAccessor(plugin, "Portals.yml");
config.getConfig().set(name.toLowerCase() + ".world", pos1.getWorld().getName());
config.getConfig().set(name + ".world", pos1.getWorld().getName());
config.getConfig().set(name.toLowerCase() + ".triggerblock", checkMaterial(triggerBlock));
config.getConfig().set(name + ".triggerblock", checkMaterial(triggerBlock));
config.getConfig().set(name.toLowerCase() + ".destination", destination);
config.getConfig().set(name + ".destination", destination);
config.getConfig().set(name.toLowerCase() + ".pos1.X", HighX);
config.getConfig().set(name.toLowerCase() + ".pos1.Y", HighY);
config.getConfig().set(name.toLowerCase() + ".pos1.Z", HighZ);
config.getConfig().set(name + ".pos1.X", HighX);
config.getConfig().set(name + ".pos1.Y", HighY);
config.getConfig().set(name + ".pos1.Z", HighZ);
config.getConfig().set(name.toLowerCase() + ".pos2.X", LowX);
config.getConfig().set(name.toLowerCase() + ".pos2.Y", LowY);
config.getConfig().set(name.toLowerCase() + ".pos2.Z", LowZ);
config.getConfig().set(name + ".pos2.X", LowX);
config.getConfig().set(name + ".pos2.Y", LowY);
config.getConfig().set(name + ".pos2.Z", LowZ);
config.saveConfig();
@ -245,13 +245,13 @@ public class Portal {
ConfigAccessor config = new ConfigAccessor(plugin, "Portals.yml");
config.getConfig().set(name.toLowerCase() + ".pos1.X", pos1.getX());
config.getConfig().set(name.toLowerCase() + ".pos1.Y", pos1.getY());
config.getConfig().set(name.toLowerCase() + ".pos1.Z", pos1.getZ());
config.getConfig().set(name + ".pos1.X", pos1.getX());
config.getConfig().set(name + ".pos1.Y", pos1.getY());
config.getConfig().set(name + ".pos1.Z", pos1.getZ());
config.getConfig().set(name.toLowerCase() + ".pos2.X", pos2.getX());
config.getConfig().set(name.toLowerCase() + ".pos2.Y", pos2.getY());
config.getConfig().set(name.toLowerCase() + ".pos2.Z", pos2.getZ());
config.getConfig().set(name + ".pos2.X", pos2.getX());
config.getConfig().set(name + ".pos2.Y", pos2.getY());
config.getConfig().set(name + ".pos2.Z", pos2.getZ());
config.saveConfig();
@ -262,22 +262,39 @@ public class Portal {
public static void remove(String name){
ConfigAccessor config = new ConfigAccessor(plugin, "Portals.yml");
config.getConfig().set(name.toLowerCase() + ".world", null);
config.getConfig().set(name.toLowerCase() + ".triggerblock", null);
config.getConfig().set(name.toLowerCase() + ".destination", null);
Object[] keys = config.getConfig().getKeys(true).toArray();
for(int i = keys.length - 1; i >= 0; i--){
String key = keys[i].toString();
if(key.startsWith(name + ".")){
System.out.println(key);
config.getConfig().set(key, null);
}
}
config.getConfig().set(name, null);
config.getConfig().set(name.toLowerCase() + ".pos1.X", null);
config.getConfig().set(name.toLowerCase() + ".pos1.Y", null);
config.getConfig().set(name.toLowerCase() + ".pos1.Z", null);
/**Set<String> keys = config.getConfig().getKeys(true);
for(String key: keys){
if(key.startsWith(name)){
config.getConfig().set(key, null);
}
}*/
config.getConfig().set(name.toLowerCase() + ".pos2.X", null);
config.getConfig().set(name.toLowerCase() + ".pos2.Y", null);
config.getConfig().set(name.toLowerCase() + ".pos2.Z", null);
/**config.getConfig().set(name + ".world", null);
config.getConfig().set(name + ".triggerblock", null);
config.getConfig().set(name + ".destination", null);
config.getConfig().set(name.toLowerCase() + ".pos1", null);
config.getConfig().set(name.toLowerCase() + ".pos2", null);
config.getConfig().set(name + ".pos1.X", null);
config.getConfig().set(name + ".pos1.Y", null);
config.getConfig().set(name + ".pos1.Z", null);
config.getConfig().set(name.toLowerCase(), null);
config.getConfig().set(name + ".pos2.X", null);
config.getConfig().set(name + ".pos2.Y", null);
config.getConfig().set(name + ".pos2.Z", null);
config.getConfig().set(name + ".pos1", null);
config.getConfig().set(name + ".pos2", null);
config.getConfig().set(name, null);*/
config.saveConfig();
@ -344,20 +361,30 @@ public class Portal {
// set it so it gets all data from one and puts it into another place
ConfigAccessor config = new ConfigAccessor(plugin, "Destinations.yml");
ConfigAccessor config = new ConfigAccessor(plugin, "Portals.yml");
config.getConfig().set(newName.toLowerCase() + ".world", config.getConfig().getString(oldName + ".world"));
Set<String> keys = config.getConfig().getKeys(true);
for(String key: keys){
if(key.startsWith(oldName + ".")){
if(config.getConfig().getString(key) != null){
try
{
int intData = Integer.parseInt(config.getConfig().getString(key));
config.getConfig().set(key.replace(oldName + ".", newName + "."), intData);
}
catch(Exception e)
{
config.getConfig().set(key.replace(oldName + ".", newName + "."), config.getConfig().getString(key));
}
}
}
}
config.getConfig().set(newName.toLowerCase() + ".pos.X", config.getConfig().getDouble(oldName + ".pos.X"));
config.getConfig().set(newName.toLowerCase() + ".pos.Y", config.getConfig().getDouble(oldName + ".pos.Y"));
config.getConfig().set(newName.toLowerCase() + ".pos.Z", config.getConfig().getDouble(oldName + ".pos.Z"));
config.getConfig().set(newName.toLowerCase() + ".pos.pitch", config.getConfig().getDouble(oldName + ".pos.pitch"));
config.getConfig().set(newName.toLowerCase() + ".pos.yaw", config.getConfig().getDouble(oldName + ".pos.yaw"));
config.saveConfig();
remove(oldName);
config.saveConfig();
}