Should be the complete code for custom permissions to use portals
This commit is contained in:
parent
ac21a19a3d
commit
5a2bd1796d
|
@ -1,7 +1,7 @@
|
|||
package com.sekwah.advancedportals;
|
||||
|
||||
import com.sekwah.advancedportals.portals.Portal;
|
||||
import com.sekwah.advancedportals.portals.PortalArgs;
|
||||
import com.sekwah.advancedportals.portals.PortalArg;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
|
@ -80,7 +80,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
|
|||
String serverName = null;
|
||||
String permission = null;
|
||||
|
||||
ArrayList<PortalArgs> extraData = new ArrayList<PortalArgs>();
|
||||
ArrayList<PortalArg> extraData = new ArrayList<PortalArg>();
|
||||
|
||||
for(int i = 1; i < args.length; i++){
|
||||
if(args[i].toLowerCase().startsWith("name:") && args[i].length() > 5){
|
||||
|
@ -115,7 +115,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
|
|||
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));
|
||||
extraData.add(new PortalArg("permission", serverName));
|
||||
}
|
||||
}
|
||||
if(!hasName){
|
||||
|
@ -161,7 +161,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
|
|||
triggerBlockMat = Material.getMaterial(triggerBlock.toUpperCase());
|
||||
if(triggerBlockMat != null){
|
||||
player.sendMessage("\u00A7atriggerBlock: \u00A7e" + triggerBlock.toUpperCase());
|
||||
player.sendMessage(Portal.create(pos1, pos2, portalName, destination, triggerBlockMat, serverName, (PortalArgs[]) extraData.toArray()));
|
||||
player.sendMessage(Portal.create(pos1, pos2, portalName, destination, triggerBlockMat, serverName, (PortalArg[]) extraData.toArray()));
|
||||
}
|
||||
else{
|
||||
hasTriggerBlock = false;
|
||||
|
@ -169,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, (PortalArgs[]) extraData.toArray()));
|
||||
player.sendMessage(Portal.create(pos1, pos2, portalName, destination, serverName, (PortalArg[]) 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, (PortalArgs[]) extraData.toArray()));
|
||||
player.sendMessage(Portal.create(pos1, pos2, portalName, destination, serverName, (PortalArg[]) extraData.toArray()));
|
||||
}
|
||||
}
|
||||
else{
|
||||
|
|
|
@ -11,7 +11,6 @@ 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;
|
||||
|
||||
|
@ -90,11 +89,11 @@ public class Portal {
|
|||
|
||||
}
|
||||
|
||||
public static String create(Location pos1, Location pos2 , String name, String destination, Material triggerBlock, PortalArgs... extraData) {
|
||||
public static String create(Location pos1, Location pos2 , String name, String destination, Material triggerBlock, PortalArg... 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, PortalArgs... extraData) {
|
||||
public static String create(Location pos1, Location pos2, String name, String destination, Material triggerBlock, String serverName, PortalArg... portalArgs) {
|
||||
|
||||
if(!pos1.getWorld().equals(pos2.getWorld())){
|
||||
plugin.getLogger().log(Level.WARNING, "pos1 and pos2 must be in the same world!");
|
||||
|
@ -160,8 +159,8 @@ public class Portal {
|
|||
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);
|
||||
for(PortalArg arg: portalArgs){
|
||||
config.getConfig().set(name + ".portalArgs." + arg.argName, arg.value);
|
||||
}
|
||||
|
||||
config.saveConfig();
|
||||
|
@ -220,7 +219,7 @@ public class Portal {
|
|||
return triggerBlock.toString();
|
||||
}
|
||||
|
||||
public static String create(Location pos1, Location pos2, String portalName, String name, String destination, PortalArgs... extraData) {
|
||||
public static String create(Location pos1, Location pos2, String portalName, String name, String destination, PortalArg... extraData) {
|
||||
return create(pos1, pos2, name, destination,(String) null);
|
||||
}
|
||||
|
||||
|
@ -345,8 +344,15 @@ public class Portal {
|
|||
ConfigAccessor configDesti = new ConfigAccessor(plugin, "Destinations.yml");
|
||||
String destiName = config.getConfig().getString(portalName + ".destination");
|
||||
if(configDesti.getConfig().getString(destiName + ".world") != null){
|
||||
boolean warped = Destination.warp(player, destiName);
|
||||
return warped;
|
||||
String permission = config.getConfig().getString(portalName + ".portalArgs.permission");
|
||||
if(permission != null && player.hasPermission(permission)){
|
||||
boolean warped = Destination.warp(player, destiName);
|
||||
return warped;
|
||||
}
|
||||
else{
|
||||
player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You do not have permission to use this portal!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else{
|
||||
player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] The destination you are currently attempting to warp to doesnt exist!");
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
package com.sekwah.advancedportals.portals;
|
||||
|
||||
public class PortalArgs {
|
||||
public class PortalArg {
|
||||
|
||||
public final String argName;
|
||||
public final String value;
|
||||
//public final int type;
|
||||
|
||||
public PortalArgs(String argName, String value/*, int type*/){
|
||||
public PortalArg(String argName, String value/*, int type*/){
|
||||
this.argName = argName;
|
||||
this.value = value;
|
||||
// may be used if values need to be 100% not string
|
Loading…
Reference in New Issue