In the middle of refactoring to merged role and relation as one enum

This commit is contained in:
Olof Larsson
2011-10-23 17:30:41 +02:00
parent 4f7fd6dd96
commit d280f9409d
26 changed files with 278 additions and 100 deletions

View File

@ -0,0 +1,46 @@
package com.massivecraft.factions.struct;
/**
* Flags that describe the nature of a faction and it's territory.
* Can monsters spawn there? May fire spread etc? Is the faction permanent?
* These flags have nothing to do with player-permission.
*
* The flags are either true or false.
*/
public enum FactionFlag
{
// Faction flags
PERMANENT,
PEACEFUL, // This faction is friends with everyone
INFPOWER, // This faction has infinite power: TODO: Add faction has enough method. Replace the permanentpower level
// (Faction) Territory flags
POWERLOSS, // Regardless of death-reason players loose power on death IF powerloss is true in this territory
PVP,
FRIENDLYFIRE, // Can members/allies/friends damage eachother in this territory?
MONSTERS,
EXPLOSIONS,
FIRESPREAD,
LIGHTNING,
;
/**
* The state for newly created factions.
*/
public boolean getDefault()
{
// Use config file for this later.
return true;
}
/**
* Is this flag changeable by the faction leaders or not?
* The normal faction members can never change these flags.
* Note that server operators and admin bypassers can change all flags.
*/
public boolean isChangeable()
{
// TODO: Use config file
return true;
}
}

View File

@ -0,0 +1,17 @@
package com.massivecraft.factions.struct;
/**
* Permissions that you (a player) may or may not have in the territory of a certain faction.
*
* You need a certain rel to be able
*/
public enum FactionPlayerPerm
{
BUILD, // This player can build in the faction
PAINBUILD, // This player can build in the faction BUT will take damage each time. This is overridden by BUILD if player has both
DOOR,
WORKBENCH,
CONTAINER,
BUTTON,
LEVER,
}

View File

@ -0,0 +1,119 @@
package com.massivecraft.factions.struct;
import org.bukkit.ChatColor;
import com.massivecraft.factions.Conf;
public enum Rel
{
LEADER (70, "leader"),
OFFICER(60, "officer"),
MEMBER (50, "member"),
ALLY (40, "ally"),
TRUCE (30, "truce"),
NEUTRAL(20, "neutral"),
ENEMY (10, "enemy"),
;
public final int value;
public final String nicename;
private Rel(final int value, final String nicename)
{
this.value = value;
this.nicename = nicename;
}
public static Rel parse(String str)
{
if (str == null || str.length() < 1) return null;
str = str.toLowerCase();
// These are to allow conversion from the old system.
if (str.equals("admin"))
{
return LEADER;
}
if (str.equals("moderator"))
{
return OFFICER;
}
if (str.equals("normal"))
{
return MEMBER;
}
// This is how we check: Based on first char.
char c = str.charAt(0);
if (c == 'l') return LEADER;
if (c == 'o') return OFFICER;
if (c == 'm') return MEMBER;
if (c == 'a') return ALLY;
if (c == 't') return TRUCE;
if (c == 'n') return NEUTRAL;
if (c == 'e') return ENEMY;
return null;
}
@Override
public String toString()
{
return this.nicename;
}
public boolean isAtLeast(Rel rel)
{
return this.value >= rel.value;
}
public boolean isAtMost(Rel rel)
{
return this.value <= rel.value;
}
public boolean isLessThan(Rel rel)
{
return this.value < rel.value;
}
public ChatColor getColor()
{
if (this == MEMBER)
return Conf.colorMember;
else if (this == ALLY)
return Conf.colorAlly;
else if (this == NEUTRAL)
return Conf.colorNeutral;
else
return Conf.colorEnemy;
}
public String getPrefix()
{
if (this == LEADER)
{
return Conf.prefixAdmin;
}
if (this == OFFICER)
{
return Conf.prefixMod;
}
return "";
}
// TODO: ADD TRUCE!!!!
public double getRelationCost()
{
if (this == ENEMY)
return Conf.econCostEnemy;
else if (this == ALLY)
return Conf.econCostAlly;
else
return Conf.econCostNeutral;
}
}

View File

@ -5,17 +5,18 @@ import org.bukkit.ChatColor;
import com.massivecraft.factions.Conf;
public enum Relation
public enum RelationDEPR
{
MEMBER(3, "member"),
ALLY(2, "ally"),
NEUTRAL(1, "neutral"),
ENEMY(0, "enemy");
ENEMY(0, "enemy"),
;
public final int value;
public final String nicename;
private Relation(final int value, final String nicename)
private RelationDEPR(final int value, final String nicename)
{
this.value = value;
this.nicename = nicename;

View File

@ -2,7 +2,7 @@ package com.massivecraft.factions.struct;
import com.massivecraft.factions.Conf;
public enum Role
public enum RoleDEPR
{
ADMIN(2, "admin"),
MODERATOR(1, "moderator"),
@ -11,7 +11,7 @@ public enum Role
public final int value;
public final String nicename;
private Role(final int value, final String nicename)
private RoleDEPR(final int value, final String nicename)
{
this.value = value;
this.nicename = nicename;