Updated /f config to support modifying "factionFlagDefaults" and "factionPermDefaults". Both of these settings require an additional argument more than other settings.
Examples: /f config factionFlagDefaults firespread false - set default "FIRESPREAD" faction flag to false /f config factionFlagDefaults monsters true - set default "MONSTERS" faction flag to true /f config factionPermDefaults build ally - for default "BUILD" faction permission, add/remove permission for allies /f config factionPermDefaults withdraw member - for default "WITHDRAW" faction permission, add/remove permission for regular faction members
This commit is contained in:
parent
fd44983ae2
commit
a888a9c5b5
@ -5,6 +5,8 @@ import java.lang.reflect.ParameterizedType;
|
|||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -13,7 +15,10 @@ import org.bukkit.entity.Player;
|
|||||||
import com.massivecraft.factions.Conf;
|
import com.massivecraft.factions.Conf;
|
||||||
import com.massivecraft.factions.P;
|
import com.massivecraft.factions.P;
|
||||||
import com.massivecraft.factions.integration.SpoutFeatures;
|
import com.massivecraft.factions.integration.SpoutFeatures;
|
||||||
|
import com.massivecraft.factions.struct.FFlag;
|
||||||
|
import com.massivecraft.factions.struct.FPerm;
|
||||||
import com.massivecraft.factions.struct.Permission;
|
import com.massivecraft.factions.struct.Permission;
|
||||||
|
import com.massivecraft.factions.struct.Rel;
|
||||||
|
|
||||||
public class CmdConfig extends FCommand
|
public class CmdConfig extends FCommand
|
||||||
{
|
{
|
||||||
@ -174,15 +179,11 @@ public class CmdConfig extends FCommand
|
|||||||
ParameterizedType targSet = (ParameterizedType)target.getGenericType();
|
ParameterizedType targSet = (ParameterizedType)target.getGenericType();
|
||||||
Type innerType = targSet.getActualTypeArguments()[0];
|
Type innerType = targSet.getActualTypeArguments()[0];
|
||||||
|
|
||||||
// not a Set, somehow, and that should be the only collection we're using in Conf.java
|
// Set<?>
|
||||||
if (targSet.getRawType() != Set.class)
|
if (targSet.getRawType() == Set.class)
|
||||||
{
|
{
|
||||||
sendMessage("\""+fieldName+"\" is not a data collection type which can be modified with this command.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set<Material>
|
// Set<Material>
|
||||||
else if (innerType == Material.class)
|
if (innerType == Material.class)
|
||||||
{
|
{
|
||||||
Material newMat = null;
|
Material newMat = null;
|
||||||
try
|
try
|
||||||
@ -228,16 +229,15 @@ public class CmdConfig extends FCommand
|
|||||||
if (stringSet.contains(value))
|
if (stringSet.contains(value))
|
||||||
{
|
{
|
||||||
stringSet.remove(value);
|
stringSet.remove(value);
|
||||||
target.set(null, stringSet);
|
|
||||||
success = "\""+fieldName+"\" set: \""+value+"\" removed.";
|
success = "\""+fieldName+"\" set: \""+value+"\" removed.";
|
||||||
}
|
}
|
||||||
// String not present yet, add it
|
// String not present yet, add it
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
stringSet.add(value);
|
stringSet.add(value);
|
||||||
target.set(null, stringSet);
|
|
||||||
success = "\""+fieldName+"\" set: \""+value+"\" added.";
|
success = "\""+fieldName+"\" set: \""+value+"\" added.";
|
||||||
}
|
}
|
||||||
|
target.set(null, stringSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set of unknown type
|
// Set of unknown type
|
||||||
@ -248,6 +248,121 @@ public class CmdConfig extends FCommand
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Map<?, ?>
|
||||||
|
else if (targSet.getRawType() == Map.class)
|
||||||
|
{
|
||||||
|
if (args.size() < 3)
|
||||||
|
{
|
||||||
|
sendMessage("Cannot change \""+fieldName+"\" map: not enough arguments passed.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Type innerType2 = targSet.getActualTypeArguments()[1];
|
||||||
|
String value1 = args.get(1);
|
||||||
|
String value2 = value.substring(value1.length() + 1);
|
||||||
|
|
||||||
|
// Map<FFlag, Boolean>
|
||||||
|
if (innerType == FFlag.class && innerType2 == Boolean.class)
|
||||||
|
{
|
||||||
|
value1 = value1.toUpperCase();
|
||||||
|
FFlag newFlag = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
newFlag = FFlag.valueOf(value1);
|
||||||
|
}
|
||||||
|
catch (IllegalArgumentException ex) {}
|
||||||
|
|
||||||
|
if (newFlag == null)
|
||||||
|
{
|
||||||
|
sendMessage("Cannot change \""+fieldName+"\" map: \""+value1+"\" is not a valid FFlag.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
Map<FFlag, Boolean> map = (Map<FFlag, Boolean>)target.get(null);
|
||||||
|
|
||||||
|
Boolean targetValue = this.strAsBool(value2);
|
||||||
|
|
||||||
|
map.put(newFlag, targetValue);
|
||||||
|
target.set(null, map);
|
||||||
|
|
||||||
|
if (targetValue)
|
||||||
|
success = "\""+fieldName+"\" flag \""+value1+"\" set to true (enabled).";
|
||||||
|
else
|
||||||
|
success = "\""+fieldName+"\" flag \""+value1+"\" set to false (disabled).";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Map<FPerm, Set<Rel>>
|
||||||
|
else if (innerType == FPerm.class && innerType2 instanceof ParameterizedType)
|
||||||
|
{
|
||||||
|
if (((ParameterizedType)innerType2).getRawType() != Set.class)
|
||||||
|
{
|
||||||
|
sendMessage("\""+fieldName+"\" is not a data type map which can be modified with this command, due to the inner collection type.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
value1 = value1.toUpperCase();
|
||||||
|
value2 = value2.toUpperCase();
|
||||||
|
|
||||||
|
FPerm newPerm = null;
|
||||||
|
Rel newRel = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
newPerm = FPerm.valueOf(value1);
|
||||||
|
newRel = Rel.valueOf(value2);
|
||||||
|
}
|
||||||
|
catch (IllegalArgumentException ex) {}
|
||||||
|
|
||||||
|
if (newPerm == null)
|
||||||
|
{
|
||||||
|
sendMessage("Cannot change \""+fieldName+"\" map: \""+value1+"\" is not a valid FPerm.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (newRel == null)
|
||||||
|
{
|
||||||
|
sendMessage("Cannot change \""+fieldName+"\" map: \""+value2+"\" is not a valid Rel.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
Map<FPerm, Set<Rel>> map = (Map<FPerm, Set<Rel>>)target.get(null);
|
||||||
|
|
||||||
|
Set<Rel> relSet = map.get(newPerm);
|
||||||
|
if (relSet == null)
|
||||||
|
relSet = new HashSet<Rel>();
|
||||||
|
|
||||||
|
// Rel already present, so remove it
|
||||||
|
if (relSet.contains(newRel))
|
||||||
|
{
|
||||||
|
relSet.remove(newRel);
|
||||||
|
success = "\""+fieldName+"\" permission \""+value1+"\": relation \""+value2+"\" removed.";
|
||||||
|
}
|
||||||
|
// Rel not present yet, add it
|
||||||
|
else
|
||||||
|
{
|
||||||
|
relSet.add(newRel);
|
||||||
|
success = "\""+fieldName+"\" permission \""+value1+"\": relation \""+value2+"\" added.";
|
||||||
|
}
|
||||||
|
|
||||||
|
map.put(newPerm, relSet);
|
||||||
|
target.set(null, map);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Map of unknown type
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sendMessage("\""+fieldName+"\" is not a data type map which can be modified with this command.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// not a Set or Map?
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sendMessage("\""+fieldName+"\" is not a data collection type which can be modified with this command.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// unknown type
|
// unknown type
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user