Skip to content

Commit

Permalink
Fixed half complete code which was released by mistake...
Browse files Browse the repository at this point in the history
  • Loading branch information
sekwah41 committed Feb 29, 2016
1 parent 1ff177e commit b522b16
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/com/sekwah/advancedportals/AdvancedPortalsCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ else if(args[0].toLowerCase().equals("create")) {
String permission = null;
String portalCommand = null;

ArrayList<PortalArg> extraData = new ArrayList<PortalArg>();
ArrayList<PortalArg> extraData = new ArrayList<>();

for(int i = 1; i < args.length; i++){
if(args[i].toLowerCase().startsWith("name:") && args[i].length() > 5){
Expand Down
20 changes: 15 additions & 5 deletions src/com/sekwah/advancedportals/portals/AdvancedPortal.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public class AdvancedPortal {
public Location pos2 = null;

public String portalName = null;


// TODO store destinations also as variables like portals
public String destiation = null; // Could possibly store the destination name to stop the server having to read the config file

public String bungee = null; // Could possibly store the bungee server name to stop the server having to read the config file
Expand All @@ -24,13 +25,13 @@ public class AdvancedPortal {
public PortalArg[] portalArgs = null;

// TODO think of relaying out the data input to a more logical format.
public AdvancedPortal(String portalName, Material trigger, String destination, Location pos1, Location pos2){
this(portalName, trigger, pos1, pos2, pos2.getWorld().getName());
public AdvancedPortal(String portalName, Material trigger, String destination, Location pos1, Location pos2, PortalArg... portalArgs){
this(portalName, trigger, pos1, pos2, pos2.getWorld().getName(), portalArgs);
this.destiation = destination;
}

public AdvancedPortal(String portalName, Material trigger, Location pos1, Location pos2){
this(portalName, trigger, pos1, pos2, pos2.getWorld().getName());
public AdvancedPortal(String portalName, Material trigger, Location pos1, Location pos2, PortalArg... portalArgs){
this(portalName, trigger, pos1, pos2, pos2.getWorld().getName(), portalArgs);
}

public AdvancedPortal(String portalName, Material trigger, String destination, Location pos1, Location pos2, String worldName, PortalArg... portalArgs){
Expand All @@ -47,4 +48,13 @@ public AdvancedPortal(String portalName, Material trigger, Location pos1, Locati
this.portalArgs = portalArgs;
}

public String getArg(String arg){
for(PortalArg portalArg : portalArgs){
if(arg.equals(portalArg.argName)){
return portalArg.value;
}
}
return null;
}

}
14 changes: 14 additions & 0 deletions src/com/sekwah/advancedportals/portals/ArgRegistry.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.sekwah.advancedportals.portals;

/**
* Created by on 29/02/2016.
*
* TODO create argument registry for easier altering and control :) also allows other coders to add custom args
*
* @author sekwah41
*/
public class ArgRegistry {



}
52 changes: 30 additions & 22 deletions src/com/sekwah/advancedportals/portals/Portal.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,23 +78,32 @@ public static void loadPortals(){
blockType = Material.PORTAL;
}

ConfigurationSection portalArgs = portalConfigSection.getConfigurationSection("portalArgs");
Set<String> argsSet = portalArgs.getKeys(true);
ConfigurationSection portalArgsConf = portalConfigSection.getConfigurationSection("portalArgs");

ArrayList<PortalArg> extraData = new ArrayList<PortalArg>();
ArrayList<PortalArg> extraData = new ArrayList<>();

for(Object argName : argsSet.toArray()){
if(portalArgs.isString(argName.toString())){
extraData.add(new PortalArg(argName.toString(), portalArgs.getString(argName.toString())));
if (portalArgsConf != null) {
Set<String> argsSet = portalArgsConf.getKeys(true);

for(Object argName : argsSet.toArray()){
if(portalArgsConf.isString(argName.toString())){
extraData.add(new PortalArg(argName.toString(), portalArgsConf.getString(argName.toString())));
}
}
}



String worldName = portalData.getConfig().getString(portal.toString() + ".world");

World world = Bukkit.getWorld(worldName);
Location pos1 = new Location(world, portalData.getConfig().getInt(portal.toString() + ".pos1.X"), portalData.getConfig().getInt(portal.toString() + ".pos1.Y"), portalData.getConfig().getInt(portal.toString() + ".pos1.Z"));
Location pos2 = new Location(world, portalData.getConfig().getInt(portal.toString() + ".pos2.X"), portalData.getConfig().getInt(portal.toString() + ".pos2.Y"), portalData.getConfig().getInt(portal.toString() + ".pos2.Z"));

Portals[portalId] = new AdvancedPortal(portal.toString(), blockType, pos1, pos2, worldName);
PortalArg[] portalArgs = new PortalArg[extraData.size()];
extraData.toArray(portalArgs);

Portals[portalId] = new AdvancedPortal(portal.toString(), blockType, pos1, pos2, worldName, portalArgs);

Portals[portalId].bungee = portalConfigSection.getString("bungee");

Expand Down Expand Up @@ -346,28 +355,28 @@ public static boolean activate(Player player, String portalName) {
return false;
}

public static boolean activate(Player player, AdvancedPortal portalName) {
public static boolean activate(Player player, AdvancedPortal portal) {

// add other variables or filter code here, or somehow have a way to register them

if(portalData.getConfig().getString(portalName + ".bungee") != null){
if(portal.bungee != null){
if(ShowBungeeMessage){
player.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Attempting to warp to \u00A7e" + portalData.getConfig().getString(portalName + ".bungee") + "\u00A7a.");
player.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Attempting to warp to \u00A7e" + portal.bungee + "\u00A7a.");
}
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("Connect");
out.writeUTF(portalData.getConfig().getString(portalName + ".bungee"));
out.writeUTF(portal.bungee);
player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
return false;

}
else{
boolean showFailMessage = true;

if(portalData.getConfig().getString(portalName + ".portalArgs.command.1") != null){
if(portal.getArg("command.1") != null){
showFailMessage = false;
int commandLine = 1;
String command = portalData.getConfig().getString(portalName + ".portalArgs.command." + commandLine);
String command = portal.getArg("command." + commandLine);//portalData.getConfig().getString(portal.portalName+ ".portalArgs.command." + commandLine);
do{
// (?i) makes the search case insensitive
command = command.replaceAll("@player", player.getName());
Expand Down Expand Up @@ -402,22 +411,21 @@ else if(command.startsWith("^")){
else{
player.performCommand(command);
}
command = portalData.getConfig().getString(portalName + ".portalArgs.command." + ++commandLine);
command = portal.getArg("command." + ++commandLine);
}while(command != null);
}

if(portalData.getConfig().getString(portalName + ".destination") != null){
plugin.getLogger().info(portal.portalName + ":" + portal.destiation);
if(portal.destiation != null){
ConfigAccessor configDesti = new ConfigAccessor(plugin, "Destinations.yml");
String destiName = portalData.getConfig().getString(portalName + ".destination");
String permission = portalData.getConfig().getString(portalName + ".portalArgs.permission");
String permission = portal.getArg("permission");
if(permission == null || (permission != null && player.hasPermission(permission)) || player.isOp()){
if(configDesti.getConfig().getString(destiName + ".world") != null){
boolean warped = Destination.warp(player, destiName);
if(configDesti.getConfig().getString(portal.destiation + ".world") != null){
boolean warped = Destination.warp(player, portal.destiation);
return warped;
}
else{
player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] The destination you are currently attempting to warp to doesnt exist!");
plugin.getLogger().log(Level.SEVERE, "The portal '" + portalName + "' has just had a warp "
plugin.getLogger().log(Level.SEVERE, "The portal '" + portal.portalName + "' has just had a warp "
+ "attempt and either the data is corrupt or that destination listed doesn't exist!");
return false;
}
Expand Down Expand Up @@ -448,7 +456,7 @@ else if(command.startsWith("^")){
else{
if(showFailMessage) {
player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] The portal you are trying to use doesn't have a destination!");
plugin.getLogger().log(Level.SEVERE, "The portal '" + portalName + "' has just had a warp "
plugin.getLogger().log(Level.SEVERE, "The portal '" + portal.portalName + "' has just had a warp "
+ "attempt and either the data is corrupt or portal doesn't exist!");
}
return false;
Expand Down
4 changes: 2 additions & 2 deletions src/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
main: com.sekwah.advancedportals.AdvancedPortalsPlugin
name: AdvancedPortals
version: 0.0.11
version: 0.0.12
author: SEKWAH41
description: An advanced portals plugin for bukkit.
commands:
advancedportals:
description: The main command for the advanced portals
aliases: [portals, aportals, portal]
aliases: [portals, aportals, portal, ap]
usage: /<command>
destination:
description: Can be used to access portal destinations.
Expand Down

0 comments on commit b522b16

Please sign in to comment.