Started adding the extra data for permissions and stuff

This commit is contained in:
sekwah41 2015-03-25 22:51:29 +00:00
parent 4561c7faf0
commit ac21a19a3d
4 changed files with 58 additions and 16 deletions

View File

@ -1,6 +1,7 @@
package com.sekwah.advancedportals;
import com.sekwah.advancedportals.portals.Portal;
import com.sekwah.advancedportals.portals.PortalArgs;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
@ -14,10 +15,7 @@ import org.bukkit.inventory.PlayerInventory;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.metadata.FixedMetadataValue;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.*;
public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
@ -75,10 +73,15 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
boolean hasTriggerBlock = false;
boolean hasDestination = false;
boolean isBungeePortal = false;
boolean needsPermission = false;
String destination = null;
String portalName = null;
String triggerBlock = null;
String serverName = null;
String permission = null;
ArrayList<PortalArgs> extraData = new ArrayList<PortalArgs>();
for(int i = 1; i < args.length; i++){
if(args[i].toLowerCase().startsWith("name:") && args[i].length() > 5){
hasName = true;
@ -107,7 +110,13 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
else if(args[i].toLowerCase().startsWith("bungee:") && args[i].length() > 7){ // not completely implemented
isBungeePortal = true;
serverName = args[i].toLowerCase().replaceFirst("bungee:", "");
//extraData.add(new PortalArgs("bungee", serverName));
}
else if(args[i].toLowerCase().startsWith("permission:") && args[i].length() > 11){ // not completely implemented
needsPermission = true;
permission = args[i].toLowerCase().replaceFirst("permission:", "");
extraData.add(new PortalArgs("permission", serverName));
}
}
if(!hasName){
player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You must include a name for the portal that you are creating in the variables!");
@ -140,12 +149,19 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
player.sendMessage("\u00A7abungee: \u00A7e" + serverName);
}
if(needsPermission){
player.sendMessage("\u00A7apermission: \u00A7e" + permission);
}
else{
player.sendMessage("\u00A7apermission: \u00A7e(none needed)");
}
Material triggerBlockMat = Material.getMaterial(0);
if(hasTriggerBlock){
triggerBlockMat = Material.getMaterial(triggerBlock.toUpperCase());
if(triggerBlockMat != null){
player.sendMessage("\u00A7atriggerBlock: \u00A7e" + triggerBlock.toUpperCase());
player.sendMessage(Portal.create(pos1, pos2, portalName, destination, triggerBlockMat, serverName));
player.sendMessage(Portal.create(pos1, pos2, portalName, destination, triggerBlockMat, serverName, (PortalArgs[]) extraData.toArray()));
}
else{
hasTriggerBlock = false;
@ -153,13 +169,13 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
player.sendMessage("\u00A7ctriggerBlock: \u00A7edefault(" + Config.getConfig().getString("DefaultPortalTriggerBlock") + ")");
player.sendMessage("\u00A7cThe block " + triggerBlock.toUpperCase() + " is not a valid block name in minecraft so the trigger block has been set to the default!");
player.sendMessage(Portal.create(pos1, pos2, portalName, destination, serverName));
player.sendMessage(Portal.create(pos1, pos2, portalName, destination, serverName, (PortalArgs[]) extraData.toArray()));
}
}
else{
ConfigAccessor Config = new ConfigAccessor(plugin, "Config.yml");
player.sendMessage("\u00A7atriggerBlock: \u00A7edefault(" + Config.getConfig().getString("DefaultPortalTriggerBlock") + ")");
player.sendMessage(Portal.create(pos1, pos2, portalName, destination, serverName));
player.sendMessage(Portal.create(pos1, pos2, portalName, destination, serverName, (PortalArgs[]) extraData.toArray()));
}
}
else{
@ -432,6 +448,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
boolean hasTriggerBlock = false;
boolean hasDestination = false;
boolean isBungeePortal = false;
boolean needsPermission = false;
for(int i = 1; i < args.length; i++){
if(args[i].toLowerCase().startsWith("name:") && args[i].length() > 5){
@ -449,6 +466,9 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
else if(args[i].toLowerCase().startsWith("bungee:") && args[i].length() > 7){
isBungeePortal = true;
}
else if(args[i].toLowerCase().startsWith("permission:") && args[i].length() > 11){
needsPermission = true;
}
}
@ -456,6 +476,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
if(!hasTriggerBlock){autoComplete.add("triggerblock:");}
if(!hasDestination){autoComplete.add("destination:");autoComplete.add("desti:");}
if(!isBungeePortal){autoComplete.add("bungee:");}
if(!isBungeePortal){autoComplete.add("permission:");}
}
}
Collections.sort(autoComplete);

