Maven Attempt 1
This commit is contained in:
@ -1,23 +0,0 @@
|
||||
package com.massivecraft.factions;
|
||||
|
||||
public class Const
|
||||
{
|
||||
// Collections & Aspects
|
||||
public static final String BASENAME = "factions";
|
||||
public static final String BASENAME_ = BASENAME+"_";
|
||||
|
||||
public static final String COLLECTION_BOARD = BASENAME_+"board";
|
||||
public static final String COLLECTION_FACTION = BASENAME_+"faction";
|
||||
public static final String COLLECTION_UPLAYER = BASENAME_+"uplayer";
|
||||
public static final String COLLECTION_MPLAYER = BASENAME_+"mplayer";
|
||||
public static final String COLLECTION_UCONF = BASENAME_+"uconf";
|
||||
public static final String COLLECTION_MCONF = BASENAME_+"mconf";
|
||||
|
||||
public static final String ASPECT = BASENAME;
|
||||
|
||||
// ASCII Map
|
||||
public static final int MAP_HEIGHT = 8;
|
||||
public static final int MAP_WIDTH = 39;
|
||||
public static final char[] MAP_KEY_CHARS = "\\/#?$%=&^ABCDEFGHJKLMNOPQRSTUVWXYZ1234567890abcdeghjmnopqrsuvwxyz".toCharArray();
|
||||
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
package com.massivecraft.factions;
|
||||
|
||||
|
||||
public interface EconomyParticipator extends RelationParticipator
|
||||
{
|
||||
public boolean msg(String msg, Object... args);
|
||||
}
|
@ -1,125 +0,0 @@
|
||||
package com.massivecraft.factions;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import com.massivecraft.factions.entity.Board;
|
||||
import com.massivecraft.factions.entity.BoardColl;
|
||||
import com.massivecraft.factions.entity.BoardColls;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.FactionColl;
|
||||
import com.massivecraft.factions.entity.FactionColls;
|
||||
import com.massivecraft.factions.entity.MPlayerColl;
|
||||
import com.massivecraft.factions.entity.UPlayerColl;
|
||||
import com.massivecraft.factions.entity.UPlayerColls;
|
||||
import com.massivecraft.massivecore.EngineAbstract;
|
||||
import com.massivecraft.massivecore.event.EventMassiveCoreUuidUpdate;
|
||||
import com.massivecraft.massivecore.util.IdUpdateUtil;
|
||||
import com.massivecraft.massivecore.util.MUtil;
|
||||
|
||||
public class EngineIdUpdate extends EngineAbstract
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static EngineIdUpdate i = new EngineIdUpdate();
|
||||
public static EngineIdUpdate get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Plugin getPlugin()
|
||||
{
|
||||
return Factions.get();
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// LISTENER
|
||||
// -------------------------------------------- //
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void update(EventMassiveCoreUuidUpdate event)
|
||||
{
|
||||
for (FactionColl coll : FactionColls.get().getColls())
|
||||
{
|
||||
for (Faction entity : coll.getAll())
|
||||
{
|
||||
update(coll, entity);
|
||||
}
|
||||
}
|
||||
|
||||
IdUpdateUtil.update(MPlayerColl.get());
|
||||
|
||||
for (UPlayerColl coll : UPlayerColls.get().getColls())
|
||||
{
|
||||
IdUpdateUtil.update(coll);
|
||||
}
|
||||
|
||||
for (BoardColl coll : BoardColls.get().getColls())
|
||||
{
|
||||
update(coll);
|
||||
}
|
||||
}
|
||||
|
||||
public static void update(FactionColl coll, Faction entity)
|
||||
{
|
||||
// Before and After
|
||||
Set<String> before = entity.getInvitedPlayerIds();
|
||||
if (before == null) return;
|
||||
Set<String> after = IdUpdateUtil.update(before, true);
|
||||
if (after == null) return;
|
||||
|
||||
// NoChange
|
||||
if (MUtil.equals(before, after)) return;
|
||||
|
||||
// Apply
|
||||
entity.setInvitedPlayerIds(after);
|
||||
entity.sync();
|
||||
}
|
||||
|
||||
public static void update(BoardColl coll)
|
||||
{
|
||||
for (Board board : coll.getAll())
|
||||
{
|
||||
update(board);
|
||||
}
|
||||
}
|
||||
|
||||
public static void update(Board board)
|
||||
{
|
||||
boolean changed = false;
|
||||
for (TerritoryAccess ta : board.getMap().values())
|
||||
{
|
||||
changed |= update(ta);
|
||||
}
|
||||
if (changed)
|
||||
{
|
||||
board.changed();
|
||||
board.sync();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean update(TerritoryAccess entity)
|
||||
{
|
||||
// Before and After
|
||||
Set<String> before = entity.playerIds;
|
||||
if (before == null) return false;
|
||||
Set<String> after = IdUpdateUtil.update(before, true);
|
||||
if (after == null) return false;
|
||||
|
||||
// NoChange
|
||||
if (MUtil.equals(before, after)) return false;
|
||||
|
||||
// Apply
|
||||
entity.playerIds = after;
|
||||
//entity.sync();
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
package com.massivecraft.factions;
|
||||
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.massivecore.util.extractor.Extractor;
|
||||
|
||||
public class ExtractorFactionAccountId implements Extractor
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static ExtractorFactionAccountId i = new ExtractorFactionAccountId();
|
||||
public static ExtractorFactionAccountId get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE: EXTRACTOR
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Object extract(Object o)
|
||||
{
|
||||
if (o instanceof Faction)
|
||||
{
|
||||
String factionId = ((Faction)o).getId();
|
||||
if (factionId == null) return null;
|
||||
return Factions.FACTION_MONEY_ACCOUNT_ID_PREFIX + factionId;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -1,122 +0,0 @@
|
||||
package com.massivecraft.factions;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.massivecraft.factions.entity.UConf;
|
||||
|
||||
|
||||
/**
|
||||
* 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 FFlag
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// ENUM
|
||||
// -------------------------------------------- //
|
||||
|
||||
// Faction flags
|
||||
PERMANENT("permanent", "<i>A permanent faction will never be deleted.", false),
|
||||
PEACEFUL("peaceful", "<i>Allways in truce with other factions.", false),
|
||||
INFPOWER("infpower", "<i>This flag gives the faction infinite power.", false),
|
||||
// This faction has infinite power: TODO: Add faction has enough method. Replace the permanentpower level
|
||||
|
||||
// (Faction) Territory flags
|
||||
// If a faction later could have many different territories this would probably be in another enum
|
||||
POWERLOSS("powerloss", "<i>Is power lost on death in this territory?", true),
|
||||
PVP("pvp", "<i>Can you PVP in territory?", true),
|
||||
FRIENDLYFIRE("friendlyfire", "<i>Can friends hurt eachother here?", false),
|
||||
MONSTERS("monsters", "<i>Can monsters spawn in this territory?", true),
|
||||
EXPLOSIONS("explosions", "<i>Can explosions occur in this territory?", true),
|
||||
OFFLINE_EXPLOSIONS("offlineexplosions", "<i>Can explosions occur if faction is offline?", false),
|
||||
FIRESPREAD("firespread", "<i>Can fire spread in territory?", true),
|
||||
ENDERGRIEF("endergrief", "<i>Can endermen grief in this territory?", false),
|
||||
|
||||
// END OF LIST
|
||||
;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
private final String nicename;
|
||||
public String getNicename() { return this.nicename; }
|
||||
|
||||
private final String desc;
|
||||
public String getDescription() { return this.desc; }
|
||||
|
||||
public final boolean defaultDefault;
|
||||
public boolean getDefaultDefault() { return this.defaultDefault; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private FFlag(String nicename, final String desc, boolean defaultDefault)
|
||||
{
|
||||
this.nicename = nicename;
|
||||
this.desc = desc;
|
||||
this.defaultDefault = defaultDefault;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// DEFAULTS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public boolean getDefault(Object o)
|
||||
{
|
||||
Boolean ret = UConf.get(o).defaultFactionFlags.get(this);
|
||||
if (ret == null) return this.getDefaultDefault();
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static Map<FFlag, Boolean> getDefaultDefaults()
|
||||
{
|
||||
Map<FFlag, Boolean> ret = new LinkedHashMap<FFlag, Boolean>();
|
||||
for (FFlag flag : values())
|
||||
{
|
||||
ret.put(flag, flag.getDefaultDefault());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// PARSE
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static FFlag parse(String str)
|
||||
{
|
||||
str = str.toLowerCase();
|
||||
if (str.startsWith("per")) return PERMANENT;
|
||||
if (str.startsWith("pea")) return PEACEFUL;
|
||||
if (str.startsWith("i")) return INFPOWER;
|
||||
if (str.startsWith("pow")) return POWERLOSS;
|
||||
if (str.startsWith("pvp")) return PVP;
|
||||
if (str.startsWith("fr") || str.startsWith("ff")) return FRIENDLYFIRE;
|
||||
if (str.startsWith("m")) return MONSTERS;
|
||||
if (str.startsWith("ex")) return EXPLOSIONS;
|
||||
if (str.startsWith("o")) return OFFLINE_EXPLOSIONS;
|
||||
if (str.startsWith("fi")) return FIRESPREAD;
|
||||
if (str.startsWith("en")) return ENDERGRIEF;
|
||||
return null;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// UTIL
|
||||
// -------------------------------------------- //
|
||||
|
||||
public String getStateInfo(boolean value, boolean withDesc)
|
||||
{
|
||||
String ret = (value ? "<g>YES" : "<b>NOO") + "<c> " + this.getNicename();
|
||||
if (withDesc)
|
||||
{
|
||||
ret += " " + this.getDescription();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
@ -1,221 +0,0 @@
|
||||
package com.massivecraft.factions;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.massivecraft.factions.entity.BoardColls;
|
||||
import com.massivecraft.factions.entity.UPlayer;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.UConf;
|
||||
import com.massivecraft.massivecore.ps.PS;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
/**
|
||||
* Permissions that you (a player) may or may not have in the territory of a certain faction.
|
||||
* Each faction have many Rel's assigned to each one of these Perms.
|
||||
*/
|
||||
public enum FPerm
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// ENUM
|
||||
// -------------------------------------------- //
|
||||
|
||||
BUILD(true, "build", "edit the terrain", Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.ALLY),
|
||||
PAINBUILD(true, "painbuild", "edit, take damage"),
|
||||
DOOR(true, "door", "use doors", Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY),
|
||||
BUTTON(true, "button", "use stone buttons", Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY),
|
||||
LEVER(true, "lever", "use levers", Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY),
|
||||
CONTAINER(true, "container", "use containers", Rel.LEADER, Rel.OFFICER, Rel.MEMBER),
|
||||
|
||||
INVITE(false, "invite", "invite players", Rel.LEADER, Rel.OFFICER),
|
||||
KICK(false, "kick", "kick members", Rel.LEADER, Rel.OFFICER),
|
||||
SETHOME(false, "sethome", "set the home", Rel.LEADER, Rel.OFFICER),
|
||||
WITHDRAW(false, "withdraw", "withdraw money", Rel.LEADER, Rel.OFFICER),
|
||||
TERRITORY(false, "territory", "claim or unclaim", Rel.LEADER, Rel.OFFICER),
|
||||
ACCESS(false, "access", "grant territory", Rel.LEADER, Rel.OFFICER),
|
||||
DISBAND(false, "disband", "disband the faction", Rel.LEADER),
|
||||
PERMS(false, "perms", "manage permissions", Rel.LEADER),
|
||||
|
||||
// END OF LIST
|
||||
;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
private final boolean territoryPerm;
|
||||
public boolean isTerritoryPerm() { return this.territoryPerm; }
|
||||
|
||||
private final String nicename;
|
||||
public String getNicename() { return this.nicename; }
|
||||
|
||||
private final String desc;
|
||||
public String getDescription() { return this.desc; }
|
||||
|
||||
public final Set<Rel> defaultDefault;
|
||||
public Set<Rel> getDefaultDefault() { return new LinkedHashSet<Rel>(this.defaultDefault); }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private FPerm(boolean territoryPerm, final String nicename, final String desc, final Rel... rels)
|
||||
{
|
||||
this.territoryPerm = territoryPerm;
|
||||
this.nicename = nicename;
|
||||
this.desc = desc;
|
||||
|
||||
Set<Rel> defaultDefaultValue = new LinkedHashSet<Rel>();
|
||||
defaultDefaultValue.addAll(Arrays.asList(rels));
|
||||
defaultDefaultValue = Collections.unmodifiableSet(defaultDefaultValue);
|
||||
this.defaultDefault = defaultDefaultValue;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// DEFAULTS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public Set<Rel> getDefault(Object o)
|
||||
{
|
||||
Set<Rel> ret = UConf.get(o).defaultFactionPerms.get(this);
|
||||
if (ret == null) return this.getDefaultDefault();
|
||||
ret = new LinkedHashSet<Rel>(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static Map<FPerm, Set<Rel>> getDefaultDefaults()
|
||||
{
|
||||
Map<FPerm, Set<Rel>> ret = new LinkedHashMap<FPerm, Set<Rel>>();
|
||||
for (FPerm fperm : values())
|
||||
{
|
||||
ret.put(fperm, fperm.getDefaultDefault());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// PARSE
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static FPerm parse(String str)
|
||||
{
|
||||
str = str.toLowerCase();
|
||||
if (str.startsWith("a")) return ACCESS;
|
||||
if (str.startsWith("bui")) return BUILD;
|
||||
if (str.startsWith("pa")) return PAINBUILD;
|
||||
if (str.startsWith("do")) return DOOR;
|
||||
if (str.startsWith("but")) return BUTTON;
|
||||
if (str.startsWith("l")) return LEVER;
|
||||
if (str.startsWith("co")) return CONTAINER;
|
||||
if (str.startsWith("i")) return INVITE;
|
||||
if (str.startsWith("k")) return KICK;
|
||||
if (str.startsWith("s")) return SETHOME;
|
||||
if (str.startsWith("w")) return WITHDRAW;
|
||||
if (str.startsWith("t")) return TERRITORY;
|
||||
if (str.startsWith("di")) return DISBAND;
|
||||
if (str.startsWith("pe")) return PERMS;
|
||||
return null;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// HAS?
|
||||
// -------------------------------------------- //
|
||||
|
||||
public String createDeniedMessage(UPlayer uplayer, Faction hostFaction)
|
||||
{
|
||||
String ret = Txt.parse("%s<b> does not allow you to %s<b>.", hostFaction.describeTo(uplayer, true), this.getDescription());
|
||||
if (Perm.ADMIN.has(uplayer.getPlayer()))
|
||||
{
|
||||
ret += Txt.parse("\n<i>You can bypass by using " + Factions.get().getOuterCmdFactions().cmdFactionsAdmin.getUseageTemplate(false));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public boolean has(Faction faction, Faction hostFaction)
|
||||
{
|
||||
Rel rel = faction.getRelationTo(hostFaction);
|
||||
return hostFaction.getPermittedRelations(this).contains(rel);
|
||||
}
|
||||
|
||||
public boolean has(UPlayer uplayer, Faction hostFaction, boolean verboose)
|
||||
{
|
||||
if (uplayer.isUsingAdminMode()) return true;
|
||||
|
||||
Rel rel = uplayer.getRelationTo(hostFaction);
|
||||
if (hostFaction.getPermittedRelations(this).contains(rel)) return true;
|
||||
|
||||
if (verboose) uplayer.sendMessage(this.createDeniedMessage(uplayer, hostFaction));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean has(UPlayer uplayer, PS ps, boolean verboose)
|
||||
{
|
||||
if (uplayer.isUsingAdminMode()) return true;
|
||||
|
||||
TerritoryAccess ta = BoardColls.get().getTerritoryAccessAt(ps);
|
||||
Faction hostFaction = ta.getHostFaction(ps);
|
||||
|
||||
if (this.isTerritoryPerm())
|
||||
{
|
||||
Boolean hasTerritoryAccess = ta.hasTerritoryAccess(uplayer);
|
||||
if (hasTerritoryAccess != null)
|
||||
{
|
||||
if (verboose && !hasTerritoryAccess)
|
||||
{
|
||||
uplayer.sendMessage(this.createDeniedMessage(uplayer, hostFaction));
|
||||
}
|
||||
return hasTerritoryAccess;
|
||||
}
|
||||
}
|
||||
|
||||
return this.has(uplayer, hostFaction, verboose);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// UTIL: ASCII
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static String getStateHeaders()
|
||||
{
|
||||
String ret = "";
|
||||
for (Rel rel : Rel.values())
|
||||
{
|
||||
ret += rel.getColor().toString();
|
||||
ret += rel.toString().substring(0, 3);
|
||||
ret += " ";
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public String getStateInfo(Set<Rel> value, boolean withDesc)
|
||||
{
|
||||
String ret = "";
|
||||
|
||||
for (Rel rel : Rel.values())
|
||||
{
|
||||
if (value.contains(rel))
|
||||
{
|
||||
ret += "<g>YES";
|
||||
}
|
||||
else
|
||||
{
|
||||
ret += "<b>NOO";
|
||||
}
|
||||
ret += " ";
|
||||
}
|
||||
|
||||
ret +="<c>"+this.getNicename();
|
||||
if (withDesc)
|
||||
{
|
||||
ret += " <i>" + this.getDescription();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
package com.massivecraft.factions;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.massivecraft.factions.entity.UPlayer;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.massivecore.Predictate;
|
||||
|
||||
public class FactionEqualsPredictate implements Predictate<CommandSender>, Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
private final String factionId;
|
||||
public String getFactionId() { return this.factionId; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public FactionEqualsPredictate(Faction faction)
|
||||
{
|
||||
this.factionId = faction.getId();
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public boolean apply(CommandSender sender)
|
||||
{
|
||||
UPlayer uplayer = UPlayer.get(sender);
|
||||
return this.factionId.equals(uplayer.getFactionId());
|
||||
}
|
||||
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
package com.massivecraft.factions;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.massivecore.util.MUtil;
|
||||
|
||||
public class FactionListComparator implements Comparator<Faction>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static FactionListComparator i = new FactionListComparator();
|
||||
public static FactionListComparator get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE: COMPARATOR
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public int compare(Faction f1, Faction f2)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
// Null
|
||||
if (f1 == null && f2 == null) ret = 0;
|
||||
if (f1 == null) ret = -1;
|
||||
if (f2 == null) ret = +1;
|
||||
if (ret != 0) return ret;
|
||||
|
||||
// None a.k.a. Wilderness
|
||||
if (f1.isNone() && f2.isNone()) ret = 0;
|
||||
if (f1.isNone()) ret = -1;
|
||||
if (f2.isNone()) ret = +1;
|
||||
if (ret != 0) return ret;
|
||||
|
||||
// Players Online
|
||||
ret = f2.getUPlayersWhereOnline(true).size() - f1.getUPlayersWhereOnline(true).size();
|
||||
if (ret != 0) return ret;
|
||||
|
||||
// Players Total
|
||||
ret = f2.getUPlayers().size() - f1.getUPlayers().size();
|
||||
if (ret != 0) return ret;
|
||||
|
||||
// Tie by Id
|
||||
return MUtil.compare(f1.getId(), f2.getId());
|
||||
}
|
||||
|
||||
}
|
@ -1,195 +0,0 @@
|
||||
package com.massivecraft.factions;
|
||||
|
||||
import com.massivecraft.factions.adapter.BoardAdapter;
|
||||
import com.massivecraft.factions.adapter.BoardMapAdapter;
|
||||
import com.massivecraft.factions.adapter.FFlagAdapter;
|
||||
import com.massivecraft.factions.adapter.FPermAdapter;
|
||||
import com.massivecraft.factions.adapter.FactionPreprocessAdapter;
|
||||
import com.massivecraft.factions.adapter.RelAdapter;
|
||||
import com.massivecraft.factions.adapter.TerritoryAccessAdapter;
|
||||
import com.massivecraft.factions.chat.modifier.ChatModifierLc;
|
||||
import com.massivecraft.factions.chat.modifier.ChatModifierLp;
|
||||
import com.massivecraft.factions.chat.modifier.ChatModifierParse;
|
||||
import com.massivecraft.factions.chat.modifier.ChatModifierRp;
|
||||
import com.massivecraft.factions.chat.modifier.ChatModifierUc;
|
||||
import com.massivecraft.factions.chat.modifier.ChatModifierUcf;
|
||||
import com.massivecraft.factions.chat.tag.ChatTagRelcolor;
|
||||
import com.massivecraft.factions.chat.tag.ChatTagRole;
|
||||
import com.massivecraft.factions.chat.tag.ChatTagRoleprefix;
|
||||
import com.massivecraft.factions.chat.tag.ChatTagName;
|
||||
import com.massivecraft.factions.chat.tag.ChatTagNameforce;
|
||||
import com.massivecraft.factions.chat.tag.ChatTagRoleprefixforce;
|
||||
import com.massivecraft.factions.chat.tag.ChatTagTitle;
|
||||
import com.massivecraft.factions.cmd.*;
|
||||
import com.massivecraft.factions.entity.Board;
|
||||
import com.massivecraft.factions.entity.BoardColls;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.MPlayerColl;
|
||||
import com.massivecraft.factions.entity.UConfColls;
|
||||
import com.massivecraft.factions.entity.UPlayerColls;
|
||||
import com.massivecraft.factions.entity.FactionColls;
|
||||
import com.massivecraft.factions.entity.MConfColl;
|
||||
import com.massivecraft.factions.integration.dynmap.IntegrationDynmap;
|
||||
import com.massivecraft.factions.integration.dynmap.IntegrationDynmapFactions;
|
||||
import com.massivecraft.factions.integration.herochat.IntegrationHerochat;
|
||||
import com.massivecraft.factions.integration.lwc.IntegrationLwc;
|
||||
import com.massivecraft.factions.listeners.FactionsListenerChat;
|
||||
import com.massivecraft.factions.listeners.FactionsListenerEcon;
|
||||
import com.massivecraft.factions.listeners.FactionsListenerExploit;
|
||||
import com.massivecraft.factions.listeners.FactionsListenerMain;
|
||||
import com.massivecraft.factions.mixin.PowerMixin;
|
||||
import com.massivecraft.factions.mixin.PowerMixinDefault;
|
||||
import com.massivecraft.factions.task.TaskPlayerDataRemove;
|
||||
import com.massivecraft.factions.task.TaskEconLandReward;
|
||||
import com.massivecraft.factions.task.TaskPlayerPowerUpdate;
|
||||
import com.massivecraft.massivecore.Aspect;
|
||||
import com.massivecraft.massivecore.AspectColl;
|
||||
import com.massivecraft.massivecore.MassivePlugin;
|
||||
import com.massivecraft.massivecore.Multiverse;
|
||||
import com.massivecraft.massivecore.util.MUtil;
|
||||
import com.massivecraft.massivecore.xlib.gson.Gson;
|
||||
import com.massivecraft.massivecore.xlib.gson.GsonBuilder;
|
||||
|
||||
|
||||
public class Factions extends MassivePlugin
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTANTS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public final static String FACTION_MONEY_ACCOUNT_ID_PREFIX = "faction-";
|
||||
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static Factions i;
|
||||
public static Factions get() { return i; }
|
||||
public Factions() { Factions.i = this; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
// Commands
|
||||
private CmdFactions outerCmdFactions;
|
||||
public CmdFactions getOuterCmdFactions() { return this.outerCmdFactions; }
|
||||
|
||||
// Aspects
|
||||
private Aspect aspect;
|
||||
public Aspect getAspect() { return this.aspect; }
|
||||
public Multiverse getMultiverse() { return this.getAspect().getMultiverse(); }
|
||||
|
||||
// Database Initialized
|
||||
private boolean databaseInitialized;
|
||||
public boolean isDatabaseInitialized() { return this.databaseInitialized; }
|
||||
|
||||
// Mixins
|
||||
private PowerMixin powerMixin = null;
|
||||
public PowerMixin getPowerMixin() { return this.powerMixin == null ? PowerMixinDefault.get() : this.powerMixin; }
|
||||
public void setPowerMixin(PowerMixin powerMixin) { this.powerMixin = powerMixin; }
|
||||
|
||||
// Gson without preprocessors
|
||||
public final Gson gsonWithoutPreprocessors = this.getGsonBuilderWithoutPreprocessors().create();
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void onEnable()
|
||||
{
|
||||
if ( ! preEnable()) return;
|
||||
|
||||
// Initialize Aspects
|
||||
this.aspect = AspectColl.get().get(Const.ASPECT, true);
|
||||
this.aspect.register();
|
||||
this.aspect.setDesc(
|
||||
"<i>If the factions system even is enabled and how it's configured.",
|
||||
"<i>What factions exists and what players belong to them."
|
||||
);
|
||||
|
||||
// Register Faction accountId Extractor
|
||||
// TODO: Perhaps this should be placed in the econ integration somewhere?
|
||||
MUtil.registerExtractor(String.class, "accountId", ExtractorFactionAccountId.get());
|
||||
|
||||
// Initialize Database
|
||||
this.databaseInitialized = false;
|
||||
MConfColl.get().init();
|
||||
MPlayerColl.get().init();
|
||||
UConfColls.get().init();
|
||||
UPlayerColls.get().init();
|
||||
FactionColls.get().init();
|
||||
BoardColls.get().init();
|
||||
FactionColls.get().reindexUPlayers();
|
||||
this.databaseInitialized = true;
|
||||
|
||||
// Commands
|
||||
this.outerCmdFactions = new CmdFactions();
|
||||
this.outerCmdFactions.register();
|
||||
|
||||
// Setup Listeners
|
||||
EngineIdUpdate.get().activate();
|
||||
FactionsListenerMain.get().setup();
|
||||
FactionsListenerChat.get().setup();
|
||||
FactionsListenerExploit.get().setup();
|
||||
|
||||
// TODO: This listener is a work in progress.
|
||||
// The goal is that the Econ integration should be completely based on listening to our own events.
|
||||
// Right now only a few situations are handled through this listener.
|
||||
FactionsListenerEcon.get().setup();
|
||||
|
||||
// Integrate
|
||||
this.integrate(
|
||||
IntegrationHerochat.get(),
|
||||
IntegrationLwc.get(),
|
||||
IntegrationDynmap.get(),
|
||||
IntegrationDynmapFactions.get()
|
||||
);
|
||||
|
||||
// Schedule recurring non-tps-dependent tasks
|
||||
TaskPlayerPowerUpdate.get().activate(this);
|
||||
TaskPlayerDataRemove.get().activate(this);
|
||||
TaskEconLandReward.get().activate(this);
|
||||
|
||||
// Register built in chat modifiers
|
||||
ChatModifierLc.get().register();
|
||||
ChatModifierLp.get().register();
|
||||
ChatModifierParse.get().register();
|
||||
ChatModifierRp.get().register();
|
||||
ChatModifierUc.get().register();
|
||||
ChatModifierUcf.get().register();
|
||||
|
||||
// Register built in chat tags
|
||||
ChatTagRelcolor.get().register();
|
||||
ChatTagRole.get().register();
|
||||
ChatTagRoleprefix.get().register();
|
||||
ChatTagRoleprefixforce.get().register();
|
||||
ChatTagName.get().register();
|
||||
ChatTagNameforce.get().register();
|
||||
ChatTagTitle.get().register();
|
||||
|
||||
postEnable();
|
||||
}
|
||||
|
||||
public GsonBuilder getGsonBuilderWithoutPreprocessors()
|
||||
{
|
||||
return super.getGsonBuilder()
|
||||
.registerTypeAdapter(TerritoryAccess.class, TerritoryAccessAdapter.get())
|
||||
.registerTypeAdapter(Board.class, BoardAdapter.get())
|
||||
.registerTypeAdapter(Board.MAP_TYPE, BoardMapAdapter.get())
|
||||
.registerTypeAdapter(Rel.class, RelAdapter.get())
|
||||
.registerTypeAdapter(FPerm.class, FPermAdapter.get())
|
||||
.registerTypeAdapter(FFlag.class, FFlagAdapter.get())
|
||||
;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GsonBuilder getGsonBuilder()
|
||||
{
|
||||
return this.getGsonBuilderWithoutPreprocessors()
|
||||
.registerTypeAdapter(Faction.class, FactionPreprocessAdapter.get())
|
||||
;
|
||||
}
|
||||
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
package com.massivecraft.factions;
|
||||
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
public class Lang
|
||||
{
|
||||
public static final String FACTION_NODESCRIPTION = Txt.parse("<em><silver>no description set");
|
||||
public static final String PLAYER_NOTITLE = Txt.parse("<em><silver>no title set");
|
||||
}
|
@ -1,96 +0,0 @@
|
||||
package com.massivecraft.factions;
|
||||
|
||||
import org.bukkit.permissions.Permissible;
|
||||
|
||||
import com.massivecraft.massivecore.util.PermUtil;
|
||||
|
||||
public enum Perm
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// ENUM
|
||||
// -------------------------------------------- //
|
||||
|
||||
ACCESS("access"),
|
||||
ACCESS_VIEW("access.view"),
|
||||
ACCESS_PLAYER("access.player"),
|
||||
ACCESS_FACTION("access.faction"),
|
||||
ADMIN("admin"),
|
||||
AUTOCLAIM("autoclaim"),
|
||||
CLAIM("claim"),
|
||||
CLAIM_RADIUS("claim.radius"),
|
||||
CREATE("create"),
|
||||
DEMOTE("demote"),
|
||||
DESCRIPTION("description"),
|
||||
DISBAND("disband"),
|
||||
FACTION("faction"),
|
||||
FLAG("flag"),
|
||||
FLAG_SET("flag.set"),
|
||||
HOME("home"),
|
||||
INVITE("invite"),
|
||||
JOIN("join"),
|
||||
JOIN_ANY("join.any"),
|
||||
JOIN_OTHERS("join.others"),
|
||||
KICK("kick"),
|
||||
LEADER("leader"),
|
||||
LEADER_ANY("leader.any"),
|
||||
LEAVE("leave"),
|
||||
LIST("list"),
|
||||
MAP("map"),
|
||||
MONEY("money"),
|
||||
MONEY_BALANCE("money.balance"),
|
||||
MONEY_BALANCE_ANY("money.balance.any"),
|
||||
MONEY_DEPOSIT("money.deposit"),
|
||||
MONEY_F2F("money.f2f"),
|
||||
MONEY_F2P("money.f2p"),
|
||||
MONEY_P2F("money.p2f"),
|
||||
MONEY_WITHDRAW("money.withdraw"),
|
||||
OFFICER("officer"),
|
||||
OFFICER_ANY("officer.any"),
|
||||
OPEN("open"),
|
||||
PERM("perm"),
|
||||
PLAYER("player"),
|
||||
POWERBOOST("powerboost"),
|
||||
PROMOTE("promote"),
|
||||
RELATION("relation"),
|
||||
SEE_CHUNK("seechunk"),
|
||||
SETHOME("sethome"),
|
||||
NAME("name"),
|
||||
TITLE("title"),
|
||||
TITLE_COLOR("title.color"),
|
||||
UNCLAIM("unclaim"),
|
||||
UNCLAIM_ALL("unclaimall"),
|
||||
VERSION("version"),
|
||||
|
||||
// END OF LIST
|
||||
;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public final String node;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
Perm(final String node)
|
||||
{
|
||||
this.node = "factions."+node;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// HAS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public boolean has(Permissible permissible, boolean informSenderIfNot)
|
||||
{
|
||||
return PermUtil.has(permissible, this.node, informSenderIfNot);
|
||||
}
|
||||
|
||||
public boolean has(Permissible permissible)
|
||||
{
|
||||
return has(permissible, false);
|
||||
}
|
||||
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
package com.massivecraft.factions;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
import com.massivecraft.factions.entity.UPlayer;
|
||||
|
||||
public class PlayerRoleComparator implements Comparator<UPlayer>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static PlayerRoleComparator i = new PlayerRoleComparator();
|
||||
public static PlayerRoleComparator get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE: COMPARATOR
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public int compare(UPlayer o1, UPlayer o2)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
// Null
|
||||
if (o1 == null && o2 == null) ret = 0;
|
||||
if (o1 == null) ret = -1;
|
||||
if (o2 == null) ret = +1;
|
||||
if (ret != 0) return ret;
|
||||
|
||||
// Rank
|
||||
Rel r1 = o1.getRole();
|
||||
Rel r2 = o2.getRole();
|
||||
return r2.getValue() - r1.getValue();
|
||||
}
|
||||
|
||||
}
|
@ -1,162 +0,0 @@
|
||||
package com.massivecraft.factions;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import com.massivecraft.factions.entity.MConf;
|
||||
|
||||
|
||||
public enum Rel
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// ENUM
|
||||
// -------------------------------------------- //
|
||||
|
||||
LEADER (70, true, "your faction leader", "your faction leader", "", ""),
|
||||
OFFICER (60, true, "an officer in your faction", "officers in your faction", "", ""),
|
||||
MEMBER (50, true, "a member in your faction", "members in your faction", "your faction", "your factions"),
|
||||
RECRUIT (45, true, "a recruit in your faction", "recruits in your faction", "", ""),
|
||||
ALLY (40, true, "an ally", "allies", "an allied faction", "allied factions"),
|
||||
TRUCE (30, true, "someone in truce with you", "those in truce with you", "a faction in truce", "factions in truce"),
|
||||
NEUTRAL (20, false, "someone neutral to you", "those neutral to you", "a neutral faction", "neutral factions"),
|
||||
ENEMY (10, false, "an enemy", "enemies", "an enemy faction", "enemy factions"),
|
||||
|
||||
// END OF LIST
|
||||
;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
// TODO: Are not enums sorted without this?
|
||||
private final int value;
|
||||
public int getValue() { return this.value; }
|
||||
|
||||
// Used for friendly fire.
|
||||
private final boolean friend;
|
||||
public boolean isFriend() { return this.friend; }
|
||||
|
||||
private final String descPlayerOne;
|
||||
public String getDescPlayerOne() { return this.descPlayerOne; }
|
||||
|
||||
private final String descPlayerMany;
|
||||
public String getDescPlayerMany() { return this.descPlayerMany; }
|
||||
|
||||
private final String descFactionOne;
|
||||
public String getDescFactionOne() { return this.descFactionOne; }
|
||||
|
||||
private final String descFactionMany;
|
||||
public String getDescFactionMany() { return this.descFactionMany; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private Rel(final int value, final boolean friend, final String descPlayerOne, final String descPlayerMany, final String descFactionOne, final String descFactionMany)
|
||||
{
|
||||
this.value = value;
|
||||
this.friend = friend;
|
||||
this.descPlayerOne = descPlayerOne;
|
||||
this.descPlayerMany = descPlayerMany;
|
||||
this.descFactionOne = descFactionOne;
|
||||
this.descFactionMany = descFactionMany;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// UTIL
|
||||
// -------------------------------------------- //
|
||||
|
||||
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 == 'r') return RECRUIT;
|
||||
if (c == 'a') return ALLY;
|
||||
if (c == 't') return TRUCE;
|
||||
if (c == 'n') return NEUTRAL;
|
||||
if (c == 'e') return ENEMY;
|
||||
return null;
|
||||
}
|
||||
|
||||
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 boolean isMoreThan(Rel rel)
|
||||
{
|
||||
return this.value > rel.value;
|
||||
}
|
||||
|
||||
public ChatColor getColor()
|
||||
{
|
||||
if (this.isAtLeast(RECRUIT))
|
||||
return MConf.get().colorMember;
|
||||
else if (this == ALLY)
|
||||
return MConf.get().colorAlly;
|
||||
else if (this == NEUTRAL)
|
||||
return MConf.get().colorNeutral;
|
||||
else if (this == TRUCE)
|
||||
return MConf.get().colorTruce;
|
||||
else
|
||||
return MConf.get().colorEnemy;
|
||||
}
|
||||
|
||||
public String getPrefix()
|
||||
{
|
||||
if (this == LEADER)
|
||||
{
|
||||
return MConf.get().prefixLeader;
|
||||
}
|
||||
|
||||
if (this == OFFICER)
|
||||
{
|
||||
return MConf.get().prefixOfficer;
|
||||
}
|
||||
|
||||
if (this == MEMBER)
|
||||
{
|
||||
return MConf.get().prefixMember;
|
||||
}
|
||||
|
||||
if (this == RECRUIT)
|
||||
{
|
||||
return MConf.get().prefixRecruit;
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
package com.massivecraft.factions;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
|
||||
public interface RelationParticipator
|
||||
{
|
||||
public String describeTo(RelationParticipator observer);
|
||||
public String describeTo(RelationParticipator observer, boolean ucfirst);
|
||||
|
||||
public Rel getRelationTo(RelationParticipator observer);
|
||||
public Rel getRelationTo(RelationParticipator observer, boolean ignorePeaceful);
|
||||
|
||||
public ChatColor getColorTo(RelationParticipator observer);
|
||||
}
|
@ -1,220 +0,0 @@
|
||||
package com.massivecraft.factions;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import com.massivecraft.factions.entity.FactionColl;
|
||||
import com.massivecraft.factions.entity.UPlayer;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.FactionColls;
|
||||
import com.massivecraft.factions.entity.UPlayerColl;
|
||||
import com.massivecraft.factions.entity.UPlayerColls;
|
||||
|
||||
public class TerritoryAccess
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// FIELDS: RAW
|
||||
// -------------------------------------------- //
|
||||
|
||||
// no default value, can't be null
|
||||
private final String hostFactionId;
|
||||
public String getHostFactionId() { return this.hostFactionId; }
|
||||
|
||||
// default is true
|
||||
private final boolean hostFactionAllowed;
|
||||
public boolean isHostFactionAllowed() { return this.hostFactionAllowed; }
|
||||
|
||||
// default is empty
|
||||
private final Set<String> factionIds;
|
||||
public Set<String> getFactionIds() { return this.factionIds; }
|
||||
|
||||
// TODO: remate private final
|
||||
// default is empty
|
||||
public Set<String> playerIds;
|
||||
public Set<String> getPlayerIds() { return this.playerIds; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS: DELTA
|
||||
// -------------------------------------------- //
|
||||
|
||||
// The simple ones
|
||||
public TerritoryAccess withHostFactionId(String hostFactionId) { return valueOf(hostFactionId, hostFactionAllowed, factionIds, playerIds); }
|
||||
public TerritoryAccess withHostFactionAllowed(Boolean hostFactionAllowed) { return valueOf(hostFactionId, hostFactionAllowed, factionIds, playerIds); }
|
||||
public TerritoryAccess withFactionIds(Collection<String> factionIds) { return valueOf(hostFactionId, hostFactionAllowed, factionIds, playerIds); }
|
||||
public TerritoryAccess withPlayerIds(Collection<String> playerIds) { return valueOf(hostFactionId, hostFactionAllowed, factionIds, playerIds); }
|
||||
|
||||
// The intermediate ones
|
||||
public TerritoryAccess withFactionId(String factionId, boolean with)
|
||||
{
|
||||
if (this.getHostFactionId().equals(factionId))
|
||||
{
|
||||
return valueOf(hostFactionId, with, factionIds, playerIds);
|
||||
}
|
||||
|
||||
Set<String> factionIds = new HashSet<String>(this.getFactionIds());
|
||||
if (with)
|
||||
{
|
||||
factionIds.add(factionId);
|
||||
}
|
||||
else
|
||||
{
|
||||
factionIds.remove(factionId);
|
||||
}
|
||||
return valueOf(hostFactionId, hostFactionAllowed, factionIds, playerIds);
|
||||
}
|
||||
|
||||
public TerritoryAccess withPlayerId(String playerId, boolean with)
|
||||
{
|
||||
playerId = playerId.toLowerCase();
|
||||
Set<String> playerIds = new HashSet<String>(this.getPlayerIds());
|
||||
if (with)
|
||||
{
|
||||
playerIds.add(playerId);
|
||||
}
|
||||
else
|
||||
{
|
||||
playerIds.remove(playerId);
|
||||
}
|
||||
return valueOf(hostFactionId, hostFactionAllowed, factionIds, playerIds);
|
||||
}
|
||||
|
||||
// The complex ones
|
||||
public TerritoryAccess toggleFactionId(String factionId)
|
||||
{
|
||||
return this.withFactionId(factionId, !this.isFactionIdGranted(factionId));
|
||||
}
|
||||
|
||||
public TerritoryAccess togglePlayerId(String playerId)
|
||||
{
|
||||
return this.withPlayerId(playerId, !this.isPlayerIdGranted(playerId));
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS: UNIVERSED
|
||||
// -------------------------------------------- //
|
||||
|
||||
public Faction getHostFaction(Object universe)
|
||||
{
|
||||
return FactionColls.get().get(universe).get(this.getHostFactionId());
|
||||
}
|
||||
|
||||
public LinkedHashSet<UPlayer> getGrantedUPlayers(Object universe)
|
||||
{
|
||||
LinkedHashSet<UPlayer> ret = new LinkedHashSet<UPlayer>();
|
||||
UPlayerColl coll = UPlayerColls.get().get(universe);
|
||||
for (String playerId : this.getPlayerIds())
|
||||
{
|
||||
ret.add(coll.get(playerId));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public LinkedHashSet<Faction> getGrantedFactions(Object universe)
|
||||
{
|
||||
LinkedHashSet<Faction> ret = new LinkedHashSet<Faction>();
|
||||
FactionColl coll = FactionColls.get().get(universe);
|
||||
for (String factionId : this.getFactionIds())
|
||||
{
|
||||
ret.add(coll.get(factionId));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// PRIVATE CONSTRUCTOR
|
||||
// -------------------------------------------- //
|
||||
|
||||
private TerritoryAccess(String hostFactionId, Boolean hostFactionAllowed, Collection<String> factionIds, Collection<String> playerIds)
|
||||
{
|
||||
if (hostFactionId == null) throw new IllegalArgumentException("hostFactionId was null");
|
||||
this.hostFactionId = hostFactionId;
|
||||
|
||||
Set<String> factionIdsInner = new TreeSet<String>();
|
||||
if (factionIds != null)
|
||||
{
|
||||
factionIdsInner.addAll(factionIds);
|
||||
if (factionIdsInner.remove(hostFactionId))
|
||||
{
|
||||
hostFactionAllowed = true;
|
||||
}
|
||||
}
|
||||
this.factionIds = Collections.unmodifiableSet(factionIdsInner);
|
||||
|
||||
Set<String> playerIdsInner = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
|
||||
if (playerIds != null)
|
||||
{
|
||||
for (String playerId : playerIds)
|
||||
{
|
||||
playerIdsInner.add(playerId.toLowerCase());
|
||||
}
|
||||
}
|
||||
this.playerIds = Collections.unmodifiableSet(playerIdsInner);
|
||||
|
||||
this.hostFactionAllowed = (hostFactionAllowed == null || hostFactionAllowed);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FACTORY: VALUE OF
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static TerritoryAccess valueOf(String hostFactionId, Boolean hostFactionAllowed, Collection<String> factionIds, Collection<String> playerIds)
|
||||
{
|
||||
return new TerritoryAccess(hostFactionId, hostFactionAllowed, factionIds, playerIds);
|
||||
}
|
||||
|
||||
public static TerritoryAccess valueOf(String hostFactionId)
|
||||
{
|
||||
return valueOf(hostFactionId, null, null, null);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE METHODS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public boolean isFactionIdGranted(String factionId)
|
||||
{
|
||||
if (this.getHostFactionId().equals(factionId))
|
||||
{
|
||||
return this.isHostFactionAllowed();
|
||||
}
|
||||
return this.getFactionIds().contains(factionId);
|
||||
}
|
||||
|
||||
// Note that the player can have access without being specifically granted.
|
||||
// The player could for example be a member of a granted faction.
|
||||
public boolean isPlayerIdGranted(String playerId)
|
||||
{
|
||||
return this.getPlayerIds().contains(playerId);
|
||||
}
|
||||
|
||||
// A "default" TerritoryAccess could be serialized as a simple string only.
|
||||
// The host faction is still allowed (default) and no faction or player has been granted explicit access (default).
|
||||
public boolean isDefault()
|
||||
{
|
||||
return this.isHostFactionAllowed() && this.getFactionIds().isEmpty() && this.getPlayerIds().isEmpty();
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// HAS CHECK
|
||||
// -------------------------------------------- //
|
||||
|
||||
// true means elevated access
|
||||
// false means decreased access
|
||||
// null means standard access
|
||||
public Boolean hasTerritoryAccess(UPlayer uplayer)
|
||||
{
|
||||
if (this.getPlayerIds().contains(uplayer.getId())) return true;
|
||||
|
||||
String factionId = uplayer.getFactionId();
|
||||
if (this.getFactionIds().contains(factionId)) return true;
|
||||
|
||||
if (this.getHostFactionId().equals(factionId) && !this.isHostFactionAllowed()) return false;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
package com.massivecraft.factions.adapter;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
|
||||
import com.massivecraft.massivecore.ps.PS;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonDeserializationContext;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonDeserializer;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonElement;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonParseException;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonSerializationContext;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonSerializer;
|
||||
import com.massivecraft.factions.TerritoryAccess;
|
||||
import com.massivecraft.factions.entity.Board;
|
||||
|
||||
public class BoardAdapter implements JsonDeserializer<Board>, JsonSerializer<Board>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static BoardAdapter i = new BoardAdapter();
|
||||
public static BoardAdapter get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Board deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
|
||||
{
|
||||
return new Board((Map<PS, TerritoryAccess>) context.deserialize(json, Board.MAP_TYPE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(Board src, Type typeOfSrc, JsonSerializationContext context)
|
||||
{
|
||||
return context.serialize(src.getMap(), Board.MAP_TYPE);
|
||||
}
|
||||
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
package com.massivecraft.factions.adapter;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentSkipListMap;
|
||||
|
||||
import com.massivecraft.massivecore.ps.PS;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonDeserializationContext;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonDeserializer;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonElement;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonObject;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonParseException;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonSerializationContext;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonSerializer;
|
||||
import com.massivecraft.factions.TerritoryAccess;
|
||||
|
||||
public class BoardMapAdapter implements JsonDeserializer<Map<PS, TerritoryAccess>>, JsonSerializer<Map<PS, TerritoryAccess>>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static BoardMapAdapter i = new BoardMapAdapter();
|
||||
public static BoardMapAdapter get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Map<PS, TerritoryAccess> deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
|
||||
{
|
||||
Map<PS, TerritoryAccess> ret = new ConcurrentSkipListMap<PS, TerritoryAccess>();
|
||||
|
||||
JsonObject jsonObject = json.getAsJsonObject();
|
||||
|
||||
for (Entry<String, JsonElement> entry : jsonObject.entrySet())
|
||||
{
|
||||
String[] ChunkCoordParts = entry.getKey().split("[,\\s]+");
|
||||
int chunkX = Integer.parseInt(ChunkCoordParts[0]);
|
||||
int chunkZ = Integer.parseInt(ChunkCoordParts[1]);
|
||||
PS chunk = PS.valueOf(chunkX, chunkZ);
|
||||
|
||||
TerritoryAccess territoryAccess = context.deserialize(entry.getValue(), TerritoryAccess.class);
|
||||
|
||||
ret.put(chunk, territoryAccess);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(Map<PS, TerritoryAccess> src, Type typeOfSrc, JsonSerializationContext context)
|
||||
{
|
||||
JsonObject ret = new JsonObject();
|
||||
|
||||
for (Entry<PS, TerritoryAccess> entry : src.entrySet())
|
||||
{
|
||||
PS ps = entry.getKey();
|
||||
TerritoryAccess territoryAccess = entry.getValue();
|
||||
|
||||
ret.add(ps.getChunkX().toString() + "," + ps.getChunkZ().toString(), context.serialize(territoryAccess, TerritoryAccess.class));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
package com.massivecraft.factions.adapter;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import com.massivecraft.factions.FFlag;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonDeserializationContext;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonDeserializer;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonElement;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonParseException;
|
||||
|
||||
public class FFlagAdapter implements JsonDeserializer<FFlag>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static FFlagAdapter i = new FFlagAdapter();
|
||||
public static FFlagAdapter get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public FFlag deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
|
||||
{
|
||||
return FFlag.parse(json.getAsString());
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
package com.massivecraft.factions.adapter;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonDeserializationContext;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonDeserializer;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonElement;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonParseException;
|
||||
import com.massivecraft.factions.FPerm;
|
||||
|
||||
public class FPermAdapter implements JsonDeserializer<FPerm>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static FPermAdapter i = new FPermAdapter();
|
||||
public static FPermAdapter get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public FPerm deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
|
||||
{
|
||||
return FPerm.parse(json.getAsString());
|
||||
}
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
package com.massivecraft.factions.adapter;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonDeserializationContext;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonDeserializer;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonElement;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonObject;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonParseException;
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
|
||||
public class FactionPreprocessAdapter implements JsonDeserializer<Faction>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static FactionPreprocessAdapter i = new FactionPreprocessAdapter();
|
||||
public static FactionPreprocessAdapter get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Faction deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
|
||||
{
|
||||
preprocess(json);
|
||||
return Factions.get().gsonWithoutPreprocessors.fromJson(json, typeOfT);
|
||||
}
|
||||
|
||||
public void preprocess(JsonElement json)
|
||||
{
|
||||
JsonObject jsonObject = json.getAsJsonObject();
|
||||
|
||||
// Renamed fields
|
||||
// 1.8.X --> 2.0.0
|
||||
rename(jsonObject, "tag", "name");
|
||||
rename(jsonObject, "invites", "invitedPlayerIds");
|
||||
rename(jsonObject, "relationWish", "relationWishes");
|
||||
rename(jsonObject, "flagOverrides", "flags");
|
||||
rename(jsonObject, "permOverrides", "perms");
|
||||
}
|
||||
|
||||
public void rename(final JsonObject jsonObject, final String from, final String to)
|
||||
{
|
||||
JsonElement element = jsonObject.remove(from);
|
||||
if (element != null) jsonObject.add(to, element);
|
||||
}
|
||||
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
package com.massivecraft.factions.adapter;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonDeserializationContext;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonDeserializer;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonElement;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonParseException;
|
||||
import com.massivecraft.factions.Rel;
|
||||
|
||||
public class RelAdapter implements JsonDeserializer<Rel>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static RelAdapter i = new RelAdapter();
|
||||
public static RelAdapter get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Rel deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
|
||||
{
|
||||
return Rel.parse(json.getAsString());
|
||||
}
|
||||
}
|
@ -1,116 +0,0 @@
|
||||
package com.massivecraft.factions.adapter;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Set;
|
||||
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonDeserializationContext;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonDeserializer;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonElement;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonObject;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonParseException;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonPrimitive;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonSerializationContext;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonSerializer;
|
||||
import com.massivecraft.massivecore.xlib.gson.reflect.TypeToken;
|
||||
import com.massivecraft.factions.TerritoryAccess;
|
||||
|
||||
public class TerritoryAccessAdapter implements JsonDeserializer<TerritoryAccess>, JsonSerializer<TerritoryAccess>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTANTS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static final String HOST_FACTION_ID = "hostFactionId";
|
||||
public static final String HOST_FACTION_ALLOWED = "hostFactionAllowed";
|
||||
public static final String FACTION_IDS = "factionIds";
|
||||
public static final String PLAYER_IDS = "playerIds";
|
||||
|
||||
public static final Type SET_OF_STRING_TYPE = new TypeToken<Set<String>>(){}.getType();
|
||||
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static TerritoryAccessAdapter i = new TerritoryAccessAdapter();
|
||||
public static TerritoryAccessAdapter get() { return i; }
|
||||
|
||||
//----------------------------------------------//
|
||||
// OVERRIDE
|
||||
//----------------------------------------------//
|
||||
|
||||
@Override
|
||||
public TerritoryAccess deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
|
||||
{
|
||||
// isDefault <=> simple hostFactionId string
|
||||
if (json.isJsonPrimitive())
|
||||
{
|
||||
String hostFactionId = json.getAsString();
|
||||
return TerritoryAccess.valueOf(hostFactionId);
|
||||
}
|
||||
|
||||
// Otherwise object
|
||||
JsonObject obj = json.getAsJsonObject();
|
||||
|
||||
// Prepare variables
|
||||
String hostFactionId = null;
|
||||
Boolean hostFactionAllowed = null;
|
||||
Set<String> factionIds = null;
|
||||
Set<String> playerIds = null;
|
||||
|
||||
// Read variables (test old values first)
|
||||
JsonElement element = null;
|
||||
|
||||
element = obj.get("ID");
|
||||
if (element == null) element = obj.get(HOST_FACTION_ID);
|
||||
hostFactionId = element.getAsString();
|
||||
|
||||
element = obj.get("open");
|
||||
if (element == null) element = obj.get(HOST_FACTION_ALLOWED);
|
||||
if (element != null) hostFactionAllowed = element.getAsBoolean();
|
||||
|
||||
element = obj.get("factions");
|
||||
if (element == null) element = obj.get(FACTION_IDS);
|
||||
if (element != null) factionIds = context.deserialize(element, SET_OF_STRING_TYPE);
|
||||
|
||||
element = obj.get("fplayers");
|
||||
if (element == null) element = obj.get(PLAYER_IDS);
|
||||
if (element != null) playerIds = context.deserialize(element, SET_OF_STRING_TYPE);
|
||||
|
||||
return TerritoryAccess.valueOf(hostFactionId, hostFactionAllowed, factionIds, playerIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(TerritoryAccess src, Type typeOfSrc, JsonSerializationContext context)
|
||||
{
|
||||
if (src == null) return null;
|
||||
|
||||
// isDefault <=> simple hostFactionId string
|
||||
if (src.isDefault())
|
||||
{
|
||||
return new JsonPrimitive(src.getHostFactionId());
|
||||
}
|
||||
|
||||
// Otherwise object
|
||||
JsonObject obj = new JsonObject();
|
||||
|
||||
obj.addProperty(HOST_FACTION_ID, src.getHostFactionId());
|
||||
|
||||
if (!src.isHostFactionAllowed())
|
||||
{
|
||||
obj.addProperty(HOST_FACTION_ALLOWED, src.isHostFactionAllowed());
|
||||
}
|
||||
|
||||
if (!src.getFactionIds().isEmpty())
|
||||
{
|
||||
obj.add(FACTION_IDS, context.serialize(src.getFactionIds(), SET_OF_STRING_TYPE));
|
||||
}
|
||||
|
||||
if (!src.getPlayerIds().isEmpty())
|
||||
{
|
||||
obj.add(PLAYER_IDS, context.serialize(src.getPlayerIds(), SET_OF_STRING_TYPE));
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
}
|
@ -1,184 +0,0 @@
|
||||
package com.massivecraft.factions.chat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
* The ChatFormater is a system offered by factions for tag parsing.
|
||||
*
|
||||
* Note that every tag and modifier id must be lowercase.
|
||||
* A tag with id "derp" is allowed but not with id "Derp". For that reason the tag {sender} will work but {Sender} wont.
|
||||
*/
|
||||
public class ChatFormatter
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTANTS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public final static String START = "{";
|
||||
public final static String END = "}";
|
||||
public final static String SEPARATOR = "|";
|
||||
|
||||
public final static String ESC_START = "\\"+START;
|
||||
public final static String ESC_END = "\\"+END;
|
||||
public final static String ESC_SEPARATOR = "\\"+SEPARATOR;
|
||||
|
||||
public final static Pattern pattern = Pattern.compile(ESC_START+"([^"+ESC_START+ESC_END+"]+)"+ESC_END);
|
||||
|
||||
// -------------------------------------------- //
|
||||
// TAG REGISTER
|
||||
// -------------------------------------------- //
|
||||
|
||||
private final static Map<String, ChatTag> idToTag = new HashMap<String, ChatTag>();
|
||||
public static ChatTag getTag(String tagId) { return idToTag.get(tagId); }
|
||||
public static boolean registerTag(ChatTag tag)
|
||||
{
|
||||
if (tag == null) throw new NullPointerException("tag");
|
||||
|
||||
String id = tag.getId();
|
||||
if (id == null) throw new NullPointerException("tag id");
|
||||
if (!id.equals(id.toLowerCase()))
|
||||
{
|
||||
throw new IllegalArgumentException("tag id must be lowercase");
|
||||
}
|
||||
|
||||
ChatTag current = idToTag.get(id);
|
||||
if (current != null)
|
||||
{
|
||||
return current.equals(tag);
|
||||
}
|
||||
|
||||
idToTag.put(id, tag);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean unregisterTag(ChatTag tag)
|
||||
{
|
||||
if (tag == null) return false;
|
||||
return idToTag.remove(tag.getId()) != null;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// MODIFIER REGISTER
|
||||
// -------------------------------------------- //
|
||||
|
||||
private final static Map<String, ChatModifier> idToModifier = new HashMap<String, ChatModifier>();
|
||||
public static ChatModifier getModifier(String modifierId) { return idToModifier.get(modifierId); }
|
||||
public static boolean registerModifier(ChatModifier modifier)
|
||||
{
|
||||
if (modifier == null) throw new NullPointerException("modifier");
|
||||
|
||||
String id = modifier.getId();
|
||||
if (id == null) throw new NullPointerException("modifier id");
|
||||
if (!id.equals(id.toLowerCase()))
|
||||
{
|
||||
throw new IllegalArgumentException("modifier id must be lowercase");
|
||||
}
|
||||
|
||||
ChatModifier current = idToModifier.get(id);
|
||||
if (current != null)
|
||||
{
|
||||
return current.equals(modifier);
|
||||
}
|
||||
|
||||
idToModifier.put(id, modifier);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean unregisterModifier(ChatModifier modifier)
|
||||
{
|
||||
if (modifier == null) return false;
|
||||
return idToModifier.remove(modifier.getId()) != null;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FORMAT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static String format(String msg, CommandSender sender, CommandSender recipient)
|
||||
{
|
||||
// We build the return value in this string buffer
|
||||
StringBuffer ret = new StringBuffer();
|
||||
|
||||
// A matcher to match all the tags in the msg
|
||||
Matcher matcher = pattern.matcher(msg);
|
||||
|
||||
// For each tag we find
|
||||
while (matcher.find())
|
||||
{
|
||||
// The fullmatch is something like "{sender|lp|rp}"
|
||||
String fullmatch = matcher.group(0);
|
||||
|
||||
// The submatch is something like "sender|lp|rp"
|
||||
String submatch = matcher.group(1);
|
||||
|
||||
// The parts are something like ["sender", "lp", "rp"]
|
||||
String[] parts = submatch.split(ESC_SEPARATOR);
|
||||
|
||||
// The modifier ids are something like ["lp", "rp"] and tagId something like "sender"
|
||||
List<String> modifierIds = new ArrayList<String>(Arrays.asList(parts));
|
||||
String tagId = modifierIds.remove(0);
|
||||
|
||||
// Fetch tag for the id
|
||||
ChatTag tag = getTag(tagId);
|
||||
|
||||
String replacement;
|
||||
if (tag == null)
|
||||
{
|
||||
// No change if tag wasn't found
|
||||
replacement = fullmatch;
|
||||
}
|
||||
else
|
||||
{
|
||||
replacement = compute(tag, modifierIds, sender, recipient);
|
||||
if (replacement == null)
|
||||
{
|
||||
// If a tag or modifier returns null it's the same as opting out.
|
||||
replacement = fullmatch;
|
||||
}
|
||||
}
|
||||
|
||||
matcher.appendReplacement(ret, replacement);
|
||||
}
|
||||
|
||||
// Append the rest
|
||||
matcher.appendTail(ret);
|
||||
|
||||
// And finally we return the string value of the buffer we built
|
||||
return ret.toString();
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// TAG COMPUTE
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static String compute(ChatTag tag, List<String> modifierIds, CommandSender sender, CommandSender recipient)
|
||||
{
|
||||
String ret = tag.getReplacement(sender, recipient);
|
||||
if (ret == null) return null;
|
||||
|
||||
for (String modifierId : modifierIds)
|
||||
{
|
||||
// Find the modifier or skip
|
||||
ChatModifier modifier = getModifier(modifierId);
|
||||
if (modifier == null) continue;
|
||||
|
||||
// Modify and ignore change if null.
|
||||
// Modifier can't get or return null.
|
||||
String modified = modifier.getModified(ret, sender, recipient);
|
||||
if (modified == null) continue;
|
||||
|
||||
ret = modified;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
package com.massivecraft.factions.chat;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public interface ChatModifier
|
||||
{
|
||||
public String getId();
|
||||
public String getModified(String subject, CommandSender sender, CommandSender recipient);
|
||||
public boolean register();
|
||||
public boolean unregister();
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
package com.massivecraft.factions.chat;
|
||||
|
||||
public abstract class ChatModifierAbstract implements ChatModifier
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// FIELDS & RAWDATA GET/SET
|
||||
// -------------------------------------------- //
|
||||
|
||||
private final String id;
|
||||
@Override public String getId() { return this.id; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDES
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public boolean register()
|
||||
{
|
||||
return ChatFormatter.registerModifier(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean unregister()
|
||||
{
|
||||
return ChatFormatter.unregisterModifier(this);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public ChatModifierAbstract(final String id)
|
||||
{
|
||||
this.id = id.toLowerCase();
|
||||
}
|
||||
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
package com.massivecraft.factions.chat;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public interface ChatTag
|
||||
{
|
||||
public String getId();
|
||||
public String getReplacement(CommandSender sender, CommandSender recipient);
|
||||
public boolean register();
|
||||
public boolean unregister();
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
package com.massivecraft.factions.chat;
|
||||
|
||||
public abstract class ChatTagAbstract implements ChatTag
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// FIELDS & RAWDATA GET/SET
|
||||
// -------------------------------------------- //
|
||||
|
||||
private final String id;
|
||||
@Override public String getId() { return this.id; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDES
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public boolean register()
|
||||
{
|
||||
return ChatFormatter.registerTag(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean unregister()
|
||||
{
|
||||
return ChatFormatter.unregisterTag(this);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public ChatTagAbstract(final String id)
|
||||
{
|
||||
this.id = id.toLowerCase();
|
||||
}
|
||||
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
package com.massivecraft.factions.chat.modifier;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.massivecraft.factions.chat.ChatModifierAbstract;
|
||||
|
||||
public class ChatModifierLc extends ChatModifierAbstract
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private ChatModifierLc() { super("lc"); }
|
||||
private static ChatModifierLc i = new ChatModifierLc();
|
||||
public static ChatModifierLc get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public String getModified(String subject, CommandSender sender, CommandSender recipient)
|
||||
{
|
||||
return subject.toLowerCase();
|
||||
}
|
||||
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
package com.massivecraft.factions.chat.modifier;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.massivecraft.factions.chat.ChatModifierAbstract;
|
||||
|
||||
|
||||
public class ChatModifierLp extends ChatModifierAbstract
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private ChatModifierLp() { super("lp"); }
|
||||
private static ChatModifierLp i = new ChatModifierLp();
|
||||
public static ChatModifierLp get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public String getModified(String subject, CommandSender sender, CommandSender recipient)
|
||||
{
|
||||
if (subject.equals("")) return subject;
|
||||
return " "+subject;
|
||||
}
|
||||
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
package com.massivecraft.factions.chat.modifier;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.massivecraft.factions.chat.ChatModifierAbstract;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
public class ChatModifierParse extends ChatModifierAbstract
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private ChatModifierParse() { super("parse"); }
|
||||
private static ChatModifierParse i = new ChatModifierParse();
|
||||
public static ChatModifierParse get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public String getModified(String subject, CommandSender sender, CommandSender recipient)
|
||||
{
|
||||
return Txt.parse(subject);
|
||||
}
|
||||
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
package com.massivecraft.factions.chat.modifier;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.massivecraft.factions.chat.ChatModifierAbstract;
|
||||
|
||||
public class ChatModifierRp extends ChatModifierAbstract
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private ChatModifierRp() { super("rp"); }
|
||||
private static ChatModifierRp i = new ChatModifierRp();
|
||||
public static ChatModifierRp get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public String getModified(String subject, CommandSender sender, CommandSender recipient)
|
||||
{
|
||||
if (subject.equals("")) return subject;
|
||||
return subject+" ";
|
||||
}
|
||||
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
package com.massivecraft.factions.chat.modifier;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.massivecraft.factions.chat.ChatModifierAbstract;
|
||||
|
||||
public class ChatModifierUc extends ChatModifierAbstract
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private ChatModifierUc() { super("uc"); }
|
||||
private static ChatModifierUc i = new ChatModifierUc();
|
||||
public static ChatModifierUc get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public String getModified(String subject, CommandSender sender, CommandSender recipient)
|
||||
{
|
||||
return subject.toUpperCase();
|
||||
}
|
||||
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
package com.massivecraft.factions.chat.modifier;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.massivecraft.factions.chat.ChatModifierAbstract;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
public class ChatModifierUcf extends ChatModifierAbstract
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private ChatModifierUcf() { super("ucf"); }
|
||||
private static ChatModifierUcf i = new ChatModifierUcf();
|
||||
public static ChatModifierUcf get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public String getModified(String subject, CommandSender sender, CommandSender recipient)
|
||||
{
|
||||
return Txt.upperCaseFirst(subject);
|
||||
}
|
||||
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
package com.massivecraft.factions.chat.tag;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.massivecraft.factions.chat.ChatTagAbstract;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.UConf;
|
||||
import com.massivecraft.factions.entity.UPlayer;
|
||||
|
||||
public class ChatTagName extends ChatTagAbstract
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private ChatTagName() { super("factions_name"); }
|
||||
private static ChatTagName i = new ChatTagName();
|
||||
public static ChatTagName get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public String getReplacement(CommandSender sender, CommandSender recipient)
|
||||
{
|
||||
// Check disabled
|
||||
if (UConf.isDisabled(sender)) return "";
|
||||
|
||||
// Get entities
|
||||
UPlayer usender = UPlayer.get(sender);
|
||||
|
||||
// No "force"
|
||||
Faction faction = usender.getFaction();
|
||||
if (faction.isNone()) return "";
|
||||
|
||||
return faction.getName();
|
||||
}
|
||||
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
package com.massivecraft.factions.chat.tag;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.massivecraft.factions.chat.ChatTagAbstract;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.UConf;
|
||||
import com.massivecraft.factions.entity.UPlayer;
|
||||
|
||||
public class ChatTagNameforce extends ChatTagAbstract
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private ChatTagNameforce() { super("factions_nameforce"); }
|
||||
private static ChatTagNameforce i = new ChatTagNameforce();
|
||||
public static ChatTagNameforce get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public String getReplacement(CommandSender sender, CommandSender recipient)
|
||||
{
|
||||
// Check disabled
|
||||
if (UConf.isDisabled(sender)) return "";
|
||||
|
||||
// Get entities
|
||||
UPlayer usender = UPlayer.get(sender);
|
||||
|
||||
Faction faction = usender.getFaction();
|
||||
return faction.getName();
|
||||
}
|
||||
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
package com.massivecraft.factions.chat.tag;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.massivecraft.factions.chat.ChatTagAbstract;
|
||||
import com.massivecraft.factions.entity.UConf;
|
||||
import com.massivecraft.factions.entity.UPlayer;
|
||||
|
||||
public class ChatTagRelcolor extends ChatTagAbstract
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private ChatTagRelcolor() { super("factions_relcolor"); }
|
||||
private static ChatTagRelcolor i = new ChatTagRelcolor();
|
||||
public static ChatTagRelcolor get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public String getReplacement(CommandSender sender, CommandSender recipient)
|
||||
{
|
||||
// Check disabled
|
||||
if (UConf.isDisabled(sender)) return "";
|
||||
|
||||
// Opt out if no recipient
|
||||
if (recipient == null) return null;
|
||||
|
||||
// Get entities
|
||||
UPlayer usender = UPlayer.get(sender);
|
||||
UPlayer urecipient = UPlayer.get(recipient);
|
||||
|
||||
return urecipient.getRelationTo(usender).getColor().toString();
|
||||
}
|
||||
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
package com.massivecraft.factions.chat.tag;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.massivecraft.factions.chat.ChatTagAbstract;
|
||||
import com.massivecraft.factions.entity.UConf;
|
||||
import com.massivecraft.factions.entity.UPlayer;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
public class ChatTagRole extends ChatTagAbstract
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private ChatTagRole() { super("factions_role"); }
|
||||
private static ChatTagRole i = new ChatTagRole();
|
||||
public static ChatTagRole get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public String getReplacement(CommandSender sender, CommandSender recipient)
|
||||
{
|
||||
// Check disabled
|
||||
if (UConf.isDisabled(sender)) return "";
|
||||
|
||||
// Get entities
|
||||
UPlayer usender = UPlayer.get(sender);
|
||||
|
||||
return Txt.upperCaseFirst(usender.getRole().toString().toLowerCase());
|
||||
}
|
||||
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
package com.massivecraft.factions.chat.tag;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.massivecraft.factions.chat.ChatTagAbstract;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.UConf;
|
||||
import com.massivecraft.factions.entity.UPlayer;
|
||||
|
||||
public class ChatTagRoleprefix extends ChatTagAbstract
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private ChatTagRoleprefix() { super("factions_roleprefix"); }
|
||||
private static ChatTagRoleprefix i = new ChatTagRoleprefix();
|
||||
public static ChatTagRoleprefix get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public String getReplacement(CommandSender sender, CommandSender recipient)
|
||||
{
|
||||
// Check disabled
|
||||
if (UConf.isDisabled(sender)) return "";
|
||||
|
||||
// Get entities
|
||||
UPlayer usender = UPlayer.get(sender);
|
||||
|
||||
// No "force"
|
||||
Faction faction = usender.getFaction();
|
||||
if (faction.isNone()) return "";
|
||||
|
||||
return usender.getRole().getPrefix();
|
||||
}
|
||||
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
package com.massivecraft.factions.chat.tag;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.massivecraft.factions.chat.ChatTagAbstract;
|
||||
import com.massivecraft.factions.entity.UConf;
|
||||
import com.massivecraft.factions.entity.UPlayer;
|
||||
|
||||
public class ChatTagRoleprefixforce extends ChatTagAbstract
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private ChatTagRoleprefixforce() { super("factions_roleprefix"); }
|
||||
private static ChatTagRoleprefixforce i = new ChatTagRoleprefixforce();
|
||||
public static ChatTagRoleprefixforce get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public String getReplacement(CommandSender sender, CommandSender recipient)
|
||||
{
|
||||
// Check disabled
|
||||
if (UConf.isDisabled(sender)) return "";
|
||||
|
||||
// Get entities
|
||||
UPlayer usender = UPlayer.get(sender);
|
||||
|
||||
return usender.getRole().getPrefix();
|
||||
}
|
||||
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
package com.massivecraft.factions.chat.tag;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.massivecraft.factions.chat.ChatTagAbstract;
|
||||
import com.massivecraft.factions.entity.UConf;
|
||||
import com.massivecraft.factions.entity.UPlayer;
|
||||
|
||||
public class ChatTagTitle extends ChatTagAbstract
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private ChatTagTitle() { super("factions_title"); }
|
||||
private static ChatTagTitle i = new ChatTagTitle();
|
||||
public static ChatTagTitle get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public String getReplacement(CommandSender sender, CommandSender recipient)
|
||||
{
|
||||
// Check disabled
|
||||
if (UConf.isDisabled(sender)) return "";
|
||||
|
||||
// Get entities
|
||||
UPlayer usender = UPlayer.get(sender);
|
||||
|
||||
if (!usender.hasTitle()) return "";
|
||||
return usender.getTitle();
|
||||
}
|
||||
|
||||
}
|
@ -1,114 +0,0 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.entity.MConf;
|
||||
import com.massivecraft.massivecore.cmd.HelpCommand;
|
||||
import com.massivecraft.massivecore.cmd.VersionCommand;
|
||||
|
||||
public class CmdFactions extends FCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsList cmdFactionsList = new CmdFactionsList();
|
||||
public CmdFactionsFaction cmdFactionsFaction = new CmdFactionsFaction();
|
||||
public CmdFactionsPlayer cmdFactionsPlayer = new CmdFactionsPlayer();
|
||||
public CmdFactionsJoin cmdFactionsJoin = new CmdFactionsJoin();
|
||||
public CmdFactionsLeave cmdFactionsLeave = new CmdFactionsLeave();
|
||||
public CmdFactionsHome cmdFactionsHome = new CmdFactionsHome();
|
||||
public CmdFactionsMap cmdFactionsMap = new CmdFactionsMap();
|
||||
public CmdFactionsCreate cmdFactionsCreate = new CmdFactionsCreate();
|
||||
public CmdFactionsName cmdFactionsName = new CmdFactionsName();
|
||||
public CmdFactionsDescription cmdFactionsDescription = new CmdFactionsDescription();
|
||||
public CmdFactionsSethome cmdFactionsSethome = new CmdFactionsSethome();
|
||||
public CmdFactionsOpen cmdFactionsOpen = new CmdFactionsOpen();
|
||||
public CmdFactionsInvite cmdFactionsInvite = new CmdFactionsInvite();
|
||||
public CmdFactionsKick cmdFactionsKick = new CmdFactionsKick();
|
||||
public CmdFactionsTitle cmdFactionsTitle = new CmdFactionsTitle();
|
||||
public CmdFactionsPromote cmdFactionsPromote = new CmdFactionsPromote();
|
||||
public CmdFactionsDemote cmdFactionsDemote = new CmdFactionsDemote();
|
||||
public CmdFactionsOfficer cmdFactionsOfficer = new CmdFactionsOfficer();
|
||||
public CmdFactionsLeader cmdFactionsLeader = new CmdFactionsLeader();
|
||||
public CmdFactionsMoney cmdFactionsMoney = new CmdFactionsMoney();
|
||||
public CmdFactionsSeeChunk cmdFactionsSeeChunk = new CmdFactionsSeeChunk();
|
||||
public CmdFactionsClaim cmdFactionsClaim = new CmdFactionsClaim();
|
||||
public CmdFactionsAutoClaim cmdFactionsAutoClaim = new CmdFactionsAutoClaim();
|
||||
public CmdFactionsUnclaim cmdFactionsUnclaim = new CmdFactionsUnclaim();
|
||||
public CmdFactionsUnclaimall cmdFactionsUnclaimall = new CmdFactionsUnclaimall();
|
||||
public CmdFactionsAccess cmdFactionsAccess = new CmdFactionsAccess();
|
||||
public CmdFactionsRelationAlly cmdFactionsRelationAlly = new CmdFactionsRelationAlly();
|
||||
public CmdFactionsRelationTruce cmdFactionsRelationTruce = new CmdFactionsRelationTruce();
|
||||
public CmdFactionsRelationNeutral cmdFactionsRelationNeutral = new CmdFactionsRelationNeutral();
|
||||
public CmdFactionsRelationEnemy cmdFactionsRelationEnemy = new CmdFactionsRelationEnemy();
|
||||
public CmdFactionsPerm cmdFactionsPerm = new CmdFactionsPerm();
|
||||
public CmdFactionsFlag cmdFactionsFlag = new CmdFactionsFlag();
|
||||
public CmdFactionsDisband cmdFactionsDisband = new CmdFactionsDisband();
|
||||
public CmdFactionsAdmin cmdFactionsAdmin = new CmdFactionsAdmin();
|
||||
public CmdFactionsPowerBoost cmdFactionsPowerBoost = new CmdFactionsPowerBoost();
|
||||
public VersionCommand cmdFactionsVersion = new VersionCommand(Factions.get(), Perm.VERSION.node, "v", "version");
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactions()
|
||||
{
|
||||
// Add SubCommands
|
||||
this.addSubCommand(HelpCommand.get());
|
||||
this.addSubCommand(this.cmdFactionsList);
|
||||
this.addSubCommand(this.cmdFactionsFaction);
|
||||
this.addSubCommand(this.cmdFactionsPlayer);
|
||||
this.addSubCommand(this.cmdFactionsJoin);
|
||||
this.addSubCommand(this.cmdFactionsLeave);
|
||||
this.addSubCommand(this.cmdFactionsHome);
|
||||
this.addSubCommand(this.cmdFactionsMap);
|
||||
this.addSubCommand(this.cmdFactionsCreate);
|
||||
this.addSubCommand(this.cmdFactionsName);
|
||||
this.addSubCommand(this.cmdFactionsDescription);
|
||||
this.addSubCommand(this.cmdFactionsSethome);
|
||||
this.addSubCommand(this.cmdFactionsOpen);
|
||||
this.addSubCommand(this.cmdFactionsInvite);
|
||||
this.addSubCommand(this.cmdFactionsKick);
|
||||
this.addSubCommand(this.cmdFactionsTitle);
|
||||
this.addSubCommand(this.cmdFactionsPromote);
|
||||
this.addSubCommand(this.cmdFactionsDemote);
|
||||
this.addSubCommand(this.cmdFactionsOfficer);
|
||||
this.addSubCommand(this.cmdFactionsLeader);
|
||||
this.addSubCommand(this.cmdFactionsMoney);
|
||||
this.addSubCommand(this.cmdFactionsSeeChunk);
|
||||
this.addSubCommand(this.cmdFactionsClaim);
|
||||
this.addSubCommand(this.cmdFactionsAutoClaim);
|
||||
this.addSubCommand(this.cmdFactionsUnclaim);
|
||||
this.addSubCommand(this.cmdFactionsUnclaimall);
|
||||
this.addSubCommand(this.cmdFactionsAccess);
|
||||
this.addSubCommand(this.cmdFactionsRelationAlly);
|
||||
this.addSubCommand(this.cmdFactionsRelationTruce);
|
||||
this.addSubCommand(this.cmdFactionsRelationNeutral);
|
||||
this.addSubCommand(this.cmdFactionsRelationEnemy);
|
||||
this.addSubCommand(this.cmdFactionsPerm);
|
||||
this.addSubCommand(this.cmdFactionsFlag);
|
||||
this.addSubCommand(this.cmdFactionsDisband);
|
||||
this.addSubCommand(this.cmdFactionsAdmin);
|
||||
this.addSubCommand(this.cmdFactionsPowerBoost);
|
||||
this.addSubCommand(this.cmdFactionsVersion);
|
||||
|
||||
// Misc
|
||||
this.setDesc("The faction base command");
|
||||
this.setHelp("This command contains all faction stuff.");
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public List<String> getAliases()
|
||||
{
|
||||
return MConf.get().aliasesF;
|
||||
}
|
||||
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.cmd.req.ReqFactionsEnabled;
|
||||
import com.massivecraft.massivecore.cmd.HelpCommand;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqIsPlayer;
|
||||
|
||||
|
||||
public class CmdFactionsAccess extends FCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsAccessView cmdFactionsAccessView = new CmdFactionsAccessView();
|
||||
public CmdFactionsAccessPlayer cmdFactionsAccessPlayer = new CmdFactionsAccessPlayer();
|
||||
public CmdFactionsAccessFaction cmdFactionsAccessFaction = new CmdFactionsAccessFaction();
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsAccess()
|
||||
{
|
||||
// Add SubCommands
|
||||
this.addSubCommand(this.cmdFactionsAccessView);
|
||||
this.addSubCommand(this.cmdFactionsAccessPlayer);
|
||||
this.addSubCommand(this.cmdFactionsAccessFaction);
|
||||
|
||||
// Aliases
|
||||
this.addAliases("access");
|
||||
|
||||
// Requirements
|
||||
this.addRequirements(ReqFactionsEnabled.get());
|
||||
this.addRequirements(ReqIsPlayer.get());
|
||||
this.addRequirements(ReqHasPerm.get(Perm.ACCESS.node));
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform()
|
||||
{
|
||||
this.getCommandChain().add(this);
|
||||
HelpCommand.get().execute(this.sender, this.args, this.commandChain);
|
||||
}
|
||||
|
||||
}
|
@ -1,75 +0,0 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import com.massivecraft.factions.RelationParticipator;
|
||||
import com.massivecraft.factions.TerritoryAccess;
|
||||
import com.massivecraft.factions.cmd.req.ReqFactionsEnabled;
|
||||
import com.massivecraft.factions.entity.BoardColls;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqIsPlayer;
|
||||
import com.massivecraft.massivecore.ps.PS;
|
||||
import com.massivecraft.massivecore.ps.PSFormatHumanSpace;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
|
||||
public abstract class CmdFactionsAccessAbstract extends FCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public PS chunk;
|
||||
public TerritoryAccess ta;
|
||||
public Faction hostFaction;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsAccessAbstract()
|
||||
{
|
||||
// Requirements
|
||||
this.addRequirements(ReqFactionsEnabled.get());
|
||||
this.addRequirements(ReqIsPlayer.get());
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform()
|
||||
{
|
||||
chunk = PS.valueOf(me).getChunk(true);
|
||||
ta = BoardColls.get().getTerritoryAccessAt(chunk);
|
||||
hostFaction = ta.getHostFaction(usender);
|
||||
|
||||
this.innerPerform();
|
||||
}
|
||||
|
||||
public abstract void innerPerform();
|
||||
|
||||
public void sendAccessInfo()
|
||||
{
|
||||
sendMessage(Txt.titleize("Access at " + chunk.toString(PSFormatHumanSpace.get())));
|
||||
msg("<k>Host Faction: %s", hostFaction.describeTo(usender, true));
|
||||
msg("<k>Host Faction Allowed: %s", ta.isHostFactionAllowed() ? Txt.parse("<lime>TRUE") : Txt.parse("<rose>FALSE"));
|
||||
msg("<k>Granted Players: %s", describeRelationParticipators(ta.getGrantedUPlayers(usender), usender));
|
||||
msg("<k>Granted Factions: %s", describeRelationParticipators(ta.getGrantedFactions(usender), usender));
|
||||
}
|
||||
|
||||
public static String describeRelationParticipators(Collection<? extends RelationParticipator> relationParticipators, RelationParticipator observer)
|
||||
{
|
||||
if (relationParticipators.size() == 0) return Txt.parse("<silver><em>none");
|
||||
List<String> descriptions = new ArrayList<String>();
|
||||
for (RelationParticipator relationParticipator : relationParticipators)
|
||||
{
|
||||
descriptions.add(relationParticipator.describeTo(observer));
|
||||
}
|
||||
return Txt.implodeCommaAnd(descriptions, Txt.parse("<i>, "), Txt.parse(" <i>and "));
|
||||
}
|
||||
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.FPerm;
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.cmd.arg.ARFaction;
|
||||
import com.massivecraft.factions.entity.BoardColls;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.massivecore.cmd.arg.ARBoolean;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
||||
|
||||
public class CmdFactionsAccessFaction extends CmdFactionsAccessAbstract
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsAccessFaction()
|
||||
{
|
||||
// Aliases
|
||||
this.addAliases("f", "faction");
|
||||
|
||||
// Args
|
||||
this.addRequiredArg("faction");
|
||||
this.addOptionalArg("yes/no", "toggle");
|
||||
|
||||
// Requirements
|
||||
this.addRequirements(ReqHasPerm.get(Perm.ACCESS_FACTION.node));
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void innerPerform()
|
||||
{
|
||||
// Args
|
||||
Faction faction = this.arg(0, ARFaction.get(usender));
|
||||
if (faction == null) return;
|
||||
|
||||
Boolean newValue = this.arg(1, ARBoolean.get(), !ta.isFactionIdGranted(faction.getId()));
|
||||
if (newValue == null) return;
|
||||
|
||||
// FPerm
|
||||
if (!FPerm.ACCESS.has(usender, hostFaction, true)) return;
|
||||
|
||||
// Apply
|
||||
ta = ta.withFactionId(faction.getId(), newValue);
|
||||
BoardColls.get().setTerritoryAccessAt(chunk, ta);
|
||||
|
||||
// Inform
|
||||
this.sendAccessInfo();
|
||||
}
|
||||
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.FPerm;
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.cmd.arg.ARUPlayer;
|
||||
import com.massivecraft.factions.entity.BoardColls;
|
||||
import com.massivecraft.factions.entity.UPlayer;
|
||||
import com.massivecraft.massivecore.cmd.arg.ARBoolean;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
||||
|
||||
public class CmdFactionsAccessPlayer extends CmdFactionsAccessAbstract
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsAccessPlayer()
|
||||
{
|
||||
// Aliases
|
||||
this.addAliases("p", "player");
|
||||
|
||||
// Args
|
||||
this.addRequiredArg("player");
|
||||
this.addOptionalArg("yes/no", "toggle");
|
||||
|
||||
// Requirements
|
||||
this.addRequirements(ReqHasPerm.get(Perm.ACCESS_PLAYER.node));
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void innerPerform()
|
||||
{
|
||||
// Args
|
||||
UPlayer uplayer = this.arg(0, ARUPlayer.getAny(usender));
|
||||
if (uplayer == null) return;
|
||||
|
||||
Boolean newValue = this.arg(1, ARBoolean.get(), !ta.isPlayerIdGranted(uplayer.getId()));
|
||||
if (newValue == null) return;
|
||||
|
||||
// FPerm
|
||||
if (!FPerm.ACCESS.has(usender, hostFaction, true)) return;
|
||||
|
||||
// Apply
|
||||
ta = ta.withPlayerId(uplayer.getId(), newValue);
|
||||
BoardColls.get().setTerritoryAccessAt(chunk, ta);
|
||||
|
||||
// Inform
|
||||
this.sendAccessInfo();
|
||||
}
|
||||
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
||||
|
||||
public class CmdFactionsAccessView extends CmdFactionsAccessAbstract
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsAccessView()
|
||||
{
|
||||
// Aliases
|
||||
this.addAliases("v", "view");
|
||||
|
||||
// Requirements
|
||||
this.addRequirements(ReqHasPerm.get(Perm.ACCESS_VIEW.node));
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void innerPerform()
|
||||
{
|
||||
this.sendAccessInfo();
|
||||
}
|
||||
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.massivecore.cmd.arg.ARBoolean;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
||||
|
||||
public class CmdFactionsAdmin extends FCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsAdmin()
|
||||
{
|
||||
// Aliases
|
||||
this.addAliases("admin");
|
||||
|
||||
// Args
|
||||
this.addOptionalArg("on/off", "flip");
|
||||
|
||||
// Requirements
|
||||
// this.addRequirements(ReqFactionsEnabled.get());
|
||||
this.addRequirements(ReqHasPerm.get(Perm.ADMIN.node));
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform()
|
||||
{
|
||||
Boolean target = this.arg(0, ARBoolean.get(), !msender.isUsingAdminMode());
|
||||
if (target == null) return;
|
||||
|
||||
msender.setUsingAdminMode(target);
|
||||
|
||||
if (msender.isUsingAdminMode())
|
||||
{
|
||||
msender.msg("<i>You have enabled admin bypass mode.");
|
||||
Factions.get().log(msender.getId() + " has ENABLED admin bypass mode.");
|
||||
}
|
||||
else
|
||||
{
|
||||
msender.msg("<i>You have disabled admin bypass mode.");
|
||||
Factions.get().log(msender.getId() + " DISABLED admin bypass mode.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.FPerm;
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.cmd.arg.ARFaction;
|
||||
import com.massivecraft.factions.cmd.req.ReqFactionsEnabled;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.UConf;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqIsPlayer;
|
||||
import com.massivecraft.massivecore.ps.PS;
|
||||
|
||||
public class CmdFactionsAutoClaim extends FCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsAutoClaim()
|
||||
{
|
||||
// Aliases
|
||||
this.addAliases("autoclaim");
|
||||
|
||||
// Args
|
||||
this.addOptionalArg("faction", "you");
|
||||
|
||||
// Requirements
|
||||
this.addRequirements(ReqFactionsEnabled.get());
|
||||
this.addRequirements(ReqHasPerm.get(Perm.AUTOCLAIM.node));
|
||||
this.addRequirements(ReqIsPlayer.get());
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform()
|
||||
{
|
||||
// Check disabled
|
||||
if (UConf.isDisabled(sender, sender)) return;
|
||||
|
||||
// Args
|
||||
Faction forFaction = this.arg(0, ARFaction.get(usenderFaction), usenderFaction);
|
||||
|
||||
if (forFaction == null || forFaction == usender.getAutoClaimFaction())
|
||||
{
|
||||
usender.setAutoClaimFaction(null);
|
||||
msg("<i>Auto-claiming of land disabled.");
|
||||
return;
|
||||
}
|
||||
|
||||
// FPerm
|
||||
if (forFaction.isNormal() && !FPerm.TERRITORY.has(usender, forFaction, true)) return;
|
||||
|
||||
usender.setAutoClaimFaction(forFaction);
|
||||
|
||||
msg("<i>Now auto-claiming land for <h>%s<i>.", forFaction.describeTo(usender));
|
||||
usender.tryClaim(forFaction, PS.valueOf(me), true, true);
|
||||
}
|
||||
|
||||
}
|
@ -1,112 +0,0 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.FPerm;
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.cmd.arg.ARFaction;
|
||||
import com.massivecraft.factions.cmd.req.ReqFactionsEnabled;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.MConf;
|
||||
import com.massivecraft.factions.task.SpiralTask;
|
||||
import com.massivecraft.massivecore.cmd.arg.ARInteger;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqIsPlayer;
|
||||
import com.massivecraft.massivecore.ps.PS;
|
||||
|
||||
|
||||
public class CmdFactionsClaim extends FCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsClaim()
|
||||
{
|
||||
// Aliases
|
||||
this.addAliases("claim");
|
||||
|
||||
// Args
|
||||
this.addOptionalArg("radius", "1");
|
||||
this.addOptionalArg("faction", "you");
|
||||
|
||||
// Requirements
|
||||
this.addRequirements(ReqFactionsEnabled.get());
|
||||
this.addRequirements(ReqIsPlayer.get());
|
||||
this.addRequirements(ReqHasPerm.get(Perm.CLAIM.node));
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform()
|
||||
{
|
||||
// Args
|
||||
Integer radius = this.arg(0, ARInteger.get(), 1);
|
||||
if (radius == null) return;
|
||||
|
||||
final Faction forFaction = this.arg(1, ARFaction.get(me), usenderFaction);
|
||||
if (forFaction == null) return;
|
||||
|
||||
// FPerm
|
||||
if (forFaction.isNormal() && !FPerm.TERRITORY.has(usender, forFaction, true)) return;
|
||||
|
||||
// Validate
|
||||
if (radius < 1)
|
||||
{
|
||||
msg("<b>If you specify a radius, it must be at least 1.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (radius > MConf.get().radiusClaimRadiusLimit && !usender.isUsingAdminMode())
|
||||
{
|
||||
msg("<b>The maximum radius allowed is <h>%s<b>.", MConf.get().radiusClaimRadiusLimit);
|
||||
return;
|
||||
}
|
||||
|
||||
// Apply
|
||||
|
||||
// single chunk
|
||||
if (radius < 2)
|
||||
{
|
||||
usender.tryClaim(forFaction, PS.valueOf(me), true, true);
|
||||
return;
|
||||
}
|
||||
|
||||
// radius claim
|
||||
if (!Perm.CLAIM_RADIUS.has(sender, false))
|
||||
{
|
||||
msg("<b>You do not have permission to claim in a radius.");
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: There must be a better way than using a spiral task.
|
||||
// TODO: Do some research to allow for claming sets of chunks in a batch with atomicity.
|
||||
// This will probably result in an alteration to the owner change event.
|
||||
// It would possibly contain a set of chunks instead of a single chunk.
|
||||
|
||||
new SpiralTask(PS.valueOf(me), radius)
|
||||
{
|
||||
private int failCount = 0;
|
||||
private final int limit = MConf.get().radiusClaimFailureLimit - 1;
|
||||
|
||||
@Override
|
||||
public boolean work()
|
||||
{
|
||||
boolean success = usender.tryClaim(forFaction, PS.valueOf(this.currentLocation()), true, true);
|
||||
if (success)
|
||||
{
|
||||
this.failCount = 0;
|
||||
}
|
||||
else if (this.failCount++ >= this.limit)
|
||||
{
|
||||
this.stop();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,101 +0,0 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.cmd.req.ReqFactionsEnabled;
|
||||
import com.massivecraft.factions.cmd.req.ReqHasntFaction;
|
||||
import com.massivecraft.factions.entity.UPlayer;
|
||||
import com.massivecraft.factions.entity.UPlayerColls;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.FactionColl;
|
||||
import com.massivecraft.factions.entity.FactionColls;
|
||||
import com.massivecraft.factions.entity.MConf;
|
||||
import com.massivecraft.factions.event.EventFactionsCreate;
|
||||
import com.massivecraft.factions.event.EventFactionsMembershipChange;
|
||||
import com.massivecraft.factions.event.EventFactionsMembershipChange.MembershipChangeReason;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
||||
import com.massivecraft.massivecore.store.MStore;
|
||||
|
||||
public class CmdFactionsCreate extends FCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsCreate()
|
||||
{
|
||||
// Aliases
|
||||
this.addAliases("create");
|
||||
|
||||
// Args
|
||||
this.addRequiredArg("name");
|
||||
|
||||
// Requirements
|
||||
this.addRequirements(ReqFactionsEnabled.get());
|
||||
this.addRequirements(ReqHasntFaction.get());
|
||||
this.addRequirements(ReqHasPerm.get(Perm.CREATE.node));
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform()
|
||||
{
|
||||
// Args
|
||||
String newName = this.arg(0);
|
||||
|
||||
// Verify
|
||||
FactionColl coll = FactionColls.get().get(usender);
|
||||
|
||||
if (coll.isNameTaken(newName))
|
||||
{
|
||||
msg("<b>That name is already in use.");
|
||||
return;
|
||||
}
|
||||
|
||||
ArrayList<String> nameValidationErrors = coll.validateName(newName);
|
||||
if (nameValidationErrors.size() > 0)
|
||||
{
|
||||
sendMessage(nameValidationErrors);
|
||||
return;
|
||||
}
|
||||
|
||||
// Pre-Generate Id
|
||||
String factionId = MStore.createId();
|
||||
|
||||
// Event
|
||||
EventFactionsCreate createEvent = new EventFactionsCreate(sender, coll.getUniverse(), factionId, newName);
|
||||
createEvent.run();
|
||||
if (createEvent.isCancelled()) return;
|
||||
|
||||
// Apply
|
||||
Faction faction = coll.create(factionId);
|
||||
faction.setName(newName);
|
||||
|
||||
usender.setRole(Rel.LEADER);
|
||||
usender.setFaction(faction);
|
||||
|
||||
EventFactionsMembershipChange joinEvent = new EventFactionsMembershipChange(sender, usender, faction, MembershipChangeReason.CREATE);
|
||||
joinEvent.run();
|
||||
// NOTE: join event cannot be cancelled or you'll have an empty faction
|
||||
|
||||
// Inform
|
||||
for (UPlayer follower : UPlayerColls.get().get(usender).getAllOnline())
|
||||
{
|
||||
follower.msg("%s<i> created a new faction %s", usender.describeTo(follower, true), faction.getName(follower));
|
||||
}
|
||||
|
||||
msg("<i>You should now: %s", Factions.get().getOuterCmdFactions().cmdFactionsDescription.getUseageTemplate());
|
||||
|
||||
if (MConf.get().logFactionCreate)
|
||||
{
|
||||
Factions.get().log(usender.getName()+" created a new faction: "+newName);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,77 +0,0 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.cmd.arg.ARUPlayer;
|
||||
import com.massivecraft.factions.cmd.req.ReqFactionsEnabled;
|
||||
import com.massivecraft.factions.entity.UPlayer;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
||||
|
||||
public class CmdFactionsDemote extends FCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsDemote()
|
||||
{
|
||||
// Aliases
|
||||
this.addAliases("demote");
|
||||
|
||||
// Args
|
||||
this.addRequiredArg("player");
|
||||
|
||||
// Requirements
|
||||
this.addRequirements(ReqFactionsEnabled.get());
|
||||
this.addRequirements(ReqHasPerm.get(Perm.DEMOTE.node));
|
||||
|
||||
//To demote someone from member -> recruit you must be an officer.
|
||||
//To demote someone from officer -> member you must be a leader.
|
||||
//We'll handle this internally
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform()
|
||||
{
|
||||
UPlayer you = this.arg(0, ARUPlayer.getAny(usender));
|
||||
if (you == null) return;
|
||||
|
||||
if (you.getFaction() != usenderFaction)
|
||||
{
|
||||
msg("%s<b> is not a member in your faction.", you.describeTo(usender, true));
|
||||
return;
|
||||
}
|
||||
|
||||
if (you == usender)
|
||||
{
|
||||
msg("<b>The target player mustn't be yourself.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (you.getRole() == Rel.MEMBER)
|
||||
{
|
||||
if (!usender.getRole().isAtLeast(Rel.OFFICER))
|
||||
{
|
||||
msg("<b>You must be an officer to demote a member to recruit.");
|
||||
return;
|
||||
}
|
||||
you.setRole(Rel.RECRUIT);
|
||||
usenderFaction.msg("%s<i> was demoted to being a recruit in your faction.", you.describeTo(usenderFaction, true));
|
||||
}
|
||||
else if (you.getRole() == Rel.OFFICER)
|
||||
{
|
||||
if (!usender.getRole().isAtLeast(Rel.LEADER))
|
||||
{
|
||||
msg("<b>You must be the leader to demote an officer to member.");
|
||||
return;
|
||||
}
|
||||
you.setRole(Rel.MEMBER);
|
||||
usenderFaction.msg("%s<i> was demoted to being a member in your faction.", you.describeTo(usenderFaction, true));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,61 +0,0 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.cmd.req.ReqFactionsEnabled;
|
||||
import com.massivecraft.factions.cmd.req.ReqHasFaction;
|
||||
import com.massivecraft.factions.cmd.req.ReqRoleIsAtLeast;
|
||||
import com.massivecraft.factions.entity.UPlayer;
|
||||
import com.massivecraft.factions.event.EventFactionsDescriptionChange;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
||||
import com.massivecraft.massivecore.mixin.Mixin;
|
||||
|
||||
public class CmdFactionsDescription extends FCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsDescription()
|
||||
{
|
||||
// Aliases
|
||||
this.addAliases("desc");
|
||||
|
||||
// Args
|
||||
this.addRequiredArg("desc");
|
||||
this.setErrorOnToManyArgs(false);
|
||||
|
||||
// Requirements
|
||||
this.addRequirements(ReqFactionsEnabled.get());
|
||||
this.addRequirements(ReqHasPerm.get(Perm.DESCRIPTION.node));
|
||||
this.addRequirements(ReqHasFaction.get());
|
||||
this.addRequirements(ReqRoleIsAtLeast.get(Rel.OFFICER));
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform()
|
||||
{
|
||||
// Args
|
||||
String newDescription = this.argConcatFrom(0);
|
||||
|
||||
// Event
|
||||
EventFactionsDescriptionChange event = new EventFactionsDescriptionChange(sender, usenderFaction, newDescription);
|
||||
event.run();
|
||||
if (event.isCancelled()) return;
|
||||
newDescription = event.getNewDescription();
|
||||
|
||||
// Apply
|
||||
usenderFaction.setDescription(newDescription);
|
||||
|
||||
// Inform
|
||||
for (UPlayer follower : usenderFaction.getUPlayers())
|
||||
{
|
||||
follower.msg("<i>%s <i>set your faction description to:\n%s", Mixin.getDisplayName(sender, follower), usenderFaction.getDescription());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,97 +0,0 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.cmd.arg.ARFaction;
|
||||
import com.massivecraft.factions.cmd.req.ReqFactionsEnabled;
|
||||
import com.massivecraft.factions.entity.UPlayer;
|
||||
import com.massivecraft.factions.entity.UPlayerColls;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.FactionColls;
|
||||
import com.massivecraft.factions.entity.MConf;
|
||||
import com.massivecraft.factions.event.EventFactionsDisband;
|
||||
import com.massivecraft.factions.event.EventFactionsMembershipChange;
|
||||
import com.massivecraft.factions.event.EventFactionsMembershipChange.MembershipChangeReason;
|
||||
import com.massivecraft.factions.FFlag;
|
||||
import com.massivecraft.factions.FPerm;
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
||||
import com.massivecraft.massivecore.util.IdUtil;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
public class CmdFactionsDisband extends FCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsDisband()
|
||||
{
|
||||
// Aliases
|
||||
this.addAliases("disband");
|
||||
|
||||
// Args
|
||||
this.addOptionalArg("faction", "you");
|
||||
|
||||
// Requirements
|
||||
this.addRequirements(ReqFactionsEnabled.get());
|
||||
this.addRequirements(ReqHasPerm.get(Perm.DISBAND.node));
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform()
|
||||
{
|
||||
// Args
|
||||
Faction faction = this.arg(0, ARFaction.get(usender), usenderFaction);
|
||||
if (faction == null) return;
|
||||
|
||||
// FPerm
|
||||
if ( ! FPerm.DISBAND.has(usender, faction, true)) return;
|
||||
|
||||
// Verify
|
||||
if (faction.getFlag(FFlag.PERMANENT))
|
||||
{
|
||||
msg("<i>This faction is designated as permanent, so you cannot disband it.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Event
|
||||
EventFactionsDisband event = new EventFactionsDisband(me, faction);
|
||||
event.run();
|
||||
if (event.isCancelled()) return;
|
||||
|
||||
// Merged Apply and Inform
|
||||
|
||||
// Run event for each player in the faction
|
||||
for (UPlayer uplayer : faction.getUPlayers())
|
||||
{
|
||||
EventFactionsMembershipChange membershipChangeEvent = new EventFactionsMembershipChange(sender, uplayer, FactionColls.get().get(faction).getNone(), MembershipChangeReason.DISBAND);
|
||||
membershipChangeEvent.run();
|
||||
}
|
||||
|
||||
// Inform all players
|
||||
for (UPlayer uplayer : UPlayerColls.get().get(usender).getAllOnline())
|
||||
{
|
||||
String who = usender.describeTo(uplayer);
|
||||
if (uplayer.getFaction() == faction)
|
||||
{
|
||||
uplayer.msg("<h>%s<i> disbanded your faction.", who);
|
||||
}
|
||||
else
|
||||
{
|
||||
uplayer.msg("<h>%s<i> disbanded the faction %s.", who, faction.getName(uplayer));
|
||||
}
|
||||
}
|
||||
|
||||
if (MConf.get().logFactionDisband)
|
||||
{
|
||||
Factions.get().log(Txt.parse("<i>The faction <h>%s <i>(<h>%s<i>) was disbanded by <h>%s<i>.", faction.getName(), faction.getId(), usender.getDisplayName(IdUtil.getConsole())));
|
||||
}
|
||||
|
||||
faction.detach();
|
||||
}
|
||||
|
||||
}
|
@ -1,175 +0,0 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.massivecraft.factions.cmd.arg.ARFaction;
|
||||
import com.massivecraft.factions.cmd.req.ReqFactionsEnabled;
|
||||
import com.massivecraft.factions.entity.UConf;
|
||||
import com.massivecraft.factions.entity.UPlayer;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.event.EventFactionsChunkChangeType;
|
||||
import com.massivecraft.factions.integration.Econ;
|
||||
import com.massivecraft.factions.FFlag;
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.PlayerRoleComparator;
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
||||
import com.massivecraft.massivecore.mixin.Mixin;
|
||||
import com.massivecraft.massivecore.money.Money;
|
||||
import com.massivecraft.massivecore.util.TimeDiffUtil;
|
||||
import com.massivecraft.massivecore.util.TimeUnit;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
public class CmdFactionsFaction extends FCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsFaction()
|
||||
{
|
||||
// Aliases
|
||||
this.addAliases("f", "faction");
|
||||
|
||||
// Args
|
||||
this.addOptionalArg("faction", "you");
|
||||
|
||||
// Requirements
|
||||
this.addRequirements(ReqFactionsEnabled.get());
|
||||
this.addRequirements(ReqHasPerm.get(Perm.FACTION.node));
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform()
|
||||
{
|
||||
// Args
|
||||
Faction faction = this.arg(0, ARFaction.get(usenderFaction), usenderFaction);
|
||||
if (faction == null) return;
|
||||
|
||||
// Data precalculation
|
||||
UConf uconf = UConf.get(faction);
|
||||
//boolean none = faction.isNone();
|
||||
boolean normal = faction.isNormal();
|
||||
|
||||
// INFO: Title
|
||||
msg(Txt.titleize(Txt.upperCaseFirst(faction.getUniverse()) + " Faction " + faction.getName(usender)));
|
||||
|
||||
// INFO: Description
|
||||
msg("<a>Description: <i>%s", faction.getDescription());
|
||||
|
||||
if (normal)
|
||||
{
|
||||
// INFO: Age
|
||||
long ageMillis = faction.getCreatedAtMillis() - System.currentTimeMillis();
|
||||
LinkedHashMap<TimeUnit, Long> ageUnitcounts = TimeDiffUtil.limit(TimeDiffUtil.unitcounts(ageMillis, TimeUnit.getAllButMillis()), 3);
|
||||
String ageString = TimeDiffUtil.formatedVerboose(ageUnitcounts, "<i>");
|
||||
msg("<a>Age: <i>%s", ageString);
|
||||
|
||||
// INFO: Open
|
||||
msg("<a>Open: <i>"+(faction.isOpen() ? "<lime>Yes<i>, anyone can join" : "<rose>No<i>, only invited people can join"));
|
||||
|
||||
// INFO: Power
|
||||
double powerBoost = faction.getPowerBoost();
|
||||
String boost = (powerBoost == 0.0) ? "" : (powerBoost > 0.0 ? " (bonus: " : " (penalty: ") + powerBoost + ")";
|
||||
msg("<a>Land / Power / Maxpower: <i> %d/%d/%d %s", faction.getLandCount(), faction.getPowerRounded(), faction.getPowerMaxRounded(), boost);
|
||||
|
||||
// show the land value
|
||||
if (Econ.isEnabled(faction))
|
||||
{
|
||||
long landCount = faction.getLandCount();
|
||||
|
||||
for (EventFactionsChunkChangeType type : EventFactionsChunkChangeType.values())
|
||||
{
|
||||
Double money = uconf.econChunkCost.get(type);
|
||||
if (money == null) continue;
|
||||
if (money == 0D) continue;
|
||||
money *= landCount;
|
||||
|
||||
String word = null;
|
||||
if (money > 0)
|
||||
{
|
||||
word = "cost";
|
||||
}
|
||||
else
|
||||
{
|
||||
word = "reward";
|
||||
money *= -1;
|
||||
}
|
||||
|
||||
msg("<a>Total land %s %s: <i>%s", type.toString().toLowerCase(), word, Money.format(money));
|
||||
}
|
||||
|
||||
// Show bank contents
|
||||
if (UConf.get(faction).bankEnabled)
|
||||
{
|
||||
msg("<a>Bank contains: <i>"+Money.format(Money.get(faction)));
|
||||
}
|
||||
}
|
||||
|
||||
// Display important flags
|
||||
// TODO: Find the non default flags, and display them instead.
|
||||
if (faction.getFlag(FFlag.PERMANENT))
|
||||
{
|
||||
msg("<a>This faction is permanent - remaining even with no followers.");
|
||||
}
|
||||
|
||||
if (faction.getFlag(FFlag.PEACEFUL))
|
||||
{
|
||||
msg("<a>This faction is peaceful - in truce with everyone.");
|
||||
}
|
||||
}
|
||||
|
||||
String sepparator = Txt.parse("<i>")+", ";
|
||||
|
||||
// List the relations to other factions
|
||||
Map<Rel, List<String>> relationNames = faction.getFactionNamesPerRelation(usender, true);
|
||||
|
||||
if (faction.getFlag(FFlag.PEACEFUL))
|
||||
{
|
||||
sendMessage(Txt.parse("<a>In Truce with:<i> *everyone*"));
|
||||
}
|
||||
else
|
||||
{
|
||||
sendMessage(Txt.parse("<a>In Truce with: ") + Txt.implode(relationNames.get(Rel.TRUCE), sepparator));
|
||||
}
|
||||
|
||||
sendMessage(Txt.parse("<a>Allies: ") + Txt.implode(relationNames.get(Rel.ALLY), sepparator));
|
||||
sendMessage(Txt.parse("<a>Enemies: ") + Txt.implode(relationNames.get(Rel.ENEMY), sepparator));
|
||||
|
||||
// List the followers...
|
||||
List<String> followerNamesOnline = new ArrayList<String>();
|
||||
List<String> followerNamesOffline = new ArrayList<String>();
|
||||
|
||||
List<UPlayer> followers = faction.getUPlayers();
|
||||
Collections.sort(followers, PlayerRoleComparator.get());
|
||||
|
||||
for (UPlayer follower : followers)
|
||||
{
|
||||
if (follower.isOnline() && Mixin.canSee(sender, follower.getId()))
|
||||
{
|
||||
followerNamesOnline.add(follower.getNameAndTitle(usender));
|
||||
}
|
||||
else if (normal)
|
||||
{
|
||||
// For the non-faction we skip the offline members since they are far to many (infinate almost)
|
||||
followerNamesOffline.add(follower.getNameAndTitle(usender));
|
||||
}
|
||||
}
|
||||
|
||||
sendMessage(Txt.parse("<a>Followers online (%s): ", followerNamesOnline.size()) + Txt.implode(followerNamesOnline, sepparator));
|
||||
|
||||
if (normal)
|
||||
{
|
||||
sendMessage(Txt.parse("<a>Followers offline (%s): ", followerNamesOffline.size()) + Txt.implode(followerNamesOffline, sepparator));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,76 +0,0 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.FFlag;
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.cmd.arg.ARFFlag;
|
||||
import com.massivecraft.factions.cmd.arg.ARFaction;
|
||||
import com.massivecraft.factions.cmd.req.ReqFactionsEnabled;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.massivecore.cmd.arg.ARBoolean;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
public class CmdFactionsFlag extends FCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsFlag()
|
||||
{
|
||||
// Aliases
|
||||
this.addAliases("flag");
|
||||
|
||||
// Args
|
||||
this.addOptionalArg("faction", "you");
|
||||
this.addOptionalArg("flag", "all");
|
||||
this.addOptionalArg("yes/no", "read");
|
||||
|
||||
// Requirements
|
||||
this.addRequirements(ReqFactionsEnabled.get());
|
||||
this.addRequirements(ReqHasPerm.get(Perm.FLAG.node));
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform()
|
||||
{
|
||||
Faction faction = this.arg(0, ARFaction.get(sender), usenderFaction);
|
||||
if (faction == null) return;
|
||||
|
||||
if ( ! this.argIsSet(1))
|
||||
{
|
||||
msg(Txt.titleize("Flags for " + faction.describeTo(usender, true)));
|
||||
for (FFlag flag : FFlag.values())
|
||||
{
|
||||
msg(flag.getStateInfo(faction.getFlag(flag), true));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
FFlag flag = this.arg(1, ARFFlag.get());
|
||||
if (flag == null) return;
|
||||
|
||||
if ( ! this.argIsSet(2))
|
||||
{
|
||||
msg(Txt.titleize("Flag for " + faction.describeTo(usender, true)));
|
||||
msg(flag.getStateInfo(faction.getFlag(flag), true));
|
||||
return;
|
||||
}
|
||||
|
||||
Boolean targetValue = this.arg(2, ARBoolean.get());
|
||||
if (targetValue == null) return;
|
||||
|
||||
// Do the sender have the right to change flags?
|
||||
if ( ! Perm.FLAG_SET.has(sender, true)) return;
|
||||
|
||||
// Do the change
|
||||
msg(Txt.titleize("Flag for " + faction.describeTo(usender, true)));
|
||||
faction.setFlag(flag, targetValue);
|
||||
msg(flag.getStateInfo(faction.getFlag(flag), true));
|
||||
}
|
||||
|
||||
}
|
@ -1,151 +0,0 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.massivecraft.factions.FFlag;
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.cmd.req.ReqFactionsEnabled;
|
||||
import com.massivecraft.factions.cmd.req.ReqHasFaction;
|
||||
import com.massivecraft.factions.entity.BoardColls;
|
||||
import com.massivecraft.factions.entity.UConf;
|
||||
import com.massivecraft.factions.entity.UPlayer;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.event.EventFactionsHomeTeleport;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqIsPlayer;
|
||||
import com.massivecraft.massivecore.mixin.Mixin;
|
||||
import com.massivecraft.massivecore.mixin.TeleporterException;
|
||||
import com.massivecraft.massivecore.ps.PS;
|
||||
|
||||
|
||||
public class CmdFactionsHome extends FCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsHome()
|
||||
{
|
||||
// Aliases
|
||||
this.addAliases("home");
|
||||
|
||||
// Requirements
|
||||
this.addRequirements(ReqFactionsEnabled.get());
|
||||
this.addRequirements(ReqHasPerm.get(Perm.HOME.node));
|
||||
this.addRequirements(ReqHasFaction.get());
|
||||
this.addRequirements(ReqIsPlayer.get());
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform()
|
||||
{
|
||||
UConf uconf = UConf.get(sender);
|
||||
|
||||
// TODO: Hide this command on help also.
|
||||
if ( ! uconf.homesEnabled)
|
||||
{
|
||||
usender.msg("<b>Sorry, Faction homes are disabled on this server.");
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! uconf.homesTeleportCommandEnabled)
|
||||
{
|
||||
usender.msg("<b>Sorry, the ability to teleport to Faction homes is disabled on this server.");
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! usenderFaction.hasHome())
|
||||
{
|
||||
usender.msg("<b>Your faction does not have a home. " + (usender.getRole().isLessThan(Rel.OFFICER) ? "<i> Ask your leader to:" : "<i>You should:"));
|
||||
usender.sendMessage(Factions.get().getOuterCmdFactions().cmdFactionsSethome.getUseageTemplate());
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! uconf.homesTeleportAllowedFromEnemyTerritory && usender.isInEnemyTerritory())
|
||||
{
|
||||
usender.msg("<b>You cannot teleport to your faction home while in the territory of an enemy faction.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!uconf.homesTeleportAllowedFromDifferentWorld && !me.getWorld().getName().equalsIgnoreCase(usenderFaction.getHome().getWorld()))
|
||||
{
|
||||
usender.msg("<b>You cannot teleport to your faction home while in a different world.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Faction faction = BoardColls.get().getFactionAt(PS.valueOf(me));
|
||||
Location loc = me.getLocation().clone();
|
||||
|
||||
// if player is not in a safe zone or their own faction territory, only allow teleport if no enemies are nearby
|
||||
if
|
||||
(
|
||||
uconf.homesTeleportAllowedEnemyDistance > 0
|
||||
&&
|
||||
faction.getFlag(FFlag.PVP)
|
||||
&&
|
||||
(
|
||||
! usender.isInOwnTerritory()
|
||||
||
|
||||
(
|
||||
usender.isInOwnTerritory()
|
||||
&&
|
||||
! uconf.homesTeleportIgnoreEnemiesIfInOwnTerritory
|
||||
)
|
||||
)
|
||||
)
|
||||
{
|
||||
World w = loc.getWorld();
|
||||
double x = loc.getX();
|
||||
double y = loc.getY();
|
||||
double z = loc.getZ();
|
||||
|
||||
for (Player p : me.getServer().getOnlinePlayers())
|
||||
{
|
||||
if (p == null || !p.isOnline() || p.isDead() || p == me || p.getWorld() != w)
|
||||
continue;
|
||||
|
||||
UPlayer fp = UPlayer.get(p);
|
||||
if (usender.getRelationTo(fp) != Rel.ENEMY)
|
||||
continue;
|
||||
|
||||
Location l = p.getLocation();
|
||||
double dx = Math.abs(x - l.getX());
|
||||
double dy = Math.abs(y - l.getY());
|
||||
double dz = Math.abs(z - l.getZ());
|
||||
double max = uconf.homesTeleportAllowedEnemyDistance;
|
||||
|
||||
// box-shaped distance check
|
||||
if (dx > max || dy > max || dz > max)
|
||||
continue;
|
||||
|
||||
usender.msg("<b>You cannot teleport to your faction home while an enemy is within " + uconf.homesTeleportAllowedEnemyDistance + " blocks of you.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Event
|
||||
EventFactionsHomeTeleport event = new EventFactionsHomeTeleport(sender);
|
||||
event.run();
|
||||
if (event.isCancelled()) return;
|
||||
|
||||
// Apply
|
||||
try
|
||||
{
|
||||
Mixin.teleport(me, usenderFaction.getHome(), "your faction home", sender);
|
||||
}
|
||||
catch (TeleporterException e)
|
||||
{
|
||||
me.sendMessage(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,84 +0,0 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.FPerm;
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.cmd.arg.ARUPlayer;
|
||||
import com.massivecraft.factions.cmd.req.ReqFactionsEnabled;
|
||||
import com.massivecraft.factions.cmd.req.ReqHasFaction;
|
||||
import com.massivecraft.factions.entity.UPlayer;
|
||||
import com.massivecraft.factions.event.EventFactionsInvitedChange;
|
||||
import com.massivecraft.massivecore.cmd.arg.ARBoolean;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqIsPlayer;
|
||||
|
||||
public class CmdFactionsInvite extends FCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsInvite()
|
||||
{
|
||||
// Aliases
|
||||
this.addAliases("inv", "invite");
|
||||
|
||||
// Args
|
||||
this.addRequiredArg("player");
|
||||
this.addOptionalArg("yes/no", "toggle");
|
||||
|
||||
// Requirements
|
||||
this.addRequirements(ReqFactionsEnabled.get());
|
||||
this.addRequirements(ReqHasPerm.get(Perm.INVITE.node));
|
||||
this.addRequirements(ReqHasFaction.get());
|
||||
this.addRequirements(ReqIsPlayer.get());
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform()
|
||||
{
|
||||
// Args
|
||||
UPlayer uplayer = this.arg(0, ARUPlayer.getAny(sender));
|
||||
if (uplayer == null) return;
|
||||
|
||||
Boolean newInvited = this.arg(1, ARBoolean.get(), !usenderFaction.isInvited(uplayer));
|
||||
if (newInvited == null) return;
|
||||
|
||||
// Allready member?
|
||||
if (uplayer.getFaction() == usenderFaction)
|
||||
{
|
||||
msg("%s<i> is already a member of %s", uplayer.getName(), usenderFaction.getName());
|
||||
msg("<i>You might want to: " + Factions.get().getOuterCmdFactions().cmdFactionsKick.getUseageTemplate(false));
|
||||
return;
|
||||
}
|
||||
|
||||
// FPerm
|
||||
if ( ! FPerm.INVITE.has(usender, usenderFaction, true)) return;
|
||||
|
||||
// Event
|
||||
EventFactionsInvitedChange event = new EventFactionsInvitedChange(sender, uplayer, usenderFaction, newInvited);
|
||||
event.run();
|
||||
if (event.isCancelled()) return;
|
||||
newInvited = event.isNewInvited();
|
||||
|
||||
// Apply
|
||||
usenderFaction.setInvited(uplayer, newInvited);
|
||||
|
||||
// Inform
|
||||
if (newInvited)
|
||||
{
|
||||
uplayer.msg("%s<i> invited you to %s", usender.describeTo(uplayer, true), usenderFaction.describeTo(uplayer));
|
||||
usenderFaction.msg("%s<i> invited %s<i> to your faction.", usender.describeTo(usenderFaction, true), uplayer.describeTo(usenderFaction));
|
||||
}
|
||||
else
|
||||
{
|
||||
uplayer.msg("%s<i> revoked your invitation to <h>%s<i>.", usender.describeTo(uplayer), usenderFaction.describeTo(uplayer));
|
||||
usenderFaction.msg("%s<i> revoked %s's<i> invitation.", usender.describeTo(usenderFaction), uplayer.describeTo(usenderFaction));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,128 +0,0 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.cmd.arg.ARUPlayer;
|
||||
import com.massivecraft.factions.cmd.arg.ARFaction;
|
||||
import com.massivecraft.factions.cmd.req.ReqFactionsEnabled;
|
||||
import com.massivecraft.factions.entity.UPlayer;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.MConf;
|
||||
import com.massivecraft.factions.entity.UConf;
|
||||
import com.massivecraft.factions.event.EventFactionsMembershipChange;
|
||||
import com.massivecraft.factions.event.EventFactionsMembershipChange.MembershipChangeReason;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
public class CmdFactionsJoin extends FCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsJoin()
|
||||
{
|
||||
// Aliases
|
||||
this.addAliases("join");
|
||||
|
||||
// Args
|
||||
this.addRequiredArg("faction");
|
||||
this.addOptionalArg("player", "you");
|
||||
|
||||
// Requirements
|
||||
this.addRequirements(ReqFactionsEnabled.get());
|
||||
this.addRequirements(ReqHasPerm.get(Perm.JOIN.node));
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform()
|
||||
{
|
||||
// Args
|
||||
Faction faction = this.arg(0, ARFaction.get(sender));
|
||||
if (faction == null) return;
|
||||
|
||||
UPlayer uplayer = this.arg(1, ARUPlayer.getAny(sender), usender);
|
||||
if (uplayer == null) return;
|
||||
Faction uplayerFaction = uplayer.getFaction();
|
||||
|
||||
boolean samePlayer = uplayer == usender;
|
||||
|
||||
// Validate
|
||||
if (!samePlayer && ! Perm.JOIN_OTHERS.has(sender, false))
|
||||
{
|
||||
msg("<b>You do not have permission to move other players into a faction.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (faction == uplayerFaction)
|
||||
{
|
||||
msg("<i>%s <i>%s already a member of %s<i>.", uplayer.describeTo(usender, true), (samePlayer ? "are" : "is"), faction.getName(usender));
|
||||
return;
|
||||
}
|
||||
|
||||
if (UConf.get(faction).factionMemberLimit > 0 && faction.getUPlayers().size() >= UConf.get(faction).factionMemberLimit)
|
||||
{
|
||||
msg(" <b>!<white> The faction %s is at the limit of %d members, so %s cannot currently join.", faction.getName(usender), UConf.get(faction).factionMemberLimit, uplayer.describeTo(usender, false));
|
||||
return;
|
||||
}
|
||||
|
||||
if (uplayerFaction.isNormal())
|
||||
{
|
||||
msg("<b>%s must leave %s current faction first.", uplayer.describeTo(usender, true), (samePlayer ? "your" : "their"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!UConf.get(faction).canLeaveWithNegativePower && uplayer.getPower() < 0)
|
||||
{
|
||||
msg("<b>%s cannot join a faction with a negative power level.", uplayer.describeTo(usender, true));
|
||||
return;
|
||||
}
|
||||
|
||||
if( ! (faction.isOpen() || faction.isInvited(uplayer) || usender.isUsingAdminMode() || Perm.JOIN_ANY.has(sender, false)))
|
||||
{
|
||||
msg("<i>This faction requires invitation.");
|
||||
if (samePlayer)
|
||||
{
|
||||
faction.msg("%s<i> tried to join your faction.", uplayer.describeTo(faction, true));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Event
|
||||
EventFactionsMembershipChange membershipChangeEvent = new EventFactionsMembershipChange(sender, usender, faction, MembershipChangeReason.JOIN);
|
||||
membershipChangeEvent.run();
|
||||
if (membershipChangeEvent.isCancelled()) return;
|
||||
|
||||
// Inform
|
||||
if (!samePlayer)
|
||||
{
|
||||
uplayer.msg("<i>%s <i>moved you into the faction %s<i>.", usender.describeTo(uplayer, true), faction.getName(uplayer));
|
||||
}
|
||||
faction.msg("<i>%s <i>joined <lime>your faction<i>.", uplayer.describeTo(faction, true));
|
||||
usender.msg("<i>%s <i>successfully joined %s<i>.", uplayer.describeTo(usender, true), faction.getName(usender));
|
||||
|
||||
// Apply
|
||||
uplayer.resetFactionData();
|
||||
uplayer.setFaction(faction);
|
||||
|
||||
faction.setInvited(uplayer, false);
|
||||
|
||||
// Derplog
|
||||
if (MConf.get().logFactionJoin)
|
||||
{
|
||||
if (samePlayer)
|
||||
{
|
||||
Factions.get().log(Txt.parse("%s joined the faction %s.", uplayer.getName(), faction.getName()));
|
||||
}
|
||||
else
|
||||
{
|
||||
Factions.get().log(Txt.parse("%s moved the player %s into the faction %s.", usender.getName(), uplayer.getName(), faction.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,100 +0,0 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.FPerm;
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.cmd.arg.ARUPlayer;
|
||||
import com.massivecraft.factions.cmd.req.ReqFactionsEnabled;
|
||||
import com.massivecraft.factions.entity.UPlayer;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.FactionColls;
|
||||
import com.massivecraft.factions.entity.MConf;
|
||||
import com.massivecraft.factions.entity.UConf;
|
||||
import com.massivecraft.factions.event.EventFactionsMembershipChange;
|
||||
import com.massivecraft.factions.event.EventFactionsMembershipChange.MembershipChangeReason;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
||||
import com.massivecraft.massivecore.util.IdUtil;
|
||||
|
||||
public class CmdFactionsKick extends FCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsKick()
|
||||
{
|
||||
// Aliases
|
||||
this.addAliases("kick");
|
||||
|
||||
// Args
|
||||
this.addRequiredArg("player");
|
||||
|
||||
// Requirements
|
||||
this.addRequirements(ReqFactionsEnabled.get());
|
||||
this.addRequirements(ReqHasPerm.get(Perm.KICK.node));
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform()
|
||||
{
|
||||
// Arg
|
||||
UPlayer uplayer = this.arg(0, ARUPlayer.getAny(sender));
|
||||
if (uplayer == null) return;
|
||||
|
||||
// Validate
|
||||
if (usender == uplayer)
|
||||
{
|
||||
msg("<b>You cannot kick yourself.");
|
||||
msg("<i>You might want to: %s", Factions.get().getOuterCmdFactions().cmdFactionsLeave.getUseageTemplate(false));
|
||||
return;
|
||||
}
|
||||
|
||||
if (uplayer.getRole() == Rel.LEADER && !(this.senderIsConsole || usender.isUsingAdminMode()))
|
||||
{
|
||||
msg("<b>The leader can not be kicked.");
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! UConf.get(uplayer).canLeaveWithNegativePower && uplayer.getPower() < 0)
|
||||
{
|
||||
msg("<b>You cannot kick that member until their power is positive.");
|
||||
return;
|
||||
}
|
||||
|
||||
// FPerm
|
||||
Faction uplayerFaction = uplayer.getFaction();
|
||||
if (!FPerm.KICK.has(usender, uplayerFaction, true)) return;
|
||||
|
||||
// Event
|
||||
EventFactionsMembershipChange event = new EventFactionsMembershipChange(sender, uplayer, FactionColls.get().get(uplayer).getNone(), MembershipChangeReason.KICK);
|
||||
event.run();
|
||||
if (event.isCancelled()) return;
|
||||
|
||||
// Inform
|
||||
uplayerFaction.msg("%s<i> kicked %s<i> from the faction! :O", usender.describeTo(uplayerFaction, true), uplayer.describeTo(uplayerFaction, true));
|
||||
uplayer.msg("%s<i> kicked you from %s<i>! :O", usender.describeTo(uplayer, true), uplayerFaction.describeTo(uplayer));
|
||||
if (uplayerFaction != usenderFaction)
|
||||
{
|
||||
usender.msg("<i>You kicked %s<i> from the faction %s<i>!", uplayer.describeTo(usender), uplayerFaction.describeTo(usender));
|
||||
}
|
||||
|
||||
if (MConf.get().logFactionKick)
|
||||
{
|
||||
Factions.get().log(usender.getDisplayName(IdUtil.getConsole()) + " kicked " + uplayer.getName() + " from the faction " + uplayerFaction.getName());
|
||||
}
|
||||
|
||||
// Apply
|
||||
if (uplayer.getRole() == Rel.LEADER)
|
||||
{
|
||||
uplayerFaction.promoteNewLeader();
|
||||
}
|
||||
uplayerFaction.setInvited(uplayer, false);
|
||||
uplayer.resetFactionData();
|
||||
}
|
||||
|
||||
}
|
@ -1,111 +0,0 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.cmd.arg.ARUPlayer;
|
||||
import com.massivecraft.factions.cmd.arg.ARFaction;
|
||||
import com.massivecraft.factions.cmd.req.ReqFactionsEnabled;
|
||||
import com.massivecraft.factions.entity.UPlayer;
|
||||
import com.massivecraft.factions.entity.UPlayerColls;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.event.EventFactionsMembershipChange;
|
||||
import com.massivecraft.factions.event.EventFactionsMembershipChange.MembershipChangeReason;
|
||||
import com.massivecraft.factions.util.RelationUtil;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
public class CmdFactionsLeader extends FCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
public CmdFactionsLeader()
|
||||
{
|
||||
// Aliases
|
||||
this.addAliases("leader");
|
||||
|
||||
// Args
|
||||
this.addRequiredArg("player");
|
||||
this.addOptionalArg("faction", "you");
|
||||
|
||||
// Requirements
|
||||
this.addRequirements(ReqFactionsEnabled.get());
|
||||
this.addRequirements(ReqHasPerm.get(Perm.LEADER.node));
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform()
|
||||
{
|
||||
UPlayer newLeader = this.arg(0, ARUPlayer.getAny(sender));
|
||||
if (newLeader == null) return;
|
||||
|
||||
Faction targetFaction = this.arg(1, ARFaction.get(sender), usenderFaction);
|
||||
if (targetFaction == null) return;
|
||||
|
||||
UPlayer targetFactionCurrentLeader = targetFaction.getLeader();
|
||||
|
||||
// We now have uplayer and the target faction
|
||||
if (this.senderIsConsole || usender.isUsingAdminMode() || Perm.LEADER_ANY.has(sender, false))
|
||||
{
|
||||
// Do whatever you wish
|
||||
}
|
||||
else
|
||||
{
|
||||
// Follow the standard rules
|
||||
if (usender.getRole() != Rel.LEADER || targetFaction != usenderFaction)
|
||||
{
|
||||
sender.sendMessage(Txt.parse("<b>You must be leader of the faction to %s.", this.getDesc()));
|
||||
return;
|
||||
}
|
||||
|
||||
if (newLeader.getFaction() != usenderFaction)
|
||||
{
|
||||
msg("%s<i> is not a member in the faction.", newLeader.describeTo(usender, true));
|
||||
return;
|
||||
}
|
||||
|
||||
if (newLeader == usender)
|
||||
{
|
||||
msg("<b>The target player musn't be yourself.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// only run event when newLeader isn't actually in the faction
|
||||
if (newLeader.getFaction() != targetFaction)
|
||||
{
|
||||
EventFactionsMembershipChange event = new EventFactionsMembershipChange(sender, newLeader, targetFaction, MembershipChangeReason.LEADER);
|
||||
event.run();
|
||||
if (event.isCancelled()) return;
|
||||
}
|
||||
|
||||
// if target player is currently leader, demote and replace him
|
||||
if (targetFactionCurrentLeader == newLeader)
|
||||
{
|
||||
targetFaction.promoteNewLeader();
|
||||
msg("<i>You have demoted %s<i> from the position of faction leader.", newLeader.describeTo(usender, true));
|
||||
newLeader.msg("<i>You have been demoted from the position of faction leader by %s<i>.", usender.describeTo(newLeader, true));
|
||||
return;
|
||||
}
|
||||
|
||||
// Perform the switching
|
||||
if (targetFactionCurrentLeader != null)
|
||||
{
|
||||
targetFactionCurrentLeader.setRole(Rel.OFFICER);
|
||||
}
|
||||
newLeader.setFaction(targetFaction);
|
||||
newLeader.setRole(Rel.LEADER);
|
||||
msg("<i>You have promoted %s<i> to the position of faction leader.", newLeader.describeTo(usender, true));
|
||||
|
||||
// Inform all players
|
||||
for (UPlayer uplayer : UPlayerColls.get().get(sender).getAllOnline())
|
||||
{
|
||||
uplayer.msg("%s<i> gave %s<i> the leadership of %s<i>.", senderIsConsole ? "A server admin" : RelationUtil.describeThatToMe(usender, uplayer, true), newLeader.describeTo(uplayer), targetFaction.describeTo(uplayer));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.cmd.req.ReqFactionsEnabled;
|
||||
import com.massivecraft.factions.cmd.req.ReqHasFaction;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
||||
|
||||
public class CmdFactionsLeave extends FCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsLeave()
|
||||
{
|
||||
// Aliases
|
||||
this.addAliases("leave");
|
||||
|
||||
// Requirements
|
||||
this.addRequirements(ReqFactionsEnabled.get());
|
||||
this.addRequirements(ReqHasPerm.get(Perm.LEAVE.node));
|
||||
this.addRequirements(ReqHasFaction.get());
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform()
|
||||
{
|
||||
usender.leave();
|
||||
}
|
||||
|
||||
}
|
@ -1,84 +0,0 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.massivecraft.factions.FactionListComparator;
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.cmd.req.ReqFactionsEnabled;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.FactionColls;
|
||||
import com.massivecraft.massivecore.cmd.arg.ARInteger;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
|
||||
public class CmdFactionsList extends FCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsList()
|
||||
{
|
||||
// Aliases
|
||||
this.addAliases("l", "list");
|
||||
|
||||
// Args
|
||||
this.addOptionalArg("page", "1");
|
||||
|
||||
// Requirements
|
||||
this.addRequirements(ReqFactionsEnabled.get());
|
||||
this.addRequirements(ReqHasPerm.get(Perm.LIST.node));
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform()
|
||||
{
|
||||
Integer pageHumanBased = this.arg(0, ARInteger.get(), 1);
|
||||
if (pageHumanBased == null) return;
|
||||
|
||||
// Create Messages
|
||||
List<String> lines = new ArrayList<String>();
|
||||
|
||||
ArrayList<Faction> factionList = new ArrayList<Faction>(FactionColls.get().get(sender).getAll(null, FactionListComparator.get()));
|
||||
|
||||
final int pageheight = 9;
|
||||
|
||||
int pagecount = (factionList.size() / pageheight) + 1;
|
||||
if (pageHumanBased > pagecount)
|
||||
pageHumanBased = pagecount;
|
||||
else if (pageHumanBased < 1)
|
||||
pageHumanBased = 1;
|
||||
int start = (pageHumanBased - 1) * pageheight;
|
||||
int end = start + pageheight;
|
||||
if (end > factionList.size())
|
||||
end = factionList.size();
|
||||
|
||||
lines.add(Txt.titleize("Faction List "+pageHumanBased+"/"+pagecount));
|
||||
|
||||
for (Faction faction : factionList.subList(start, end))
|
||||
{
|
||||
if (faction.isNone())
|
||||
{
|
||||
lines.add(Txt.parse("<i>Factionless<i> %d online", FactionColls.get().get(sender).getNone().getUPlayersWhereOnline(true).size()));
|
||||
continue;
|
||||
}
|
||||
lines.add(Txt.parse("%s<i> %d/%d online, %d/%d/%d",
|
||||
faction.getName(usender),
|
||||
faction.getUPlayersWhereOnline(true).size(),
|
||||
faction.getUPlayers().size(),
|
||||
faction.getLandCount(),
|
||||
faction.getPowerRounded(),
|
||||
faction.getPowerMaxRounded())
|
||||
);
|
||||
}
|
||||
|
||||
sendMessage(lines);
|
||||
}
|
||||
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.cmd.req.ReqFactionsEnabled;
|
||||
import com.massivecraft.factions.entity.BoardColls;
|
||||
import com.massivecraft.massivecore.cmd.arg.ARBoolean;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqIsPlayer;
|
||||
import com.massivecraft.massivecore.ps.PS;
|
||||
|
||||
public class CmdFactionsMap extends FCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsMap()
|
||||
{
|
||||
// Aliases
|
||||
this.addAliases("map");
|
||||
|
||||
// Args
|
||||
this.addOptionalArg("on/off", "once");
|
||||
|
||||
// Requirements
|
||||
this.addRequirements(ReqFactionsEnabled.get());
|
||||
this.addRequirements(ReqHasPerm.get(Perm.MAP.node));
|
||||
this.addRequirements(ReqIsPlayer.get());
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform()
|
||||
{
|
||||
if (!this.argIsSet(0))
|
||||
{
|
||||
showMap();
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.arg(0, ARBoolean.get(), !msender.isMapAutoUpdating()))
|
||||
{
|
||||
// And show the map once
|
||||
showMap();
|
||||
|
||||
// Turn on
|
||||
msender.setMapAutoUpdating(true);
|
||||
msg("<i>Map auto update <green>ENABLED.");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Turn off
|
||||
msender.setMapAutoUpdating(false);
|
||||
msg("<i>Map auto update <red>DISABLED.");
|
||||
}
|
||||
}
|
||||
|
||||
public void showMap()
|
||||
{
|
||||
sendMessage(BoardColls.get().getMap(usenderFaction, PS.valueOf(me), me.getLocation().getYaw()));
|
||||
}
|
||||
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.cmd.req.ReqBankCommandsEnabled;
|
||||
import com.massivecraft.factions.cmd.req.ReqFactionsEnabled;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
||||
|
||||
public class CmdFactionsMoney extends FCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsMoneyBalance cmdMoneyBalance = new CmdFactionsMoneyBalance();
|
||||
public CmdFactionsMoneyDeposit cmdMoneyDeposit = new CmdFactionsMoneyDeposit();
|
||||
public CmdFactionsMoneyWithdraw cmdMoneyWithdraw = new CmdFactionsMoneyWithdraw();
|
||||
public CmdFactionsMoneyTransferFf cmdMoneyTransferFf = new CmdFactionsMoneyTransferFf();
|
||||
public CmdFactionsMoneyTransferFp cmdMoneyTransferFp = new CmdFactionsMoneyTransferFp();
|
||||
public CmdFactionsMoneyTransferPf cmdMoneyTransferPf = new CmdFactionsMoneyTransferPf();
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsMoney()
|
||||
{
|
||||
// Add SubCommands
|
||||
this.addSubCommand(this.cmdMoneyBalance);
|
||||
this.addSubCommand(this.cmdMoneyDeposit);
|
||||
this.addSubCommand(this.cmdMoneyWithdraw);
|
||||
this.addSubCommand(this.cmdMoneyTransferFf);
|
||||
this.addSubCommand(this.cmdMoneyTransferFp);
|
||||
this.addSubCommand(this.cmdMoneyTransferPf);
|
||||
|
||||
// Aliases
|
||||
this.addAliases("money");
|
||||
|
||||
// Requirements
|
||||
this.addRequirements(ReqFactionsEnabled.get());
|
||||
this.addRequirements(ReqBankCommandsEnabled.get());
|
||||
this.addRequirements(ReqHasPerm.get(Perm.MONEY.node));
|
||||
}
|
||||
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.cmd.arg.ARFaction;
|
||||
import com.massivecraft.factions.cmd.req.ReqBankCommandsEnabled;
|
||||
import com.massivecraft.factions.cmd.req.ReqFactionsEnabled;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.integration.Econ;
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
||||
|
||||
public class CmdFactionsMoneyBalance extends FCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsMoneyBalance()
|
||||
{
|
||||
// Aliases
|
||||
this.addAliases("b", "balance");
|
||||
|
||||
// Args
|
||||
this.addOptionalArg("faction", "you");
|
||||
|
||||
// Requirements
|
||||
this.addRequirements(ReqFactionsEnabled.get());
|
||||
this.addRequirements(ReqHasPerm.get(Perm.MONEY_BALANCE.node));
|
||||
this.addRequirements(ReqBankCommandsEnabled.get());
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform()
|
||||
{
|
||||
Faction faction = this.arg(0, ARFaction.get(sender), usenderFaction);
|
||||
if (faction == null) return;
|
||||
|
||||
if (faction != usenderFaction && ! Perm.MONEY_BALANCE_ANY.has(sender, true)) return;
|
||||
|
||||
Econ.sendBalanceInfo(usender, faction);
|
||||
}
|
||||
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.cmd.arg.ARFaction;
|
||||
import com.massivecraft.factions.cmd.req.ReqBankCommandsEnabled;
|
||||
import com.massivecraft.factions.cmd.req.ReqFactionsEnabled;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.MConf;
|
||||
import com.massivecraft.factions.integration.Econ;
|
||||
import com.massivecraft.massivecore.cmd.arg.ARDouble;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
||||
import com.massivecraft.massivecore.money.Money;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
public class CmdFactionsMoneyDeposit extends FCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsMoneyDeposit()
|
||||
{
|
||||
// Aliases
|
||||
this.addAliases("d", "deposit");
|
||||
|
||||
// Args
|
||||
this.addRequiredArg("amount");
|
||||
this.addOptionalArg("faction", "you");
|
||||
|
||||
// Requirements
|
||||
this.addRequirements(ReqFactionsEnabled.get());
|
||||
this.addRequirements(ReqHasPerm.get(Perm.MONEY_DEPOSIT.node));
|
||||
this.addRequirements(ReqBankCommandsEnabled.get());
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform()
|
||||
{
|
||||
Double amount = this.arg(0, ARDouble.get());
|
||||
if (amount == null) return;
|
||||
|
||||
Faction faction = this.arg(1, ARFaction.get(sender), usenderFaction);
|
||||
if (faction == null) return;
|
||||
|
||||
boolean success = Econ.transferMoney(usender, usender, faction, amount);
|
||||
|
||||
if (success && MConf.get().logMoneyTransactions)
|
||||
{
|
||||
Factions.get().log(ChatColor.stripColor(Txt.parse("%s deposited %s in the faction bank: %s", usender.getName(), Money.format(amount), faction.describeTo(null))));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.cmd.arg.ARFaction;
|
||||
import com.massivecraft.factions.cmd.req.ReqBankCommandsEnabled;
|
||||
import com.massivecraft.factions.cmd.req.ReqFactionsEnabled;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.MConf;
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.integration.Econ;
|
||||
import com.massivecraft.massivecore.cmd.arg.ARDouble;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
||||
import com.massivecraft.massivecore.money.Money;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
|
||||
public class CmdFactionsMoneyTransferFf extends FCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsMoneyTransferFf()
|
||||
{
|
||||
// Aliases
|
||||
this.addAliases("ff");
|
||||
|
||||
// Args
|
||||
this.addRequiredArg("amount");
|
||||
this.addRequiredArg("faction");
|
||||
this.addRequiredArg("faction");
|
||||
|
||||
// Requirements
|
||||
this.addRequirements(ReqFactionsEnabled.get());
|
||||
this.addRequirements(ReqHasPerm.get(Perm.MONEY_F2F.node));
|
||||
this.addRequirements(ReqBankCommandsEnabled.get());
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform()
|
||||
{
|
||||
Double amount = this.arg(0, ARDouble.get());
|
||||
if (amount == null) return;
|
||||
|
||||
Faction from = this.arg(1, ARFaction.get(sender));
|
||||
if (from == null) return;
|
||||
|
||||
Faction to = this.arg(2, ARFaction.get(sender));
|
||||
if (to == null) return;
|
||||
|
||||
boolean success = Econ.transferMoney(usender, from, to, amount);
|
||||
|
||||
if (success && MConf.get().logMoneyTransactions)
|
||||
{
|
||||
Factions.get().log(ChatColor.stripColor(Txt.parse("%s transferred %s from the faction \"%s\" to the faction \"%s\"", usender.getName(), Money.format(amount), from.describeTo(null), to.describeTo(null))));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,67 +0,0 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.cmd.arg.ARUPlayer;
|
||||
import com.massivecraft.factions.cmd.arg.ARFaction;
|
||||
import com.massivecraft.factions.cmd.req.ReqBankCommandsEnabled;
|
||||
import com.massivecraft.factions.cmd.req.ReqFactionsEnabled;
|
||||
import com.massivecraft.factions.entity.UPlayer;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.MConf;
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.integration.Econ;
|
||||
import com.massivecraft.massivecore.cmd.arg.ARDouble;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
||||
import com.massivecraft.massivecore.money.Money;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
|
||||
public class CmdFactionsMoneyTransferFp extends FCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsMoneyTransferFp()
|
||||
{
|
||||
// Aliases
|
||||
this.addAliases("fp");
|
||||
|
||||
// Args
|
||||
this.addRequiredArg("amount");
|
||||
this.addRequiredArg("faction");
|
||||
this.addRequiredArg("player");
|
||||
|
||||
// Requirements
|
||||
this.addRequirements(ReqFactionsEnabled.get());
|
||||
this.addRequirements(ReqHasPerm.get(Perm.MONEY_F2P.node));
|
||||
this.addRequirements(ReqBankCommandsEnabled.get());
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform()
|
||||
{
|
||||
Double amount = this.arg(0, ARDouble.get());
|
||||
if (amount == null) return;
|
||||
|
||||
Faction from = this.arg(1, ARFaction.get(sender));
|
||||
if (from == null) return;
|
||||
|
||||
UPlayer to = this.arg(2, ARUPlayer.getAny(sender));
|
||||
if (to == null) return;
|
||||
|
||||
boolean success = Econ.transferMoney(usender, from, to, amount);
|
||||
|
||||
if (success && MConf.get().logMoneyTransactions)
|
||||
{
|
||||
Factions.get().log(ChatColor.stripColor(Txt.parse("%s transferred %s from the faction \"%s\" to the player \"%s\"", usender.getName(), Money.format(amount), from.describeTo(null), to.describeTo(null))));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,67 +0,0 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.cmd.arg.ARUPlayer;
|
||||
import com.massivecraft.factions.cmd.arg.ARFaction;
|
||||
import com.massivecraft.factions.cmd.req.ReqBankCommandsEnabled;
|
||||
import com.massivecraft.factions.cmd.req.ReqFactionsEnabled;
|
||||
import com.massivecraft.factions.entity.UPlayer;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.MConf;
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.integration.Econ;
|
||||
import com.massivecraft.massivecore.cmd.arg.ARDouble;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
||||
import com.massivecraft.massivecore.money.Money;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
|
||||
public class CmdFactionsMoneyTransferPf extends FCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsMoneyTransferPf()
|
||||
{
|
||||
// Aliases
|
||||
this.addAliases("pf");
|
||||
|
||||
// Args
|
||||
this.addRequiredArg("amount");
|
||||
this.addRequiredArg("player");
|
||||
this.addRequiredArg("faction");
|
||||
|
||||
// Requirements
|
||||
this.addRequirements(ReqFactionsEnabled.get());
|
||||
this.addRequirements(ReqHasPerm.get(Perm.MONEY_P2F.node));
|
||||
this.addRequirements(ReqBankCommandsEnabled.get());
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform()
|
||||
{
|
||||
Double amount = this.arg(0, ARDouble.get());
|
||||
if (amount == null) return;
|
||||
|
||||
UPlayer from = this.arg(1, ARUPlayer.getAny(sender));
|
||||
if (from == null) return;
|
||||
|
||||
Faction to = this.arg(2, ARFaction.get(sender));
|
||||
if (to == null) return;
|
||||
|
||||
boolean success = Econ.transferMoney(usender, from, to, amount);
|
||||
|
||||
if (success && MConf.get().logMoneyTransactions)
|
||||
{
|
||||
Factions.get().log(ChatColor.stripColor(Txt.parse("%s transferred %s from the player \"%s\" to the faction \"%s\"", usender.getName(), Money.format(amount), from.describeTo(null), to.describeTo(null))));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.cmd.arg.ARFaction;
|
||||
import com.massivecraft.factions.cmd.req.ReqBankCommandsEnabled;
|
||||
import com.massivecraft.factions.cmd.req.ReqFactionsEnabled;
|
||||
import com.massivecraft.factions.entity.UPlayer;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.MConf;
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.integration.Econ;
|
||||
import com.massivecraft.massivecore.cmd.arg.ARDouble;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
||||
import com.massivecraft.massivecore.money.Money;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
|
||||
public class CmdFactionsMoneyWithdraw extends FCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsMoneyWithdraw()
|
||||
{
|
||||
// Aliases
|
||||
this.addAliases("w", "withdraw");
|
||||
|
||||
// Args
|
||||
this.addRequiredArg("amount");
|
||||
this.addOptionalArg("faction", "you");
|
||||
|
||||
// Requirements
|
||||
this.addRequirements(ReqFactionsEnabled.get());
|
||||
this.addRequirements(ReqHasPerm.get(Perm.MONEY_WITHDRAW.node));
|
||||
this.addRequirements(ReqBankCommandsEnabled.get());
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform()
|
||||
{
|
||||
Double amount = this.arg(0, ARDouble.get());
|
||||
if (amount == null) return;
|
||||
|
||||
Faction from = this.arg(1, ARFaction.get(sender), usenderFaction);
|
||||
if (from == null) return;
|
||||
|
||||
UPlayer to = usender;
|
||||
|
||||
boolean success = Econ.transferMoney(usender, from, to, amount);
|
||||
|
||||
if (success && MConf.get().logMoneyTransactions)
|
||||
{
|
||||
Factions.get().log(ChatColor.stripColor(Txt.parse("%s withdrew %s from the faction bank: %s", usender.getName(), Money.format(amount), from.describeTo(null))));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,90 +0,0 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.cmd.req.ReqFactionsEnabled;
|
||||
import com.massivecraft.factions.cmd.req.ReqHasFaction;
|
||||
import com.massivecraft.factions.cmd.req.ReqRoleIsAtLeast;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.FactionColl;
|
||||
import com.massivecraft.factions.entity.FactionColls;
|
||||
import com.massivecraft.factions.entity.UConf;
|
||||
import com.massivecraft.factions.event.EventFactionsNameChange;
|
||||
import com.massivecraft.factions.util.MiscUtil;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
||||
|
||||
public class CmdFactionsName extends FCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsName()
|
||||
{
|
||||
// Aliases
|
||||
this.addAliases("name");
|
||||
|
||||
// Args
|
||||
this.addRequiredArg("new name");
|
||||
|
||||
// Requirements
|
||||
this.addRequirements(ReqFactionsEnabled.get());
|
||||
this.addRequirements(ReqHasPerm.get(Perm.NAME.node));
|
||||
this.addRequirements(ReqHasFaction.get());
|
||||
this.addRequirements(ReqRoleIsAtLeast.get(Rel.OFFICER));
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform()
|
||||
{
|
||||
// Arg
|
||||
String newName = this.arg(0);
|
||||
|
||||
// TODO does not first test cover selfcase?
|
||||
|
||||
FactionColl factionColl = FactionColls.get().get(usenderFaction);
|
||||
if (factionColl.isNameTaken(newName) && ! MiscUtil.getComparisonString(newName).equals(usenderFaction.getComparisonName()))
|
||||
{
|
||||
msg("<b>That name is already taken");
|
||||
return;
|
||||
}
|
||||
|
||||
ArrayList<String> errors = new ArrayList<String>();
|
||||
errors.addAll(factionColl.validateName(newName));
|
||||
if (errors.size() > 0)
|
||||
{
|
||||
sendMessage(errors);
|
||||
return;
|
||||
}
|
||||
|
||||
// Event
|
||||
EventFactionsNameChange event = new EventFactionsNameChange(sender, usenderFaction, newName);
|
||||
event.run();
|
||||
if (event.isCancelled()) return;
|
||||
newName = event.getNewName();
|
||||
|
||||
// Apply
|
||||
String oldName = usenderFaction.getName();
|
||||
usenderFaction.setName(newName);
|
||||
|
||||
// Inform
|
||||
usenderFaction.msg("%s<i> changed your faction name to %s", usender.describeTo(usenderFaction, true), usenderFaction.getName(usenderFaction));
|
||||
|
||||
if (!UConf.get(usender).broadcastNameChange) return;
|
||||
for (Faction faction : FactionColls.get().get(usenderFaction).getAll())
|
||||
{
|
||||
if (faction == usenderFaction)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
faction.msg("<i>The player %s<i> changed their faction name from %s<i> to %s<i>.", usender.describeTo(faction, true), usender.getColorTo(faction)+oldName, usenderFaction.getName(faction));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,83 +0,0 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.cmd.arg.ARUPlayer;
|
||||
import com.massivecraft.factions.cmd.req.ReqFactionsEnabled;
|
||||
import com.massivecraft.factions.entity.UPlayer;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
||||
|
||||
public class CmdFactionsOfficer extends FCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsOfficer()
|
||||
{
|
||||
// Aliases
|
||||
this.addAliases("officer");
|
||||
|
||||
// Args
|
||||
this.addRequiredArg("player");
|
||||
|
||||
// Requirements
|
||||
this.addRequirements(ReqFactionsEnabled.get());
|
||||
this.addRequirements(ReqHasPerm.get(Perm.OFFICER.node));
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform()
|
||||
{
|
||||
UPlayer you = this.arg(0, ARUPlayer.getAny(sender));
|
||||
if (you == null) return;
|
||||
|
||||
boolean permAny = Perm.OFFICER_ANY.has(sender, false);
|
||||
Faction targetFaction = you.getFaction();
|
||||
|
||||
if (targetFaction != usenderFaction && !permAny)
|
||||
{
|
||||
msg("%s<b> is not a member in your faction.", you.describeTo(usender, true));
|
||||
return;
|
||||
}
|
||||
|
||||
if (usender != null && usender.getRole() != Rel.LEADER && !permAny)
|
||||
{
|
||||
msg("<b>You are not the faction leader.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (you == usender && !permAny)
|
||||
{
|
||||
msg("<b>The target player musn't be yourself.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (you.getRole() == Rel.LEADER)
|
||||
{
|
||||
msg("<b>The target player is a faction leader. Demote them first.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (you.getRole() == Rel.OFFICER)
|
||||
{
|
||||
// Revoke
|
||||
you.setRole(Rel.MEMBER);
|
||||
targetFaction.msg("%s<i> is no longer officer in your faction.", you.describeTo(targetFaction, true));
|
||||
msg("<i>You have removed officer status from %s<i>.", you.describeTo(usender, true));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Give
|
||||
you.setRole(Rel.OFFICER);
|
||||
targetFaction.msg("%s<i> was promoted to officer in your faction.", you.describeTo(targetFaction, true));
|
||||
msg("<i>You have promoted %s<i> to officer.", you.describeTo(usender, true));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.cmd.req.ReqFactionsEnabled;
|
||||
import com.massivecraft.factions.cmd.req.ReqHasFaction;
|
||||
import com.massivecraft.factions.cmd.req.ReqRoleIsAtLeast;
|
||||
import com.massivecraft.factions.event.EventFactionsOpenChange;
|
||||
import com.massivecraft.massivecore.cmd.arg.ARBoolean;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
||||
|
||||
public class CmdFactionsOpen extends FCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsOpen()
|
||||
{
|
||||
// Aliases
|
||||
this.addAliases("open");
|
||||
|
||||
// Args
|
||||
this.addOptionalArg("yes/no", "toggle");
|
||||
|
||||
// Requirements
|
||||
this.addRequirements(ReqFactionsEnabled.get());
|
||||
this.addRequirements(ReqHasPerm.get(Perm.OPEN.node));
|
||||
this.addRequirements(ReqHasFaction.get());
|
||||
this.addRequirements(ReqRoleIsAtLeast.get(Rel.OFFICER));
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform()
|
||||
{
|
||||
// Args
|
||||
Boolean newOpen = this.arg(0, ARBoolean.get(), !usenderFaction.isOpen());
|
||||
if (newOpen == null) return;
|
||||
|
||||
// Event
|
||||
EventFactionsOpenChange event = new EventFactionsOpenChange(sender, usenderFaction, newOpen);
|
||||
event.run();
|
||||
if (event.isCancelled()) return;
|
||||
newOpen = event.isNewOpen();
|
||||
|
||||
// Apply
|
||||
usenderFaction.setOpen(newOpen);
|
||||
|
||||
// Inform
|
||||
String descTarget = usenderFaction.isOpen() ? "open" : "closed";
|
||||
usenderFaction.msg("%s<i> changed the faction to <h>%s<i>.", usender.describeTo(usenderFaction, true), descTarget);
|
||||
}
|
||||
|
||||
}
|
@ -1,101 +0,0 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.FPerm;
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.cmd.arg.ARFPerm;
|
||||
import com.massivecraft.factions.cmd.arg.ARFaction;
|
||||
import com.massivecraft.factions.cmd.arg.ARRel;
|
||||
import com.massivecraft.factions.cmd.req.ReqFactionsEnabled;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.massivecore.cmd.arg.ARBoolean;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
public class CmdFactionsPerm extends FCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsPerm()
|
||||
{
|
||||
// Aliases
|
||||
this.addAliases("perm");
|
||||
|
||||
// Args
|
||||
this.addOptionalArg("faction", "you");
|
||||
this.addOptionalArg("perm", "all");
|
||||
this.addOptionalArg("relation", "read");
|
||||
this.addOptionalArg("yes/no", "read");
|
||||
this.setErrorOnToManyArgs(false);
|
||||
|
||||
// Requirements
|
||||
this.addRequirements(ReqFactionsEnabled.get());
|
||||
this.addRequirements(ReqHasPerm.get(Perm.PERM.node));
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform()
|
||||
{
|
||||
Faction faction = this.arg(0, ARFaction.get(usenderFaction), usenderFaction);
|
||||
if (faction == null) return;
|
||||
|
||||
if ( ! this.argIsSet(1))
|
||||
{
|
||||
msg(Txt.titleize("Perms for " + faction.describeTo(usender, true)));
|
||||
msg(FPerm.getStateHeaders());
|
||||
for (FPerm perm : FPerm.values())
|
||||
{
|
||||
msg(perm.getStateInfo(faction.getPermittedRelations(perm), true));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
FPerm perm = this.arg(1, ARFPerm.get());
|
||||
if (perm == null) return;
|
||||
//System.out.println("perm = "+perm);
|
||||
|
||||
if ( ! this.argIsSet(2))
|
||||
{
|
||||
msg(Txt.titleize("Perm for " + faction.describeTo(usender, true)));
|
||||
msg(FPerm.getStateHeaders());
|
||||
msg(perm.getStateInfo(faction.getPermittedRelations(perm), true));
|
||||
return;
|
||||
}
|
||||
|
||||
// Do the sender have the right to change perms for this faction?
|
||||
if ( ! FPerm.PERMS.has(usender, faction, true)) return;
|
||||
|
||||
Rel rel = this.arg(2, ARRel.get());
|
||||
if (rel == null) return;
|
||||
|
||||
if (!this.argIsSet(3))
|
||||
{
|
||||
msg("<b>Should <h>%s <b>have the <h>%s <b>permission or not?\nYou must <h>add \"yes\" or \"no\" <b>at the end.", Txt.getNicedEnum(rel), Txt.getNicedEnum(perm));
|
||||
return;
|
||||
}
|
||||
|
||||
Boolean val = this.arg(3, ARBoolean.get(), null);
|
||||
if (val == null) return;
|
||||
|
||||
// Do the change
|
||||
//System.out.println("setRelationPermitted perm "+perm+", rel "+rel+", val "+val);
|
||||
faction.setRelationPermitted(perm, rel, val);
|
||||
|
||||
// The following is to make sure the leader always has the right to change perms if that is our goal.
|
||||
if (perm == FPerm.PERMS && FPerm.PERMS.getDefault(faction).contains(Rel.LEADER))
|
||||
{
|
||||
faction.setRelationPermitted(FPerm.PERMS, Rel.LEADER, true);
|
||||
}
|
||||
|
||||
msg(Txt.titleize("Perm for " + faction.describeTo(usender, true)));
|
||||
msg(FPerm.getStateHeaders());
|
||||
msg(perm.getStateInfo(faction.getPermittedRelations(perm), true));
|
||||
}
|
||||
|
||||
}
|
@ -1,85 +0,0 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.cmd.arg.ARUPlayer;
|
||||
import com.massivecraft.factions.cmd.req.ReqFactionsEnabled;
|
||||
import com.massivecraft.factions.entity.UPlayer;
|
||||
import com.massivecraft.massivecore.Progressbar;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
||||
import com.massivecraft.massivecore.util.TimeDiffUtil;
|
||||
import com.massivecraft.massivecore.util.TimeUnit;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
public class CmdFactionsPlayer extends FCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsPlayer()
|
||||
{
|
||||
// Aliases
|
||||
this.addAliases("p", "player");
|
||||
|
||||
// Args
|
||||
this.addOptionalArg("player", "you");
|
||||
|
||||
// Requirements
|
||||
this.addRequirements(ReqFactionsEnabled.get());
|
||||
this.addRequirements(ReqHasPerm.get(Perm.PLAYER.node));
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform()
|
||||
{
|
||||
// Args
|
||||
UPlayer uplayer = this.arg(0, ARUPlayer.getAny(sender), usender);
|
||||
if (uplayer == null) return;
|
||||
|
||||
// INFO: Title
|
||||
msg(Txt.titleize(Txt.upperCaseFirst(uplayer.getUniverse()) + " Player " + uplayer.describeTo(usender)));
|
||||
|
||||
// INFO: Power (as progress bar)
|
||||
double progressbarQuota = uplayer.getPower() / uplayer.getPowerMax();
|
||||
int progressbarWidth = (int) Math.round(uplayer.getPowerMax() / uplayer.getPowerMaxUniversal() * 100);
|
||||
msg("<k>Power: <v>%s", Progressbar.HEALTHBAR_CLASSIC.withQuota(progressbarQuota).withWidth(progressbarWidth).render());
|
||||
|
||||
// INFO: Power (as digits)
|
||||
msg("<k>Power: <v>%.2f / %.2f", uplayer.getPower(), uplayer.getPowerMax());
|
||||
|
||||
// INFO: Power Boost
|
||||
if (uplayer.hasPowerBoost())
|
||||
{
|
||||
double powerBoost = uplayer.getPowerBoost();
|
||||
String powerBoostType = (powerBoost > 0 ? "bonus" : "penalty");
|
||||
msg("<k>Power Boost: <v>%f <i>(a manually granted %s)", powerBoost, powerBoostType);
|
||||
}
|
||||
|
||||
// INFO: Power per Hour
|
||||
// If the player is not at maximum we wan't to display how much time left.
|
||||
|
||||
String stringTillMax = "";
|
||||
double powerTillMax = uplayer.getPowerMax() - uplayer.getPower();
|
||||
if (powerTillMax > 0)
|
||||
{
|
||||
long millisTillMax = (long) (powerTillMax * TimeUnit.MILLIS_PER_HOUR / uplayer.getPowerPerHour());
|
||||
LinkedHashMap<TimeUnit, Long> unitcountsTillMax = TimeDiffUtil.unitcounts(millisTillMax, TimeUnit.getAllButMillis());
|
||||
unitcountsTillMax = TimeDiffUtil.limit(unitcountsTillMax, 2);
|
||||
String unitcountsTillMaxFormated = TimeDiffUtil.formatedVerboose(unitcountsTillMax, "<i>");
|
||||
stringTillMax = Txt.parse(" <i>(%s <i>left till max)", unitcountsTillMaxFormated);
|
||||
}
|
||||
|
||||
msg("<k>Power per Hour: <v>%.2f%s", uplayer.getPowerPerHour(), stringTillMax);
|
||||
|
||||
// INFO: Power per Death
|
||||
msg("<k>Power per Death: <v>%.2f", uplayer.getPowerPerDeath());
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,80 +0,0 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.cmd.arg.ARUPlayer;
|
||||
import com.massivecraft.factions.cmd.arg.ARFaction;
|
||||
import com.massivecraft.factions.cmd.req.ReqFactionsEnabled;
|
||||
import com.massivecraft.factions.entity.UPlayer;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.massivecore.cmd.arg.ARDouble;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
||||
|
||||
public class CmdFactionsPowerBoost extends FCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsPowerBoost()
|
||||
{
|
||||
// Aliases
|
||||
this.addAliases("powerboost");
|
||||
|
||||
// Args
|
||||
this.addRequiredArg("p|f|player|faction");
|
||||
this.addRequiredArg("name");
|
||||
this.addRequiredArg("#");
|
||||
|
||||
// Requirements
|
||||
this.addRequirements(ReqFactionsEnabled.get());
|
||||
this.addRequirements(ReqHasPerm.get(Perm.POWERBOOST.node));
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform()
|
||||
{
|
||||
String type = this.arg(0).toLowerCase();
|
||||
boolean doPlayer = true;
|
||||
if (type.equals("f") || type.equals("faction"))
|
||||
{
|
||||
doPlayer = false;
|
||||
}
|
||||
else if (!type.equals("p") && !type.equals("player"))
|
||||
{
|
||||
msg("<b>You must specify \"p\" or \"player\" to target a player or \"f\" or \"faction\" to target a faction.");
|
||||
msg("<b>ex. /f powerboost p SomePlayer 0.5 -or- /f powerboost f SomeFaction -5");
|
||||
return;
|
||||
}
|
||||
|
||||
Double targetPower = this.arg(2, ARDouble.get());
|
||||
if (targetPower == null) return;
|
||||
|
||||
String target;
|
||||
|
||||
if (doPlayer)
|
||||
{
|
||||
UPlayer targetPlayer = this.arg(1, ARUPlayer.getAny(sender));
|
||||
if (targetPlayer == null) return;
|
||||
|
||||
targetPlayer.setPowerBoost(targetPower);
|
||||
target = "Player \""+targetPlayer.getName()+"\"";
|
||||
}
|
||||
else
|
||||
{
|
||||
Faction targetFaction = this.arg(1, ARFaction.get(sender));
|
||||
if (targetFaction == null) return;
|
||||
|
||||
targetFaction.setPowerBoost(targetPower);
|
||||
target = "Faction \""+targetFaction.getName()+"\"";
|
||||
}
|
||||
|
||||
msg("<i>"+target+" now has a power bonus/penalty of "+targetPower+" to min and max power levels.");
|
||||
Factions.get().log(usender.getName()+" has set the power bonus/penalty for "+target+" to "+targetPower+".");
|
||||
}
|
||||
|
||||
}
|
@ -1,78 +0,0 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.cmd.arg.ARUPlayer;
|
||||
import com.massivecraft.factions.cmd.req.ReqFactionsEnabled;
|
||||
import com.massivecraft.factions.entity.UPlayer;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
||||
|
||||
public class CmdFactionsPromote extends FCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsPromote()
|
||||
{
|
||||
// Aliases
|
||||
this.addAliases("promote");
|
||||
|
||||
// Args
|
||||
this.addRequiredArg("player");
|
||||
|
||||
// Requirements
|
||||
this.addRequirements(ReqFactionsEnabled.get());
|
||||
this.addRequirements(ReqHasPerm.get(Perm.PROMOTE.node));
|
||||
|
||||
//To promote someone from recruit -> member you must be an officer.
|
||||
//To promote someone from member -> officer you must be a leader.
|
||||
//We'll handle this internally
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform()
|
||||
{
|
||||
UPlayer you = this.arg(0, ARUPlayer.getAny(sender));
|
||||
if (you == null) return;
|
||||
|
||||
if (you.getFaction() != usenderFaction)
|
||||
{
|
||||
msg("%s<b> is not a member in your faction.", you.describeTo(usender, true));
|
||||
return;
|
||||
}
|
||||
|
||||
if (you == usender)
|
||||
{
|
||||
msg("<b>The target player mustn't be yourself.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (you.getRole() == Rel.RECRUIT)
|
||||
{
|
||||
if (!usender.getRole().isAtLeast(Rel.OFFICER))
|
||||
{
|
||||
msg("<b>You must be an officer to promote someone to member.");
|
||||
return;
|
||||
}
|
||||
you.setRole(Rel.MEMBER);
|
||||
usenderFaction.msg("%s<i> was promoted to being a member of your faction.", you.describeTo(usenderFaction, true));
|
||||
}
|
||||
else if (you.getRole() == Rel.MEMBER)
|
||||
{
|
||||
if (!usender.getRole().isAtLeast(Rel.LEADER))
|
||||
{
|
||||
msg("<b>You must be the leader to promote someone to officer.");
|
||||
return;
|
||||
}
|
||||
// Give
|
||||
you.setRole(Rel.OFFICER);
|
||||
usenderFaction.msg("%s<i> was promoted to being a officer in your faction.", you.describeTo(usenderFaction, true));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,107 +0,0 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.FFlag;
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.cmd.arg.ARFaction;
|
||||
import com.massivecraft.factions.cmd.req.ReqFactionsEnabled;
|
||||
import com.massivecraft.factions.cmd.req.ReqHasFaction;
|
||||
import com.massivecraft.factions.cmd.req.ReqRoleIsAtLeast;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.MConf;
|
||||
import com.massivecraft.factions.event.EventFactionsRelationChange;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
||||
|
||||
public abstract class CmdFactionsRelationAbstract extends FCommand
|
||||
{
|
||||
public Rel targetRelation;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsRelationAbstract()
|
||||
{
|
||||
// Aliases
|
||||
this.addRequiredArg("faction");
|
||||
|
||||
// Requirements
|
||||
this.addRequirements(ReqFactionsEnabled.get());
|
||||
this.addRequirements(ReqHasPerm.get(Perm.RELATION.node));
|
||||
this.addRequirements(ReqHasFaction.get());
|
||||
this.addRequirements(ReqRoleIsAtLeast.get(Rel.OFFICER));
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform()
|
||||
{
|
||||
// Args
|
||||
Faction otherFaction = this.arg(0, ARFaction.get(sender));
|
||||
if (otherFaction == null) return;
|
||||
|
||||
Rel newRelation = targetRelation;
|
||||
|
||||
/*if ( ! them.isNormal())
|
||||
{
|
||||
msg("<b>Nope! You can't.");
|
||||
return;
|
||||
}*/
|
||||
|
||||
// Verify
|
||||
|
||||
if (otherFaction == usenderFaction)
|
||||
{
|
||||
msg("<b>Nope! You can't declare a relation to yourself :)");
|
||||
return;
|
||||
}
|
||||
|
||||
if (usenderFaction.getRelationWish(otherFaction) == newRelation)
|
||||
{
|
||||
msg("<b>You already have that relation wish set with %s.", otherFaction.getName());
|
||||
return;
|
||||
}
|
||||
|
||||
// Event
|
||||
EventFactionsRelationChange event = new EventFactionsRelationChange(sender, usenderFaction, otherFaction, newRelation);
|
||||
event.run();
|
||||
if (event.isCancelled()) return;
|
||||
newRelation = event.getNewRelation();
|
||||
|
||||
// try to set the new relation
|
||||
usenderFaction.setRelationWish(otherFaction, newRelation);
|
||||
Rel currentRelation = usenderFaction.getRelationTo(otherFaction, true);
|
||||
|
||||
// if the relation change was successful
|
||||
if (newRelation == currentRelation)
|
||||
{
|
||||
otherFaction.msg("%s<i> is now %s.", usenderFaction.describeTo(otherFaction, true), newRelation.getDescFactionOne());
|
||||
usenderFaction.msg("%s<i> is now %s.", otherFaction.describeTo(usenderFaction, true), newRelation.getDescFactionOne());
|
||||
}
|
||||
// inform the other faction of your request
|
||||
else
|
||||
{
|
||||
otherFaction.msg("%s<i> wishes to be %s.", usenderFaction.describeTo(otherFaction, true), newRelation.getColor()+newRelation.getDescFactionOne());
|
||||
otherFaction.msg("<i>Type <c>/"+MConf.get().aliasesF.get(0)+" "+newRelation+" "+usenderFaction.getName()+"<i> to accept.");
|
||||
usenderFaction.msg("%s<i> were informed that you wish to be %s<i>.", otherFaction.describeTo(usenderFaction, true), newRelation.getColor()+newRelation.getDescFactionOne());
|
||||
}
|
||||
|
||||
// TODO: The ally case should work!!
|
||||
// * this might have to be bumped up to make that happen, & allow ALLY,NEUTRAL only
|
||||
if ( newRelation != Rel.TRUCE && otherFaction.getFlag(FFlag.PEACEFUL))
|
||||
{
|
||||
otherFaction.msg("<i>This will have no effect while your faction is peaceful.");
|
||||
usenderFaction.msg("<i>This will have no effect while their faction is peaceful.");
|
||||
}
|
||||
|
||||
if ( newRelation != Rel.TRUCE && usenderFaction.getFlag(FFlag.PEACEFUL))
|
||||
{
|
||||
otherFaction.msg("<i>This will have no effect while their faction is peaceful.");
|
||||
usenderFaction.msg("<i>This will have no effect while your faction is peaceful.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.Rel;
|
||||
|
||||
public class CmdFactionsRelationAlly extends CmdFactionsRelationAbstract
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsRelationAlly()
|
||||
{
|
||||
// Aliases
|
||||
this.addAliases("ally");
|
||||
|
||||
// Misc
|
||||
this.targetRelation = Rel.ALLY;
|
||||
}
|
||||
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.Rel;
|
||||
|
||||
public class CmdFactionsRelationEnemy extends CmdFactionsRelationAbstract
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsRelationEnemy()
|
||||
{
|
||||
// Aliases
|
||||
this.addAliases("enemy");
|
||||
|
||||
// Misc
|
||||
this.targetRelation = Rel.ENEMY;
|
||||
}
|
||||
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.Rel;
|
||||
|
||||
public class CmdFactionsRelationNeutral extends CmdFactionsRelationAbstract
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsRelationNeutral()
|
||||
{
|
||||
// Aliases
|
||||
this.addAliases("neutral");
|
||||
|
||||
// Misc
|
||||
this.targetRelation = Rel.NEUTRAL;
|
||||
}
|
||||
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.Rel;
|
||||
|
||||
public class CmdFactionsRelationTruce extends CmdFactionsRelationAbstract
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsRelationTruce()
|
||||
{
|
||||
// Aliases
|
||||
this.addAliases("truce");
|
||||
|
||||
// Misc
|
||||
this.targetRelation = Rel.TRUCE;
|
||||
}
|
||||
|
||||
}
|
@ -1,81 +0,0 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.util.VisualizeUtil;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqIsPlayer;
|
||||
import com.massivecraft.massivecore.ps.PS;
|
||||
import com.massivecraft.massivecore.ps.PSFormatHumanSpace;
|
||||
|
||||
public class CmdFactionsSeeChunk extends FCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsSeeChunk()
|
||||
{
|
||||
// Aliases
|
||||
this.addAliases("sc", "seechunk");
|
||||
|
||||
// Requirements
|
||||
// this.addRequirements(ReqFactionsEnabled.get());
|
||||
this.addRequirements(ReqHasPerm.get(Perm.SEE_CHUNK.node));
|
||||
this.addRequirements(ReqIsPlayer.get());
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform()
|
||||
{
|
||||
// Args
|
||||
World world = me.getWorld();
|
||||
PS chunk = PS.valueOf(me).getChunk(true);
|
||||
int chunkX = chunk.getChunkX();
|
||||
int chunkZ = chunk.getChunkZ();
|
||||
|
||||
// Apply
|
||||
int blockX;
|
||||
int blockZ;
|
||||
|
||||
blockX = chunkX*16;
|
||||
blockZ = chunkZ*16;
|
||||
showPillar(me, world, blockX, blockZ);
|
||||
|
||||
blockX = chunkX*16 + 15;
|
||||
blockZ = chunkZ*16;
|
||||
showPillar(me, world, blockX, blockZ);
|
||||
|
||||
blockX = chunkX*16;
|
||||
blockZ = chunkZ*16 + 15;
|
||||
showPillar(me, world, blockX, blockZ);
|
||||
|
||||
blockX = chunkX*16 + 15;
|
||||
blockZ = chunkZ*16 + 15;
|
||||
showPillar(me, world, blockX, blockZ);
|
||||
|
||||
// Inform
|
||||
msg("<i>Visualized %s", chunk.toString(PSFormatHumanSpace.get()));
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static void showPillar(Player player, World world, int blockX, int blockZ)
|
||||
{
|
||||
for (int blockY = 0; blockY < world.getMaxHeight(); blockY++)
|
||||
{
|
||||
Location loc = new Location(world, blockX, blockY, blockZ);
|
||||
if (loc.getBlock().getType() != Material.AIR) continue;
|
||||
int typeId = blockY % 5 == 0 ? Material.GLOWSTONE.getId() : Material.GLASS.getId();
|
||||
VisualizeUtil.addLocation(player, loc, typeId);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,83 +0,0 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.FPerm;
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.cmd.arg.ARFaction;
|
||||
import com.massivecraft.factions.cmd.req.ReqFactionsEnabled;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.UConf;
|
||||
import com.massivecraft.factions.event.EventFactionsHomeChange;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqIsPlayer;
|
||||
import com.massivecraft.massivecore.ps.PS;
|
||||
|
||||
public class CmdFactionsSethome extends FCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsSethome()
|
||||
{
|
||||
// Aliases
|
||||
this.addAliases("sethome");
|
||||
|
||||
// Args
|
||||
this.addOptionalArg("faction", "you");
|
||||
|
||||
// Requirements
|
||||
this.addRequirements(ReqFactionsEnabled.get());
|
||||
this.addRequirements(ReqIsPlayer.get());
|
||||
this.addRequirements(ReqHasPerm.get(Perm.SETHOME.node));
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform()
|
||||
{
|
||||
// Args
|
||||
Faction faction = this.arg(0, ARFaction.get(usenderFaction), usenderFaction);
|
||||
if (faction == null) return;
|
||||
|
||||
PS newHome = PS.valueOf(me.getLocation());
|
||||
|
||||
// Validate
|
||||
if ( ! UConf.get(faction).homesEnabled)
|
||||
{
|
||||
usender.msg("<b>Sorry, Faction homes are disabled on this server.");
|
||||
return;
|
||||
}
|
||||
|
||||
// FPerm
|
||||
if ( ! FPerm.SETHOME.has(usender, faction, true)) return;
|
||||
|
||||
// Verify
|
||||
if (!usender.isUsingAdminMode() && !faction.isValidHome(newHome))
|
||||
{
|
||||
usender.msg("<b>Sorry, your faction home can only be set inside your own claimed territory.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Event
|
||||
EventFactionsHomeChange event = new EventFactionsHomeChange(sender, faction, newHome);
|
||||
event.run();
|
||||
if (event.isCancelled()) return;
|
||||
newHome = event.getNewHome();
|
||||
|
||||
// Apply
|
||||
faction.setHome(newHome);
|
||||
|
||||
// Inform
|
||||
faction.msg("%s<i> set the home for your faction. You can now use:", usender.describeTo(usenderFaction, true));
|
||||
faction.sendMessage(Factions.get().getOuterCmdFactions().cmdFactionsHome.getUseageTemplate());
|
||||
if (faction != usenderFaction)
|
||||
{
|
||||
usender.msg("<b>You have set the home for the "+faction.getName(usender)+"<i> faction.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,73 +0,0 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.cmd.arg.ARUPlayer;
|
||||
import com.massivecraft.factions.cmd.req.ReqFactionsEnabled;
|
||||
import com.massivecraft.factions.cmd.req.ReqRoleIsAtLeast;
|
||||
import com.massivecraft.factions.entity.UPlayer;
|
||||
import com.massivecraft.factions.event.EventFactionsTitleChange;
|
||||
import com.massivecraft.massivecore.cmd.arg.ARString;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
public class CmdFactionsTitle extends FCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsTitle()
|
||||
{
|
||||
// Aliases
|
||||
this.addAliases("title");
|
||||
|
||||
// Args
|
||||
this.addRequiredArg("player");
|
||||
this.addOptionalArg("title", "");
|
||||
|
||||
// Requirements
|
||||
this.addRequirements(ReqFactionsEnabled.get());
|
||||
this.addRequirements(ReqHasPerm.get(Perm.TITLE.node));
|
||||
this.addRequirements(ReqRoleIsAtLeast.get(Rel.OFFICER));
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform()
|
||||
{
|
||||
// Args
|
||||
UPlayer you = this.arg(0, ARUPlayer.getAny(sender));
|
||||
if (you == null) return;
|
||||
|
||||
String newTitle = this.argConcatFrom(1, ARString.get(), "");
|
||||
if (newTitle == null) return;
|
||||
|
||||
newTitle = Txt.parse(newTitle);
|
||||
if (!Perm.TITLE_COLOR.has(sender, false))
|
||||
{
|
||||
newTitle = ChatColor.stripColor(newTitle);
|
||||
}
|
||||
|
||||
// Verify
|
||||
if ( ! canIAdministerYou(usender, you)) return;
|
||||
|
||||
// Event
|
||||
EventFactionsTitleChange event = new EventFactionsTitleChange(sender, you, newTitle);
|
||||
event.run();
|
||||
if (event.isCancelled()) return;
|
||||
newTitle = event.getNewTitle();
|
||||
|
||||
// Apply
|
||||
you.setTitle(newTitle);
|
||||
|
||||
// Inform
|
||||
usenderFaction.msg("%s<i> changed a title: %s", usender.describeTo(usenderFaction, true), you.describeTo(usenderFaction, true));
|
||||
}
|
||||
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.cmd.req.ReqFactionsEnabled;
|
||||
import com.massivecraft.factions.cmd.req.ReqHasFaction;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.FactionColls;
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqIsPlayer;
|
||||
import com.massivecraft.massivecore.ps.PS;
|
||||
|
||||
public class CmdFactionsUnclaim extends FCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsUnclaim()
|
||||
{
|
||||
// Aliases
|
||||
this.addAliases("unclaim");
|
||||
|
||||
// Requirements
|
||||
this.addRequirements(ReqFactionsEnabled.get());
|
||||
this.addRequirements(ReqHasPerm.get(Perm.UNCLAIM.node));
|
||||
this.addRequirements(ReqHasFaction.get());
|
||||
this.addRequirements(ReqIsPlayer.get());
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform()
|
||||
{
|
||||
// Args
|
||||
PS chunk = PS.valueOf(me).getChunk(true);
|
||||
Faction newFaction = FactionColls.get().get(me).getNone();
|
||||
|
||||
// Apply
|
||||
if (usender.tryClaim(newFaction, chunk, true, true)) return;
|
||||
}
|
||||
|
||||
}
|
@ -1,84 +0,0 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import com.massivecraft.factions.FPerm;
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.cmd.req.ReqFactionsEnabled;
|
||||
import com.massivecraft.factions.cmd.req.ReqHasFaction;
|
||||
import com.massivecraft.factions.cmd.req.ReqRoleIsAtLeast;
|
||||
import com.massivecraft.factions.entity.BoardColl;
|
||||
import com.massivecraft.factions.entity.BoardColls;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.FactionColls;
|
||||
import com.massivecraft.factions.entity.MConf;
|
||||
import com.massivecraft.factions.event.EventFactionsChunkChange;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
||||
import com.massivecraft.massivecore.ps.PS;
|
||||
|
||||
public class CmdFactionsUnclaimall extends FCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsUnclaimall()
|
||||
{
|
||||
// Aliases
|
||||
this.addAliases("unclaimall");
|
||||
|
||||
// Requirements
|
||||
this.addRequirements(ReqFactionsEnabled.get());
|
||||
this.addRequirements(ReqHasPerm.get(Perm.UNCLAIM_ALL.node));
|
||||
this.addRequirements(ReqHasFaction.get());
|
||||
this.addRequirements(ReqRoleIsAtLeast.get(Rel.OFFICER));
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform()
|
||||
{
|
||||
// Args
|
||||
Faction faction = usenderFaction;
|
||||
Faction newFaction = FactionColls.get().get(faction).getNone();
|
||||
|
||||
// FPerm
|
||||
if (!FPerm.TERRITORY.has(usender, faction, true)) return;
|
||||
|
||||
// Apply
|
||||
BoardColl boardColl = BoardColls.get().get(faction);
|
||||
Set<PS> chunks = boardColl.getChunks(faction);
|
||||
int countTotal = chunks.size();
|
||||
int countSuccess = 0;
|
||||
int countFail = 0;
|
||||
for (PS chunk : chunks)
|
||||
{
|
||||
EventFactionsChunkChange event = new EventFactionsChunkChange(sender, chunk, newFaction);
|
||||
event.run();
|
||||
if (event.isCancelled())
|
||||
{
|
||||
countFail++;
|
||||
}
|
||||
else
|
||||
{
|
||||
countSuccess++;
|
||||
boardColl.setFactionAt(chunk, newFaction);
|
||||
}
|
||||
}
|
||||
|
||||
// Inform
|
||||
usenderFaction.msg("%s<i> unclaimed <h>%d <i>of your <h>%d <i>faction land. You now have <h>%d <i>land claimed.", usender.describeTo(usenderFaction, true), countSuccess, countTotal, countFail);
|
||||
|
||||
// Log
|
||||
if (MConf.get().logLandUnclaims)
|
||||
{
|
||||
Factions.get().log(usender.getName()+" unclaimed everything for the faction: "+usenderFaction.getName());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,80 +0,0 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import com.massivecraft.factions.entity.UConf;
|
||||
import com.massivecraft.factions.entity.UPlayer;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.massivecore.cmd.MassiveCommand;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
public abstract class FCommand extends MassiveCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public MPlayer msender;
|
||||
public UPlayer usender;
|
||||
public Faction usenderFaction;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void fixSenderVars()
|
||||
{
|
||||
this.msender = MPlayer.get(sender);
|
||||
|
||||
this.usender = null;
|
||||
this.usenderFaction = null;
|
||||
|
||||
// Check disabled
|
||||
if (UConf.isDisabled(sender)) return;
|
||||
|
||||
this.usender = UPlayer.get(this.sender);
|
||||
this.usenderFaction = this.usender.getFaction();
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// COMMONLY USED LOGIC
|
||||
// -------------------------------------------- //
|
||||
|
||||
public boolean canIAdministerYou(UPlayer i, UPlayer you)
|
||||
{
|
||||
if ( ! i.getFaction().equals(you.getFaction()))
|
||||
{
|
||||
i.sendMessage(Txt.parse("%s <b>is not in the same faction as you.",you.describeTo(i, true)));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (i.getRole().isMoreThan(you.getRole()) || i.getRole().equals(Rel.LEADER) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (you.getRole().equals(Rel.LEADER))
|
||||
{
|
||||
i.sendMessage(Txt.parse("<b>Only the faction leader can do that."));
|
||||
}
|
||||
else if (i.getRole().equals(Rel.OFFICER))
|
||||
{
|
||||
if ( i == you )
|
||||
{
|
||||
return true; //Moderators can control themselves
|
||||
}
|
||||
else
|
||||
{
|
||||
i.sendMessage(Txt.parse("<b>Moderators can't control each other..."));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
i.sendMessage(Txt.parse("<b>You must be a faction moderator to do that."));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
package com.massivecraft.factions.cmd.arg;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.massivecraft.factions.FFlag;
|
||||
import com.massivecraft.massivecore.cmd.arg.ARAbstractSelect;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
public class ARFFlag extends ARAbstractSelect<FFlag>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static ARFFlag i = new ARFFlag();
|
||||
public static ARFFlag get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public String typename()
|
||||
{
|
||||
return "faction flag";
|
||||
}
|
||||
|
||||
@Override
|
||||
public FFlag select(String str, CommandSender sender)
|
||||
{
|
||||
return FFlag.parse(str);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> altNames(CommandSender sender)
|
||||
{
|
||||
List<String> ret = new ArrayList<String>();
|
||||
|
||||
for (FFlag fflag : FFlag.values())
|
||||
{
|
||||
ret.add(Txt.getNicedEnum(fflag));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
package com.massivecraft.factions.cmd.arg;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.massivecraft.factions.FPerm;
|
||||
import com.massivecraft.massivecore.cmd.arg.ARAbstractSelect;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
public class ARFPerm extends ARAbstractSelect<FPerm>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static ARFPerm i = new ARFPerm();
|
||||
public static ARFPerm get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public String typename()
|
||||
{
|
||||
return "faction permission";
|
||||
}
|
||||
|
||||
@Override
|
||||
public FPerm select(String str, CommandSender sender)
|
||||
{
|
||||
return FPerm.parse(str);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> altNames(CommandSender sender)
|
||||
{
|
||||
List<String> ret = new ArrayList<String>();
|
||||
|
||||
for (FPerm fperm : FPerm.values())
|
||||
{
|
||||
ret.add(Txt.getNicedEnum(fperm));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
package com.massivecraft.factions.cmd.arg;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.massivecraft.factions.entity.UPlayer;
|
||||
import com.massivecraft.factions.entity.UPlayerColls;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.FactionColl;
|
||||
import com.massivecraft.factions.entity.FactionColls;
|
||||
import com.massivecraft.massivecore.cmd.arg.ArgReaderAbstract;
|
||||
import com.massivecraft.massivecore.cmd.arg.ArgResult;
|
||||
import com.massivecraft.massivecore.util.IdUtil;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
public class ARFaction extends ArgReaderAbstract<Faction>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static ARFaction get(Object universe) { return new ARFaction(FactionColls.get().get(universe)); }
|
||||
private ARFaction(FactionColl coll)
|
||||
{
|
||||
this.coll = coll;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
private final FactionColl coll;
|
||||
public FactionColl getColl() { return this.coll;}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public ArgResult<Faction> read(String str, CommandSender sender)
|
||||
{
|
||||
ArgResult<Faction> result = new ArgResult<Faction>();
|
||||
|
||||
// Faction Name Exact
|
||||
result.setResult(this.getColl().getByName(str));
|
||||
if (result.hasResult()) return result;
|
||||
|
||||
// Faction Name Match
|
||||
result.setResult(this.getColl().getBestNameMatch(str));
|
||||
if (result.hasResult()) return result;
|
||||
|
||||
// UPlayer Name Exact
|
||||
String id = IdUtil.getId(str);
|
||||
UPlayer uplayer = UPlayerColls.get().get(this.getColl()).get(id);
|
||||
if (uplayer != null)
|
||||
{
|
||||
result.setResult(uplayer.getFaction());
|
||||
return result;
|
||||
}
|
||||
|
||||
result.setErrors(Txt.parse("<b>No faction or player matching \"<p>%s<b>\".", str));
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
package com.massivecraft.factions.cmd.arg;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.massivecore.cmd.arg.ARAbstractSelect;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
public class ARRel extends ARAbstractSelect<Rel>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static ARRel i = new ARRel();
|
||||
public static ARRel get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public String typename()
|
||||
{
|
||||
return "role";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rel select(String str, CommandSender sender)
|
||||
{
|
||||
return Rel.parse(str);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> altNames(CommandSender sender)
|
||||
{
|
||||
List<String> ret = new ArrayList<String>();
|
||||
|
||||
for (Rel rel : Rel.values())
|
||||
{
|
||||
ret.add(Txt.getNicedEnum(rel));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
package com.massivecraft.factions.cmd.arg;
|
||||
|
||||
import com.massivecraft.factions.entity.UPlayer;
|
||||
import com.massivecraft.factions.entity.UPlayerColls;
|
||||
import com.massivecraft.massivecore.cmd.arg.ArgReader;
|
||||
|
||||
public class ARUPlayer
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static ArgReader<UPlayer> getAny(Object o) { return UPlayerColls.get().get(o).getAREntity(); }
|
||||
|
||||
public static ArgReader<UPlayer> getOnline(Object o) { return UPlayerColls.get().get(o).getAREntity(true); }
|
||||
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
package com.massivecraft.factions.cmd.req;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.massivecraft.factions.entity.UConf;
|
||||
import com.massivecraft.massivecore.cmd.MassiveCommand;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqAbstract;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
public class ReqBankCommandsEnabled extends ReqAbstract
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static ReqBankCommandsEnabled i = new ReqBankCommandsEnabled();
|
||||
public static ReqBankCommandsEnabled get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public boolean apply(CommandSender sender, MassiveCommand command)
|
||||
{
|
||||
return UConf.get(sender).econEnabled && UConf.get(sender).bankEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createErrorMessage(CommandSender sender, MassiveCommand command)
|
||||
{
|
||||
UConf uconf = UConf.get(sender);
|
||||
if (!uconf.bankEnabled)
|
||||
{
|
||||
return Txt.parse("<b>Faction banks are disabled in the <h>%s <b>universe.", uconf.getUniverse());
|
||||
}
|
||||
return Txt.parse("<b>Faction economy features are disabled in the <h>%s <b>universe.", uconf.getUniverse());
|
||||
}
|
||||
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
package com.massivecraft.factions.cmd.req;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.massivecraft.factions.entity.UConf;
|
||||
import com.massivecraft.massivecore.cmd.MassiveCommand;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqAbstract;
|
||||
|
||||
public class ReqFactionsEnabled extends ReqAbstract
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static ReqFactionsEnabled i = new ReqFactionsEnabled();
|
||||
public static ReqFactionsEnabled get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public boolean apply(CommandSender sender, MassiveCommand command)
|
||||
{
|
||||
return !UConf.isDisabled(sender);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createErrorMessage(CommandSender sender, MassiveCommand command)
|
||||
{
|
||||
return UConf.getDisabledMessage(sender);
|
||||
}
|
||||
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
package com.massivecraft.factions.cmd.req;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.massivecraft.factions.entity.UPlayer;
|
||||
import com.massivecraft.massivecore.cmd.MassiveCommand;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqAbstract;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
public class ReqHasFaction extends ReqAbstract
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static ReqHasFaction i = new ReqHasFaction();
|
||||
public static ReqHasFaction get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public boolean apply(CommandSender sender, MassiveCommand command)
|
||||
{
|
||||
return UPlayer.get(sender).hasFaction();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createErrorMessage(CommandSender sender, MassiveCommand command)
|
||||
{
|
||||
return Txt.parse("<b>You must belong to a faction to "+(command == null ? "do that" : command.getDesc())+".");
|
||||
}
|
||||
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
package com.massivecraft.factions.cmd.req;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.massivecraft.factions.entity.UPlayer;
|
||||
import com.massivecraft.massivecore.cmd.MassiveCommand;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqAbstract;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
public class ReqHasntFaction extends ReqAbstract
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static ReqHasntFaction i = new ReqHasntFaction();
|
||||
public static ReqHasntFaction get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public boolean apply(CommandSender sender, MassiveCommand command)
|
||||
{
|
||||
return !UPlayer.get(sender).hasFaction();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createErrorMessage(CommandSender sender, MassiveCommand command)
|
||||
{
|
||||
return Txt.parse("<b>You must leave your current faction before you "+(command == null ? "do that" : command.getDesc())+".");
|
||||
}
|
||||
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
package com.massivecraft.factions.cmd.req;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.entity.UPlayer;
|
||||
import com.massivecraft.massivecore.cmd.MassiveCommand;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqAbstract;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
public class ReqRoleIsAtLeast extends ReqAbstract
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
private final Rel rel;
|
||||
public Rel getRel() { return this.rel; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static ReqRoleIsAtLeast get(Rel rel) { return new ReqRoleIsAtLeast(rel); }
|
||||
private ReqRoleIsAtLeast(Rel rel) { this.rel = rel; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public boolean apply(CommandSender sender, MassiveCommand command)
|
||||
{
|
||||
UPlayer uplayer = UPlayer.get(sender);
|
||||
return uplayer.getRole().isAtLeast(this.rel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createErrorMessage(CommandSender sender, MassiveCommand command)
|
||||
{
|
||||
return Txt.parse("<b>You must be <h>%s <b>or higher to "+(command == null ? "do that" : command.getDesc())+".", Txt.getNicedEnum(this.rel));
|
||||
}
|
||||
|
||||
}
|
@ -1,345 +0,0 @@
|
||||
package com.massivecraft.factions.entity;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentSkipListMap;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import com.massivecraft.factions.Const;
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.RelationParticipator;
|
||||
import com.massivecraft.factions.TerritoryAccess;
|
||||
import com.massivecraft.factions.util.AsciiCompass;
|
||||
import com.massivecraft.massivecore.ps.PS;
|
||||
import com.massivecraft.massivecore.store.Entity;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
import com.massivecraft.massivecore.xlib.gson.reflect.TypeToken;
|
||||
|
||||
public class Board extends Entity<Board> implements BoardInterface
|
||||
{
|
||||
public static final transient Type MAP_TYPE = new TypeToken<Map<PS, TerritoryAccess>>(){}.getType();
|
||||
|
||||
// -------------------------------------------- //
|
||||
// META
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static Board get(Object oid)
|
||||
{
|
||||
return BoardColls.get().get2(oid);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE: ENTITY
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Board load(Board that)
|
||||
{
|
||||
this.map = that.map;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDefault()
|
||||
{
|
||||
if (this.map == null) return true;
|
||||
if (this.map.isEmpty()) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
// TODO: Make TerritoryAccess immutable.
|
||||
|
||||
private ConcurrentSkipListMap<PS, TerritoryAccess> map;
|
||||
public Map<PS, TerritoryAccess> getMap() { return Collections.unmodifiableMap(this.map); }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public Board()
|
||||
{
|
||||
this.map = new ConcurrentSkipListMap<PS, TerritoryAccess>();
|
||||
}
|
||||
|
||||
public Board(Map<PS, TerritoryAccess> map)
|
||||
{
|
||||
this.map = new ConcurrentSkipListMap<PS, TerritoryAccess>(map);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE: BOARD
|
||||
// -------------------------------------------- //
|
||||
|
||||
// GET
|
||||
|
||||
@Override
|
||||
public TerritoryAccess getTerritoryAccessAt(PS ps)
|
||||
{
|
||||
if (ps == null) return null;
|
||||
ps = ps.getChunkCoords(true);
|
||||
TerritoryAccess ret = this.map.get(ps);
|
||||
if (ret == null) ret = TerritoryAccess.valueOf(UConf.get(this).factionIdNone);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Faction getFactionAt(PS ps)
|
||||
{
|
||||
if (ps == null) return null;
|
||||
TerritoryAccess ta = this.getTerritoryAccessAt(ps);
|
||||
return ta.getHostFaction(this);
|
||||
}
|
||||
|
||||
// SET
|
||||
|
||||
@Override
|
||||
public void setTerritoryAccessAt(PS ps, TerritoryAccess territoryAccess)
|
||||
{
|
||||
ps = ps.getChunkCoords(true);
|
||||
|
||||
if (territoryAccess == null || (territoryAccess.getHostFactionId().equals(UConf.get(this).factionIdNone) && territoryAccess.isDefault()))
|
||||
{
|
||||
this.map.remove(ps);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.map.put(ps, territoryAccess);
|
||||
}
|
||||
|
||||
this.changed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFactionAt(PS ps, Faction faction)
|
||||
{
|
||||
TerritoryAccess territoryAccess = null;
|
||||
if (faction != null)
|
||||
{
|
||||
territoryAccess = TerritoryAccess.valueOf(faction.getId());
|
||||
}
|
||||
this.setTerritoryAccessAt(ps, territoryAccess);
|
||||
}
|
||||
|
||||
// REMOVE
|
||||
|
||||
@Override
|
||||
public void removeAt(PS ps)
|
||||
{
|
||||
this.setTerritoryAccessAt(ps, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAll(Faction faction)
|
||||
{
|
||||
String factionId = faction.getId();
|
||||
|
||||
for (Entry<PS, TerritoryAccess> entry : this.map.entrySet())
|
||||
{
|
||||
TerritoryAccess territoryAccess = entry.getValue();
|
||||
if ( ! territoryAccess.getHostFactionId().equals(factionId)) continue;
|
||||
|
||||
PS ps = entry.getKey();
|
||||
this.removeAt(ps);
|
||||
}
|
||||
}
|
||||
|
||||
// Removes orphaned foreign keys
|
||||
@Override
|
||||
public void clean()
|
||||
{
|
||||
FactionColl factionColl = FactionColls.get().get(this);
|
||||
|
||||
for (Entry<PS, TerritoryAccess> entry : this.map.entrySet())
|
||||
{
|
||||
TerritoryAccess territoryAccess = entry.getValue();
|
||||
String factionId = territoryAccess.getHostFactionId();
|
||||
if (factionColl.containsId(factionId)) continue;
|
||||
|
||||
PS ps = entry.getKey();
|
||||
this.removeAt(ps);
|
||||
|
||||
Factions.get().log("Board cleaner removed "+factionId+" from "+ps);
|
||||
}
|
||||
}
|
||||
|
||||
// CHUNKS
|
||||
|
||||
@Override
|
||||
public Set<PS> getChunks(Faction faction)
|
||||
{
|
||||
return this.getChunks(faction.getId());
|
||||
}
|
||||
|
||||
public Set<PS> getChunks(String factionId)
|
||||
{
|
||||
Set<PS> ret = new HashSet<PS>();
|
||||
for (Entry<PS, TerritoryAccess> entry : this.map.entrySet())
|
||||
{
|
||||
TerritoryAccess ta = entry.getValue();
|
||||
if (!ta.getHostFactionId().equals(factionId)) continue;
|
||||
|
||||
PS ps = entry.getKey();
|
||||
ps = ps.withWorld(this.getId());
|
||||
ret.add(ps);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// COUNT
|
||||
|
||||
@Override
|
||||
public int getCount(Faction faction)
|
||||
{
|
||||
return this.getCount(faction.getId());
|
||||
}
|
||||
|
||||
public int getCount(String factionId)
|
||||
{
|
||||
int ret = 0;
|
||||
for (TerritoryAccess ta : this.map.values())
|
||||
{
|
||||
if (!ta.getHostFactionId().equals(factionId)) continue;
|
||||
|
||||
ret += 1;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// NEARBY DETECTION
|
||||
|
||||
// Is this coord NOT completely surrounded by coords claimed by the same faction?
|
||||
// Simpler: Is there any nearby coord with a faction other than the faction here?
|
||||
@Override
|
||||
public boolean isBorderPs(PS ps)
|
||||
{
|
||||
ps = ps.getChunk(true);
|
||||
|
||||
PS nearby = null;
|
||||
Faction faction = this.getFactionAt(ps);
|
||||
|
||||
nearby = ps.withChunkX(ps.getChunkX() +1);
|
||||
if (faction != this.getFactionAt(nearby)) return true;
|
||||
|
||||
nearby = ps.withChunkX(ps.getChunkX() -1);
|
||||
if (faction != this.getFactionAt(nearby)) return true;
|
||||
|
||||
nearby = ps.withChunkZ(ps.getChunkZ() +1);
|
||||
if (faction != this.getFactionAt(nearby)) return true;
|
||||
|
||||
nearby = ps.withChunkZ(ps.getChunkZ() -1);
|
||||
if (faction != this.getFactionAt(nearby)) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Is this coord connected to any coord claimed by the specified faction?
|
||||
@Override
|
||||
public boolean isConnectedPs(PS ps, Faction faction)
|
||||
{
|
||||
ps = ps.getChunk(true);
|
||||
|
||||
PS nearby = null;
|
||||
|
||||
nearby = ps.withChunkX(ps.getChunkX() +1);
|
||||
if (faction == this.getFactionAt(nearby)) return true;
|
||||
|
||||
nearby = ps.withChunkX(ps.getChunkX() -1);
|
||||
if (faction == this.getFactionAt(nearby)) return true;
|
||||
|
||||
nearby = ps.withChunkZ(ps.getChunkZ() +1);
|
||||
if (faction == this.getFactionAt(nearby)) return true;
|
||||
|
||||
nearby = ps.withChunkZ(ps.getChunkZ() -1);
|
||||
if (faction == this.getFactionAt(nearby)) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// MAP GENERATION
|
||||
|
||||
@Override
|
||||
public ArrayList<String> getMap(RelationParticipator observer, PS centerPs, double inDegrees)
|
||||
{
|
||||
centerPs = centerPs.getChunkCoords(true);
|
||||
|
||||
ArrayList<String> ret = new ArrayList<String>();
|
||||
Faction centerFaction = this.getFactionAt(centerPs);
|
||||
|
||||
ret.add(Txt.titleize("("+centerPs.getChunkX() + "," + centerPs.getChunkZ()+") "+centerFaction.getName(observer)));
|
||||
|
||||
int halfWidth = Const.MAP_WIDTH / 2;
|
||||
int halfHeight = Const.MAP_HEIGHT / 2;
|
||||
|
||||
PS topLeftPs = centerPs.plusChunkCoords(-halfWidth, -halfHeight);
|
||||
|
||||
int width = halfWidth * 2 + 1;
|
||||
int height = halfHeight * 2 + 1;
|
||||
|
||||
// Make room for the list of names
|
||||
height--;
|
||||
|
||||
Map<Faction, Character> fList = new HashMap<Faction, Character>();
|
||||
int chrIdx = 0;
|
||||
|
||||
// For each row
|
||||
for (int dz = 0; dz < height; dz++)
|
||||
{
|
||||
// Draw and add that row
|
||||
String row = "";
|
||||
for (int dx = 0; dx < width; dx++)
|
||||
{
|
||||
if(dx == halfWidth && dz == halfHeight)
|
||||
{
|
||||
row += ChatColor.AQUA+"+";
|
||||
continue;
|
||||
}
|
||||
|
||||
PS herePs = topLeftPs.plusChunkCoords(dx, dz);
|
||||
Faction hereFaction = this.getFactionAt(herePs);
|
||||
if (hereFaction.isNone())
|
||||
{
|
||||
row += ChatColor.GRAY+"-";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!fList.containsKey(hereFaction))
|
||||
fList.put(hereFaction, Const.MAP_KEY_CHARS[chrIdx++]);
|
||||
char fchar = fList.get(hereFaction);
|
||||
row += hereFaction.getColorTo(observer) + "" + fchar;
|
||||
}
|
||||
}
|
||||
ret.add(row);
|
||||
}
|
||||
|
||||
// Get the compass
|
||||
ArrayList<String> asciiCompass = AsciiCompass.getAsciiCompass(inDegrees, ChatColor.RED, Txt.parse("<a>"));
|
||||
|
||||
// Add the compass
|
||||
ret.set(1, asciiCompass.get(0)+ret.get(1).substring(3*3));
|
||||
ret.set(2, asciiCompass.get(1)+ret.get(2).substring(3*3));
|
||||
ret.set(3, asciiCompass.get(2)+ret.get(3).substring(3*3));
|
||||
|
||||
String fRow = "";
|
||||
for (Faction keyfaction : fList.keySet())
|
||||
{
|
||||
fRow += ""+keyfaction.getColorTo(observer) + fList.get(keyfaction) + ": " + keyfaction.getName() + " ";
|
||||
}
|
||||
fRow = fRow.trim();
|
||||
ret.add(fRow);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
@ -1,168 +0,0 @@
|
||||
package com.massivecraft.factions.entity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.RelationParticipator;
|
||||
import com.massivecraft.factions.TerritoryAccess;
|
||||
import com.massivecraft.massivecore.ps.PS;
|
||||
import com.massivecraft.massivecore.store.Coll;
|
||||
import com.massivecraft.massivecore.store.MStore;
|
||||
import com.massivecraft.massivecore.util.MUtil;
|
||||
|
||||
public class BoardColl extends Coll<Board> implements BoardInterface
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public BoardColl(String name)
|
||||
{
|
||||
super(name, Board.class, MStore.getDb(), Factions.get(), false, true, true);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE: COLL
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public String fixId(Object oid)
|
||||
{
|
||||
if (oid == null) return null;
|
||||
if (oid instanceof String) return (String)oid;
|
||||
if (oid instanceof Board) return this.getId(oid);
|
||||
|
||||
return MUtil.extract(String.class, "worldName", oid);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE: BOARD
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public TerritoryAccess getTerritoryAccessAt(PS ps)
|
||||
{
|
||||
if (ps == null) return null;
|
||||
Board board = this.get(ps.getWorld());
|
||||
if (board == null) return null;
|
||||
return board.getTerritoryAccessAt(ps);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Faction getFactionAt(PS ps)
|
||||
{
|
||||
if (ps == null) return null;
|
||||
Board board = this.get(ps.getWorld());
|
||||
if (board == null) return null;
|
||||
return board.getFactionAt(ps);
|
||||
}
|
||||
|
||||
// SET
|
||||
|
||||
@Override
|
||||
public void setTerritoryAccessAt(PS ps, TerritoryAccess territoryAccess)
|
||||
{
|
||||
if (ps == null) return;
|
||||
Board board = this.get(ps.getWorld());
|
||||
if (board == null) return;
|
||||
board.setTerritoryAccessAt(ps, territoryAccess);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFactionAt(PS ps, Faction faction)
|
||||
{
|
||||
if (ps == null) return;
|
||||
Board board = this.get(ps.getWorld());
|
||||
if (board == null) return;
|
||||
board.setFactionAt(ps, faction);
|
||||
}
|
||||
|
||||
// REMOVE
|
||||
|
||||
@Override
|
||||
public void removeAt(PS ps)
|
||||
{
|
||||
if (ps == null) return;
|
||||
Board board = this.get(ps.getWorld());
|
||||
if (board == null) return;
|
||||
board.removeAt(ps);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAll(Faction faction)
|
||||
{
|
||||
for (Board board : this.getAll())
|
||||
{
|
||||
board.removeAll(faction);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clean()
|
||||
{
|
||||
for (Board board : this.getAll())
|
||||
{
|
||||
board.clean();
|
||||
}
|
||||
}
|
||||
|
||||
// CHUNKS
|
||||
|
||||
@Override
|
||||
public Set<PS> getChunks(Faction faction)
|
||||
{
|
||||
Set<PS> ret = new HashSet<PS>();
|
||||
for (Board board : this.getAll())
|
||||
{
|
||||
ret.addAll(board.getChunks(faction));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// COUNT
|
||||
|
||||
@Override
|
||||
public int getCount(Faction faction)
|
||||
{
|
||||
int ret = 0;
|
||||
for (Board board : this.getAll())
|
||||
{
|
||||
ret += board.getCount(faction);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// NEARBY DETECTION
|
||||
|
||||
@Override
|
||||
public boolean isBorderPs(PS ps)
|
||||
{
|
||||
if (ps == null) return false;
|
||||
Board board = this.get(ps.getWorld());
|
||||
if (board == null) return false;
|
||||
return board.isBorderPs(ps);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConnectedPs(PS ps, Faction faction)
|
||||
{
|
||||
if (ps == null) return false;
|
||||
Board board = this.get(ps.getWorld());
|
||||
if (board == null) return false;
|
||||
return board.isConnectedPs(ps, faction);
|
||||
}
|
||||
|
||||
// MAP GENERATION
|
||||
|
||||
@Override
|
||||
public ArrayList<String> getMap(RelationParticipator observer, PS centerPs, double inDegrees)
|
||||
{
|
||||
if (centerPs == null) return null;
|
||||
Board board = this.get(centerPs.getWorld());
|
||||
if (board == null) return null;
|
||||
return board.getMap(observer, centerPs, inDegrees);
|
||||
}
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user