mirror of
https://github.com/sekwah41/Advanced-Portals.git
synced 2025-01-12 19:30:54 +01:00
Finished the select command and added another feature to the API
This commit is contained in:
parent
d73d5f3f17
commit
aafb5ebebd
@ -126,13 +126,10 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
|
||||
Location pos1 = new Location(world, player.getMetadata("Pos1X").get(0).asInt(), player.getMetadata("Pos1Y").get(0).asInt(), player.getMetadata("Pos1Z").get(0).asInt());
|
||||
Location pos2 = new Location(world, player.getMetadata("Pos2X").get(0).asInt(), player.getMetadata("Pos2Y").get(0).asInt(), player.getMetadata("Pos2Z").get(0).asInt());
|
||||
|
||||
ConfigAccessor portalconfig = new ConfigAccessor(plugin, "Portals.yml");
|
||||
String posX = portalconfig.getConfig().getString(portalName + ".pos1.X");
|
||||
|
||||
ConfigAccessor desticonfig = new ConfigAccessor(plugin, "Destinations.yml");
|
||||
String destiPosX = desticonfig.getConfig().getString(destination + ".pos1.X");
|
||||
|
||||
if(posX == null){
|
||||
if(!Portal.portalExists(portalName)){
|
||||
|
||||
player.sendMessage("");
|
||||
player.sendMessage("§a[§eAdvancedPortals§a]§e You have created a new portal with the following details:");
|
||||
@ -141,7 +138,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
|
||||
player.sendMessage("§adestination: §e" + destination);
|
||||
}
|
||||
else if(destiPosX == null){
|
||||
player.sendMessage("§cdestination: §e" + destination + " (undefined destination)");
|
||||
player.sendMessage("§cdestination: §e" + destination + " (destination does not exist)");
|
||||
}
|
||||
else{
|
||||
player.sendMessage("§cdestination: §eN/A (will not work)");
|
||||
@ -216,12 +213,24 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
|
||||
|
||||
// TODO finish the select command and the hit block to replace!
|
||||
|
||||
if(player.hasMetadata("selectingPortal")){
|
||||
player.sendMessage("§a[§eAdvancedPortals§a] Hit a block inside the portal region to select the portal!");
|
||||
player.setMetadata("selectingPortal", new FixedMetadataValue(plugin, true));
|
||||
if(!player.hasMetadata("selectingPortal")){
|
||||
if(args.length > 1){
|
||||
if(Portal.portalExists(args[1])){
|
||||
|
||||
}
|
||||
else{
|
||||
player.sendMessage("§c[§7AdvancedPortals§c] No portal by the name §e" + args[1] + "§c exists (maybe you got the caps wrong)\n Try typing §e/portal select§c and hit inside the apropriate portals area!");
|
||||
}
|
||||
}
|
||||
else{
|
||||
player.sendMessage("§a[§eAdvancedPortals§a] Hit a block inside the portal region to select the portal!");
|
||||
player.setMetadata("selectingPortal", new FixedMetadataValue(plugin, true));
|
||||
}
|
||||
|
||||
}
|
||||
else{
|
||||
player.sendMessage("§c[§7AdvancedPortals§c] You are already selecting a portal!");
|
||||
player.removeMetadata("selectingPortal", plugin);
|
||||
player.sendMessage("§c[§7AdvancedPortals§c] Portal selection cancelled!");
|
||||
}
|
||||
}
|
||||
else if(args[0].toLowerCase().equals("remove")) {
|
||||
|
@ -139,9 +139,9 @@ public class Listeners implements Listener {
|
||||
for(Object portal : portals){
|
||||
if(Portal.worldName[portalId].equals(player.getWorld().getName())){
|
||||
|
||||
if((Portal.pos1[portalId].getX() + 3D) >= loc.getX() && (Portal.pos1[portalId].getY() + 3D) >= loc.getY() && (Portal.pos1[portalId].getZ() + 3D) >= loc.getZ()){
|
||||
if((Portal.pos1[portalId].getX() + 1D) >= loc.getX() && (Portal.pos1[portalId].getY() + 1D) >= loc.getY() && (Portal.pos1[portalId].getZ() + 1D) >= loc.getZ()){
|
||||
|
||||
if((Portal.pos2[portalId].getX() - 3D) <= loc.getX() && (Portal.pos2[portalId].getY() - 3D) <= loc.getY() && (Portal.pos2[portalId].getZ() - 3D) <= loc.getZ()){
|
||||
if((Portal.pos2[portalId].getX()) <= loc.getX() && (Portal.pos2[portalId].getY()) <= loc.getY() && (Portal.pos2[portalId].getZ()) <= loc.getZ()){
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
@ -164,7 +164,6 @@ public class Listeners implements Listener {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if(player.hasMetadata("selectingPortal") && (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_BLOCK)){
|
||||
player.removeMetadata("selectingPortal", plugin);
|
||||
Block block = event.getClickedBlock();
|
||||
Object[] portals = Portal.Portals;
|
||||
int portalId = 0;
|
||||
@ -174,9 +173,13 @@ public class Listeners implements Listener {
|
||||
if((Portal.pos1[portalId].getX() + 3D) >= block.getX() && (Portal.pos1[portalId].getY() + 3D) >= block.getY() && (Portal.pos1[portalId].getZ() + 3D) >= block.getZ()){
|
||||
|
||||
if((Portal.pos2[portalId].getX() - 3D) <= block.getX() && (Portal.pos2[portalId].getY() - 3D) <= block.getY() && (Portal.pos2[portalId].getZ() - 3D) <= block.getZ()){
|
||||
player.sendMessage("§a[§eAdvancedPortals§a]" + Portal.portalName[portalId]);
|
||||
player.setMetadata("selectedPortal", new FixedMetadataValue(plugin, Portal.portalName[portalId]));
|
||||
player.sendMessage("§a[§eAdvancedPortals§a] You have selected: §e" + Portal.portalName[portalId]);
|
||||
// TODO add code somewhere so when a portal is removed or changed if someone has it selected it notifies them
|
||||
// or removed their selections and tells them, maybe not before this update.
|
||||
player.removeMetadata("selectingPortal", plugin);
|
||||
player.setMetadata("selectedPortal", new FixedMetadataValue(plugin, Portal.portalName[portalId])); // adds the name to the metadata of the character
|
||||
event.setCancelled(true);
|
||||
player.removeMetadata("selectingPortal", plugin);
|
||||
return;
|
||||
|
||||
}
|
||||
@ -185,7 +188,7 @@ public class Listeners implements Listener {
|
||||
}
|
||||
portalId++;
|
||||
}
|
||||
player.sendMessage("§c[§7AdvancedPortals§c] No portal was selected!");
|
||||
player.sendMessage("§c[§7AdvancedPortals§c] No portal was selected - if you would like to stop selecting please type §e/portal select §cagain!");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
@ -283,7 +283,20 @@ public class Portal {
|
||||
|
||||
loadPortals();
|
||||
}
|
||||
|
||||
|
||||
public static boolean portalExists(String portalName){
|
||||
|
||||
ConfigAccessor portalconfig = new ConfigAccessor(plugin, "Portals.yml");
|
||||
String posX = portalconfig.getConfig().getString(portalName + ".pos1.X");
|
||||
|
||||
if(posX == null){
|
||||
return false;
|
||||
}
|
||||
else{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean activate(Player player, String portalName) {
|
||||
ConfigAccessor config = new ConfigAccessor(plugin, "Portals.yml");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user