Skip to content

Commit b522b16

Browse files
committed
Fixed half complete code which was released by mistake...
1 parent 1ff177e commit b522b16

File tree

5 files changed

+62
-30
lines changed

5 files changed

+62
-30
lines changed

src/com/sekwah/advancedportals/AdvancedPortalsCommand.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ else if(args[0].toLowerCase().equals("create")) {
9191
String permission = null;
9292
String portalCommand = null;
9393

94-
ArrayList<PortalArg> extraData = new ArrayList<PortalArg>();
94+
ArrayList<PortalArg> extraData = new ArrayList<>();
9595

9696
for(int i = 1; i < args.length; i++){
9797
if(args[i].toLowerCase().startsWith("name:") && args[i].length() > 5){

src/com/sekwah/advancedportals/portals/AdvancedPortal.java

+15-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ public class AdvancedPortal {
1414
public Location pos2 = null;
1515

1616
public String portalName = null;
17-
17+
18+
// TODO store destinations also as variables like portals
1819
public String destiation = null; // Could possibly store the destination name to stop the server having to read the config file
1920

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

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

32-
public AdvancedPortal(String portalName, Material trigger, Location pos1, Location pos2){
33-
this(portalName, trigger, pos1, pos2, pos2.getWorld().getName());
33+
public AdvancedPortal(String portalName, Material trigger, Location pos1, Location pos2, PortalArg... portalArgs){
34+
this(portalName, trigger, pos1, pos2, pos2.getWorld().getName(), portalArgs);
3435
}
3536

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

51+
public String getArg(String arg){
52+
for(PortalArg portalArg : portalArgs){
53+
if(arg.equals(portalArg.argName)){
54+
return portalArg.value;
55+
}
56+
}
57+
return null;
58+
}
59+
5060
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.sekwah.advancedportals.portals;
2+
3+
/**
4+
* Created by on 29/02/2016.
5+
*
6+
* TODO create argument registry for easier altering and control :) also allows other coders to add custom args
7+
*
8+
* @author sekwah41
9+
*/
10+
public class ArgRegistry {
11+
12+
13+
14+
}

src/com/sekwah/advancedportals/portals/Portal.java

+30-22
Original file line numberDiff line numberDiff line change
@@ -78,23 +78,32 @@ public static void loadPortals(){
7878
blockType = Material.PORTAL;
7979
}
8080

81-
ConfigurationSection portalArgs = portalConfigSection.getConfigurationSection("portalArgs");
82-
Set<String> argsSet = portalArgs.getKeys(true);
81+
ConfigurationSection portalArgsConf = portalConfigSection.getConfigurationSection("portalArgs");
8382

84-
ArrayList<PortalArg> extraData = new ArrayList<PortalArg>();
83+
ArrayList<PortalArg> extraData = new ArrayList<>();
8584

86-
for(Object argName : argsSet.toArray()){
87-
if(portalArgs.isString(argName.toString())){
88-
extraData.add(new PortalArg(argName.toString(), portalArgs.getString(argName.toString())));
85+
if (portalArgsConf != null) {
86+
Set<String> argsSet = portalArgsConf.getKeys(true);
87+
88+
for(Object argName : argsSet.toArray()){
89+
if(portalArgsConf.isString(argName.toString())){
90+
extraData.add(new PortalArg(argName.toString(), portalArgsConf.getString(argName.toString())));
91+
}
8992
}
9093
}
9194

95+
96+
9297
String worldName = portalData.getConfig().getString(portal.toString() + ".world");
98+
9399
World world = Bukkit.getWorld(worldName);
94100
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"));
95101
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"));
96102

97-
Portals[portalId] = new AdvancedPortal(portal.toString(), blockType, pos1, pos2, worldName);
103+
PortalArg[] portalArgs = new PortalArg[extraData.size()];
104+
extraData.toArray(portalArgs);
105+
106+
Portals[portalId] = new AdvancedPortal(portal.toString(), blockType, pos1, pos2, worldName, portalArgs);
98107

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

@@ -346,28 +355,28 @@ public static boolean activate(Player player, String portalName) {
346355
return false;
347356
}
348357

349-
public static boolean activate(Player player, AdvancedPortal portalName) {
358+
public static boolean activate(Player player, AdvancedPortal portal) {
350359

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

353-
if(portalData.getConfig().getString(portalName + ".bungee") != null){
362+
if(portal.bungee != null){
354363
if(ShowBungeeMessage){
355-
player.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Attempting to warp to \u00A7e" + portalData.getConfig().getString(portalName + ".bungee") + "\u00A7a.");
364+
player.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Attempting to warp to \u00A7e" + portal.bungee + "\u00A7a.");
356365
}
357366
ByteArrayDataOutput out = ByteStreams.newDataOutput();
358367
out.writeUTF("Connect");
359-
out.writeUTF(portalData.getConfig().getString(portalName + ".bungee"));
368+
out.writeUTF(portal.bungee);
360369
player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
361370
return false;
362371

363372
}
364373
else{
365374
boolean showFailMessage = true;
366375

367-
if(portalData.getConfig().getString(portalName + ".portalArgs.command.1") != null){
376+
if(portal.getArg("command.1") != null){
368377
showFailMessage = false;
369378
int commandLine = 1;
370-
String command = portalData.getConfig().getString(portalName + ".portalArgs.command." + commandLine);
379+
String command = portal.getArg("command." + commandLine);//portalData.getConfig().getString(portal.portalName+ ".portalArgs.command." + commandLine);
371380
do{
372381
// (?i) makes the search case insensitive
373382
command = command.replaceAll("@player", player.getName());
@@ -402,22 +411,21 @@ else if(command.startsWith("^")){
402411
else{
403412
player.performCommand(command);
404413
}
405-
command = portalData.getConfig().getString(portalName + ".portalArgs.command." + ++commandLine);
414+
command = portal.getArg("command." + ++commandLine);
406415
}while(command != null);
407416
}
408-
409-
if(portalData.getConfig().getString(portalName + ".destination") != null){
417+
plugin.getLogger().info(portal.portalName + ":" + portal.destiation);
418+
if(portal.destiation != null){
410419
ConfigAccessor configDesti = new ConfigAccessor(plugin, "Destinations.yml");
411-
String destiName = portalData.getConfig().getString(portalName + ".destination");
412-
String permission = portalData.getConfig().getString(portalName + ".portalArgs.permission");
420+
String permission = portal.getArg("permission");
413421
if(permission == null || (permission != null && player.hasPermission(permission)) || player.isOp()){
414-
if(configDesti.getConfig().getString(destiName + ".world") != null){
415-
boolean warped = Destination.warp(player, destiName);
422+
if(configDesti.getConfig().getString(portal.destiation + ".world") != null){
423+
boolean warped = Destination.warp(player, portal.destiation);
416424
return warped;
417425
}
418426
else{
419427
player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] The destination you are currently attempting to warp to doesnt exist!");
420-
plugin.getLogger().log(Level.SEVERE, "The portal '" + portalName + "' has just had a warp "
428+
plugin.getLogger().log(Level.SEVERE, "The portal '" + portal.portalName + "' has just had a warp "
421429
+ "attempt and either the data is corrupt or that destination listed doesn't exist!");
422430
return false;
423431
}
@@ -448,7 +456,7 @@ else if(command.startsWith("^")){
448456
else{
449457
if(showFailMessage) {
450458
player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] The portal you are trying to use doesn't have a destination!");
451-
plugin.getLogger().log(Level.SEVERE, "The portal '" + portalName + "' has just had a warp "
459+
plugin.getLogger().log(Level.SEVERE, "The portal '" + portal.portalName + "' has just had a warp "
452460
+ "attempt and either the data is corrupt or portal doesn't exist!");
453461
}
454462
return false;

src/plugin.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
main: com.sekwah.advancedportals.AdvancedPortalsPlugin
22
name: AdvancedPortals
3-
version: 0.0.11
3+
version: 0.0.12
44
author: SEKWAH41
55
description: An advanced portals plugin for bukkit.
66
commands:
77
advancedportals:
88
description: The main command for the advanced portals
9-
aliases: [portals, aportals, portal]
9+
aliases: [portals, aportals, portal, ap]
1010
usage: /<command>
1111
destination:
1212
description: Can be used to access portal destinations.

0 commit comments

Comments
 (0)