View File

@ -59,13 +59,13 @@ public class DestinationCommand implements CommandExecutor, TabCompleter {
else if(args[0].toLowerCase().equals("remove")) {
ConfigAccessor portalConfig = new ConfigAccessor(plugin, "Destinations.yml");
if(args.length > 1){
String posX = portalConfig.getConfig().getString(args[1] + ".pos1.X");
String posX = portalConfig.getConfig().getString(args[1] + ".pos.X");
if(posX != null){
Destination.remove(args[1]);
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] The portal \u00A7e" + args[1] + "\u00A7c has been removed!");
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] The destination \u00A7e" + args[1] + "\u00A7c has been removed!");
}
else{
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No portal by that name exists.");
sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No destination by that name exists.");
}
}
else{
@ -84,7 +84,7 @@ public class DestinationCommand implements CommandExecutor, TabCompleter {
sender.sendMessage("");
}
else if(PortalMessagesDisplay == 2){
ConfigAccessor config = new ConfigAccessor(plugin, "Portals.yml");
ConfigAccessor config = new ConfigAccessor(plugin, "Destinations.yml");
plugin.nmsAccess.sendActionBarMessage("{text:\"\u00A7aYou have warped to \u00A7e" + args[1].replaceAll("_", " ") + "\u00A7a.\"}", (Player) sender);
/**plugin.nmsAccess.sendActionBarMessage("[{text:\"You have warped to \",color:green},{text:\"" + config.getConfig().getString(Portal.Portals[portalId].portalName + ".destination").replaceAll("_", " ")
+ "\",color:yellow},{\"text\":\".\",color:green}]", player);*/

View File

@ -11,6 +11,7 @@ import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Set;
import java.util.logging.Level;
@ -89,11 +90,11 @@ public class Portal {
}
public static String create(Location pos1, Location pos2 , String name, String destination, Material triggerBlock) {
return create(pos1, pos2, name, destination, triggerBlock, null);
public static String create(Location pos1, Location pos2 , String name, String destination, Material triggerBlock, PortalArgs... extraData) {
return create(pos1, pos2, name, destination, triggerBlock, null, extraData);
}
public static String create(Location pos1, Location pos2 , String name, String destination, Material triggerBlock, String serverName) {
public static String create(Location pos1, Location pos2, String name, String destination, Material triggerBlock, String serverName, PortalArgs... extraData) {
if(!pos1.getWorld().equals(pos2.getWorld())){
plugin.getLogger().log(Level.WARNING, "pos1 and pos2 must be in the same world!");
@ -158,6 +159,10 @@ public class Portal {
config.getConfig().set(name + ".pos2.X", LowX);
config.getConfig().set(name + ".pos2.Y", LowY);
config.getConfig().set(name + ".pos2.Z", LowZ);
for(PortalArgs arg: extraData){
config.getConfig().set(name + ".extraData." + arg.argName, arg.value);
}
config.saveConfig();
@ -215,8 +220,8 @@ public class Portal {
return triggerBlock.toString();
}
public static String create(Location pos1, Location pos2, String name, String destination) {
return create(pos1, pos2, name, destination,(String) null);
public static String create(Location pos1, Location pos2, String portalName, String name, String destination, PortalArgs... extraData) {
return create(pos1, pos2, name, destination,(String) null);
}
@SuppressWarnings("deprecation")

View File

@ -0,0 +1,16 @@
package com.sekwah.advancedportals.portals;
public class PortalArgs {
public final String argName;
public final String value;
//public final int type;
public PortalArgs(String argName, String value/*, int type*/){
this.argName = argName;
this.value = value;
// may be used if values need to be 100% not string
//this.type = type;
}
}