No More ZCore
This commit is contained in:
parent
e874ea60df
commit
97a2ed1fd8
@ -155,7 +155,7 @@ public enum FPerm
|
|||||||
// TODO: Create better description messages like: "You must at least be officer".
|
// TODO: Create better description messages like: "You must at least be officer".
|
||||||
boolean ret = hostFaction.getPermittedRelations(this).contains(rel);
|
boolean ret = hostFaction.getPermittedRelations(this).contains(rel);
|
||||||
|
|
||||||
if (rpSubject instanceof FPlayer && ret == false && ((FPlayer)rpSubject).hasAdminMode()) ret = true;
|
if (rpSubject instanceof FPlayer && ret == false && ((FPlayer)rpSubject).isUsingAdminMode()) ret = true;
|
||||||
|
|
||||||
if (!ret && informIfNot && rpSubject instanceof FPlayer)
|
if (!ret && informIfNot && rpSubject instanceof FPlayer)
|
||||||
{
|
{
|
||||||
@ -163,7 +163,7 @@ public enum FPerm
|
|||||||
fplayer.msg(errorpattern, hostFaction.describeTo(fplayer, true), this.getDescription());
|
fplayer.msg(errorpattern, hostFaction.describeTo(fplayer, true), this.getDescription());
|
||||||
if (Perm.ADMIN.has(fplayer.getPlayer()))
|
if (Perm.ADMIN.has(fplayer.getPlayer()))
|
||||||
{
|
{
|
||||||
fplayer.msg("<i>You can bypass by using " + Factions.get().cmdBase.cmdFactionsAdmin.getUseageTemplate(false));
|
fplayer.msg("<i>You can bypass by using " + Factions.get().getOuterCmdFactions().cmdFactionsAdmin.getUseageTemplate(false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -123,9 +123,9 @@ public class FPlayer extends SenderEntity<FPlayer> implements EconomyParticipato
|
|||||||
public Faction getAutoClaimFor() { return autoClaimFor; }
|
public Faction getAutoClaimFor() { return autoClaimFor; }
|
||||||
public void setAutoClaimFor(Faction faction) { this.autoClaimFor = faction; }
|
public void setAutoClaimFor(Faction faction) { this.autoClaimFor = faction; }
|
||||||
|
|
||||||
private transient boolean hasAdminMode = false;
|
private transient boolean usingAdminMode = false;
|
||||||
public boolean hasAdminMode() { return this.hasAdminMode; }
|
public boolean isUsingAdminMode() { return this.usingAdminMode; }
|
||||||
public void setHasAdminMode(boolean val) { this.hasAdminMode = val; }
|
public void setUsingAdminMode(boolean val) { this.usingAdminMode = val; }
|
||||||
|
|
||||||
// FIELD: loginPvpDisabled
|
// FIELD: loginPvpDisabled
|
||||||
private transient boolean loginPvpDisabled;
|
private transient boolean loginPvpDisabled;
|
||||||
@ -490,7 +490,7 @@ public class FPlayer extends SenderEntity<FPlayer> implements EconomyParticipato
|
|||||||
public void leave(boolean makePay)
|
public void leave(boolean makePay)
|
||||||
{
|
{
|
||||||
Faction myFaction = this.getFaction();
|
Faction myFaction = this.getFaction();
|
||||||
makePay = makePay && Econ.shouldBeUsed() && ! this.hasAdminMode();
|
makePay = makePay && Econ.shouldBeUsed() && ! this.isUsingAdminMode();
|
||||||
|
|
||||||
if (myFaction == null)
|
if (myFaction == null)
|
||||||
{
|
{
|
||||||
@ -575,7 +575,7 @@ public class FPlayer extends SenderEntity<FPlayer> implements EconomyParticipato
|
|||||||
{
|
{
|
||||||
error = Txt.parse("<b>Sorry, this world has land claiming disabled.");
|
error = Txt.parse("<b>Sorry, this world has land claiming disabled.");
|
||||||
}
|
}
|
||||||
else if (this.hasAdminMode())
|
else if (this.isUsingAdminMode())
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -610,7 +610,7 @@ public class FPlayer extends SenderEntity<FPlayer> implements EconomyParticipato
|
|||||||
else if
|
else if
|
||||||
(
|
(
|
||||||
ConfServer.claimsMustBeConnected
|
ConfServer.claimsMustBeConnected
|
||||||
&& ! this.hasAdminMode()
|
&& ! this.isUsingAdminMode()
|
||||||
&& myFaction.getLandRoundedInWorld(ps.getWorld()) > 0
|
&& myFaction.getLandRoundedInWorld(ps.getWorld()) > 0
|
||||||
&& !BoardColl.get().isConnectedPs(ps, myFaction)
|
&& !BoardColl.get().isConnectedPs(ps, myFaction)
|
||||||
&& (!ConfServer.claimsCanBeUnconnectedIfOwnedByOtherFaction || !currentFaction.isNormal())
|
&& (!ConfServer.claimsCanBeUnconnectedIfOwnedByOtherFaction || !currentFaction.isNormal())
|
||||||
@ -655,7 +655,7 @@ public class FPlayer extends SenderEntity<FPlayer> implements EconomyParticipato
|
|||||||
|
|
||||||
// TODO: Add flag no costs??
|
// TODO: Add flag no costs??
|
||||||
// if economy is enabled and they're not on the bypass list, make sure they can pay
|
// if economy is enabled and they're not on the bypass list, make sure they can pay
|
||||||
boolean mustPay = Econ.shouldBeUsed() && ! this.hasAdminMode();
|
boolean mustPay = Econ.shouldBeUsed() && ! this.isUsingAdminMode();
|
||||||
double cost = 0.0;
|
double cost = 0.0;
|
||||||
EconomyParticipator payee = null;
|
EconomyParticipator payee = null;
|
||||||
if (mustPay)
|
if (mustPay)
|
||||||
|
@ -1,9 +1,5 @@
|
|||||||
package com.massivecraft.factions;
|
package com.massivecraft.factions;
|
||||||
|
|
||||||
import java.lang.reflect.Modifier;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
import com.massivecraft.factions.adapters.BoardAdapter;
|
import com.massivecraft.factions.adapters.BoardAdapter;
|
||||||
import com.massivecraft.factions.adapters.BoardMapAdapter;
|
import com.massivecraft.factions.adapters.BoardMapAdapter;
|
||||||
import com.massivecraft.factions.adapters.FFlagAdapter;
|
import com.massivecraft.factions.adapters.FFlagAdapter;
|
||||||
@ -26,11 +22,8 @@ import com.massivecraft.factions.listeners.FactionsPlayerListener;
|
|||||||
import com.massivecraft.factions.util.AutoLeaveTask;
|
import com.massivecraft.factions.util.AutoLeaveTask;
|
||||||
import com.massivecraft.factions.util.EconLandRewardTask;
|
import com.massivecraft.factions.util.EconLandRewardTask;
|
||||||
import com.massivecraft.factions.util.LazyLocation;
|
import com.massivecraft.factions.util.LazyLocation;
|
||||||
import com.massivecraft.factions.zcore.MPlugin;
|
|
||||||
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
|
import com.massivecraft.mcore.MPlugin;
|
||||||
import com.massivecraft.mcore.xlib.gson.GsonBuilder;
|
import com.massivecraft.mcore.xlib.gson.GsonBuilder;
|
||||||
|
|
||||||
|
|
||||||
@ -48,6 +41,10 @@ public class Factions extends MPlugin
|
|||||||
// FIELDS
|
// FIELDS
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
// Commands
|
||||||
|
private CmdFactions outerCmdFactions;
|
||||||
|
public CmdFactions getOuterCmdFactions() { return this.outerCmdFactions; }
|
||||||
|
|
||||||
// Listeners
|
// Listeners
|
||||||
public FactionsPlayerListener playerListener;
|
public FactionsPlayerListener playerListener;
|
||||||
public FactionsChatListener chatListener;
|
public FactionsChatListener chatListener;
|
||||||
@ -58,10 +55,6 @@ public class Factions extends MPlugin
|
|||||||
// Task Ids
|
// Task Ids
|
||||||
private Integer AutoLeaveTask = null;
|
private Integer AutoLeaveTask = null;
|
||||||
private Integer econLandRewardTaskID = null;
|
private Integer econLandRewardTaskID = null;
|
||||||
|
|
||||||
// Commands
|
|
||||||
public CmdFactions cmdBase;
|
|
||||||
public CmdFactionsAutoHelp cmdAutoHelp;
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// OVERRIDE
|
// OVERRIDE
|
||||||
@ -75,14 +68,14 @@ public class Factions extends MPlugin
|
|||||||
// Load Server Config
|
// Load Server Config
|
||||||
ConfServer.get().load();
|
ConfServer.get().load();
|
||||||
|
|
||||||
// Load Conf from disk
|
// Initialize Collections
|
||||||
FPlayerColl.get().init();
|
FPlayerColl.get().init();
|
||||||
FactionColl.get().init();
|
FactionColl.get().init();
|
||||||
BoardColl.get().init();
|
BoardColl.get().init();
|
||||||
|
|
||||||
// Add Base Commands
|
// Commands
|
||||||
this.cmdAutoHelp = new CmdFactionsAutoHelp();
|
this.outerCmdFactions = new CmdFactions();
|
||||||
this.cmdBase = new CmdFactions();
|
this.outerCmdFactions.register(this);
|
||||||
|
|
||||||
EssentialsFeatures.setup();
|
EssentialsFeatures.setup();
|
||||||
SpoutFeatures.setup();
|
SpoutFeatures.setup();
|
||||||
@ -125,17 +118,15 @@ public class Factions extends MPlugin
|
|||||||
@Override
|
@Override
|
||||||
public GsonBuilder getGsonBuilder()
|
public GsonBuilder getGsonBuilder()
|
||||||
{
|
{
|
||||||
return new GsonBuilder()
|
return super.getGsonBuilder()
|
||||||
.setPrettyPrinting()
|
|
||||||
.disableHtmlEscaping()
|
|
||||||
.excludeFieldsWithModifiers(Modifier.TRANSIENT, Modifier.VOLATILE)
|
|
||||||
.registerTypeAdapter(LazyLocation.class, new LazyLocationAdapter())
|
.registerTypeAdapter(LazyLocation.class, new LazyLocationAdapter())
|
||||||
.registerTypeAdapter(TerritoryAccess.class, TerritoryAccessAdapter.get())
|
.registerTypeAdapter(TerritoryAccess.class, TerritoryAccessAdapter.get())
|
||||||
.registerTypeAdapter(Board.class, BoardAdapter.get())
|
.registerTypeAdapter(Board.class, BoardAdapter.get())
|
||||||
.registerTypeAdapter(Board.MAP_TYPE, BoardMapAdapter.get())
|
.registerTypeAdapter(Board.MAP_TYPE, BoardMapAdapter.get())
|
||||||
.registerTypeAdapter(Rel.class, new RelAdapter())
|
.registerTypeAdapter(Rel.class, new RelAdapter())
|
||||||
.registerTypeAdapter(FPerm.class, new FPermAdapter())
|
.registerTypeAdapter(FPerm.class, new FPermAdapter())
|
||||||
.registerTypeAdapter(FFlag.class, new FFlagAdapter());
|
.registerTypeAdapter(FFlag.class, new FFlagAdapter())
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -186,13 +177,6 @@ public class Factions extends MPlugin
|
|||||||
econLandRewardTaskID = getServer().getScheduler().scheduleSyncRepeatingTask(this, new EconLandRewardTask(), ticks, ticks);
|
econLandRewardTaskID = getServer().getScheduler().scheduleSyncRepeatingTask(this, new EconLandRewardTask(), ticks, ticks);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] split)
|
|
||||||
{
|
|
||||||
this.cmdBase.execute(sender, new ArrayList<String>(Arrays.asList(split)));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// Functions for other plugins to hook into
|
// Functions for other plugins to hook into
|
||||||
|
@ -2,6 +2,7 @@ package com.massivecraft.factions.cmd;
|
|||||||
|
|
||||||
import com.massivecraft.factions.Factions;
|
import com.massivecraft.factions.Factions;
|
||||||
import com.massivecraft.factions.Perm;
|
import com.massivecraft.factions.Perm;
|
||||||
|
import com.massivecraft.mcore.cmd.arg.ARBoolean;
|
||||||
import com.massivecraft.mcore.cmd.req.ReqHasPerm;
|
import com.massivecraft.mcore.cmd.req.ReqHasPerm;
|
||||||
|
|
||||||
public class CmdFactionsAdmin extends FCommand
|
public class CmdFactionsAdmin extends FCommand
|
||||||
@ -18,9 +19,12 @@ public class CmdFactionsAdmin extends FCommand
|
|||||||
@Override
|
@Override
|
||||||
public void perform()
|
public void perform()
|
||||||
{
|
{
|
||||||
fme.setHasAdminMode(this.argAsBool(0, ! fme.hasAdminMode()));
|
Boolean target = this.arg(0, ARBoolean.get(), !fme.isUsingAdminMode());
|
||||||
|
if (target == null) return;
|
||||||
|
|
||||||
if ( fme.hasAdminMode())
|
fme.setUsingAdminMode(target);
|
||||||
|
|
||||||
|
if ( fme.isUsingAdminMode())
|
||||||
{
|
{
|
||||||
fme.msg("<i>You have enabled admin bypass mode.");
|
fme.msg("<i>You have enabled admin bypass mode.");
|
||||||
Factions.get().log(fme.getName() + " has ENABLED admin bypass mode.");
|
Factions.get().log(fme.getName() + " has ENABLED admin bypass mode.");
|
||||||
|
@ -3,6 +3,7 @@ package com.massivecraft.factions.cmd;
|
|||||||
import com.massivecraft.factions.FPerm;
|
import com.massivecraft.factions.FPerm;
|
||||||
import com.massivecraft.factions.Faction;
|
import com.massivecraft.factions.Faction;
|
||||||
import com.massivecraft.factions.Perm;
|
import com.massivecraft.factions.Perm;
|
||||||
|
import com.massivecraft.factions.cmd.arg.ARFaction;
|
||||||
import com.massivecraft.mcore.cmd.req.ReqHasPerm;
|
import com.massivecraft.mcore.cmd.req.ReqHasPerm;
|
||||||
import com.massivecraft.mcore.cmd.req.ReqIsPlayer;
|
import com.massivecraft.mcore.cmd.req.ReqIsPlayer;
|
||||||
|
|
||||||
@ -21,7 +22,7 @@ public class CmdFactionsAutoClaim extends FCommand
|
|||||||
@Override
|
@Override
|
||||||
public void perform()
|
public void perform()
|
||||||
{
|
{
|
||||||
Faction forFaction = this.argAsFaction(0, myFaction);
|
Faction forFaction = this.arg(0, ARFaction.get(), myFaction);
|
||||||
if (forFaction == null || forFaction == fme.getAutoClaimFor())
|
if (forFaction == null || forFaction == fme.getAutoClaimFor())
|
||||||
{
|
{
|
||||||
fme.setAutoClaimFor(null);
|
fme.setAutoClaimFor(null);
|
||||||
|
@ -28,7 +28,7 @@ public class CmdFactionsClaim extends FCommand
|
|||||||
@Override
|
@Override
|
||||||
public void perform()
|
public void perform()
|
||||||
{
|
{
|
||||||
Faction forFaction = this.arg(0, ARFaction.get());
|
final Faction forFaction = this.arg(0, ARFaction.get());
|
||||||
if (forFaction == null) return;
|
if (forFaction == null) return;
|
||||||
|
|
||||||
Integer radius = this.arg(1, ARInteger.get(), 1);
|
Integer radius = this.arg(1, ARInteger.get(), 1);
|
||||||
|
@ -15,7 +15,6 @@ import com.massivecraft.factions.Rel;
|
|||||||
import com.massivecraft.factions.event.FPlayerJoinEvent;
|
import com.massivecraft.factions.event.FPlayerJoinEvent;
|
||||||
import com.massivecraft.factions.event.FactionCreateEvent;
|
import com.massivecraft.factions.event.FactionCreateEvent;
|
||||||
import com.massivecraft.mcore.cmd.req.ReqHasPerm;
|
import com.massivecraft.mcore.cmd.req.ReqHasPerm;
|
||||||
import com.massivecraft.mcore.cmd.req.ReqIsPlayer;
|
|
||||||
|
|
||||||
public class CmdFactionsCreate extends FCommand
|
public class CmdFactionsCreate extends FCommand
|
||||||
{
|
{
|
||||||
@ -91,7 +90,7 @@ public class CmdFactionsCreate extends FCommand
|
|||||||
follower.msg("%s<i> created a new faction %s", fme.describeTo(follower, true), faction.getTag(follower));
|
follower.msg("%s<i> created a new faction %s", fme.describeTo(follower, true), faction.getTag(follower));
|
||||||
}
|
}
|
||||||
|
|
||||||
msg("<i>You should now: %s", p.cmdBase.cmdFactionsDescription.getUseageTemplate());
|
msg("<i>You should now: %s", Factions.get().getOuterCmdFactions().cmdFactionsDescription.getUseageTemplate());
|
||||||
|
|
||||||
if (ConfServer.logFactionCreate)
|
if (ConfServer.logFactionCreate)
|
||||||
Factions.get().log(fme.getName()+" created a new faction: "+tag);
|
Factions.get().log(fme.getName()+" created a new faction: "+tag);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.massivecraft.factions.cmd;
|
package com.massivecraft.factions.cmd;
|
||||||
|
|
||||||
import com.massivecraft.factions.FPlayer;
|
import com.massivecraft.factions.FPlayer;
|
||||||
|
import com.massivecraft.factions.Factions;
|
||||||
import com.massivecraft.factions.Perm;
|
import com.massivecraft.factions.Perm;
|
||||||
import com.massivecraft.factions.cmd.arg.ARFPlayer;
|
import com.massivecraft.factions.cmd.arg.ARFPlayer;
|
||||||
import com.massivecraft.mcore.cmd.req.ReqHasPerm;
|
import com.massivecraft.mcore.cmd.req.ReqHasPerm;
|
||||||
@ -31,7 +32,7 @@ public class CmdFactionsDeinvite extends FCommand
|
|||||||
if (you.getFaction() == myFaction)
|
if (you.getFaction() == myFaction)
|
||||||
{
|
{
|
||||||
msg("%s<i> is already a member of %s", you.getName(), myFaction.getTag());
|
msg("%s<i> is already a member of %s", you.getName(), myFaction.getTag());
|
||||||
msg("<i>You might want to: %s", p.cmdBase.cmdFactionsKick.getUseageTemplate(false));
|
msg("<i>You might want to: %s", Factions.get().getOuterCmdFactions().cmdFactionsKick.getUseageTemplate(false));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,9 @@ package com.massivecraft.factions.cmd;
|
|||||||
import com.massivecraft.factions.FFlag;
|
import com.massivecraft.factions.FFlag;
|
||||||
import com.massivecraft.factions.Faction;
|
import com.massivecraft.factions.Faction;
|
||||||
import com.massivecraft.factions.Perm;
|
import com.massivecraft.factions.Perm;
|
||||||
|
import com.massivecraft.factions.cmd.arg.ARFFlag;
|
||||||
import com.massivecraft.factions.cmd.arg.ARFaction;
|
import com.massivecraft.factions.cmd.arg.ARFaction;
|
||||||
|
import com.massivecraft.mcore.cmd.arg.ARBoolean;
|
||||||
import com.massivecraft.mcore.cmd.req.ReqHasPerm;
|
import com.massivecraft.mcore.cmd.req.ReqHasPerm;
|
||||||
import com.massivecraft.mcore.util.Txt;
|
import com.massivecraft.mcore.util.Txt;
|
||||||
|
|
||||||
@ -37,8 +39,9 @@ public class CmdFactionsFlag extends FCommand
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
FFlag flag = this.argAsFactionFlag(1);
|
FFlag flag = this.arg(1, ARFFlag.get());
|
||||||
if (flag == null) return;
|
if (flag == null) return;
|
||||||
|
|
||||||
if ( ! this.argIsSet(2))
|
if ( ! this.argIsSet(2))
|
||||||
{
|
{
|
||||||
msg(Txt.titleize("Flag for " + faction.describeTo(fme, true)));
|
msg(Txt.titleize("Flag for " + faction.describeTo(fme, true)));
|
||||||
@ -46,7 +49,7 @@ public class CmdFactionsFlag extends FCommand
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Boolean targetValue = this.argAsBool(2);
|
Boolean targetValue = this.arg(2, ARBoolean.get());
|
||||||
if (targetValue == null) return;
|
if (targetValue == null) return;
|
||||||
|
|
||||||
// Do the sender have the right to change flags?
|
// Do the sender have the right to change flags?
|
||||||
|
@ -13,6 +13,7 @@ import com.massivecraft.factions.FFlag;
|
|||||||
import com.massivecraft.factions.FPlayer;
|
import com.massivecraft.factions.FPlayer;
|
||||||
import com.massivecraft.factions.FPlayerColl;
|
import com.massivecraft.factions.FPlayerColl;
|
||||||
import com.massivecraft.factions.Faction;
|
import com.massivecraft.factions.Faction;
|
||||||
|
import com.massivecraft.factions.Factions;
|
||||||
import com.massivecraft.factions.Perm;
|
import com.massivecraft.factions.Perm;
|
||||||
import com.massivecraft.factions.Rel;
|
import com.massivecraft.factions.Rel;
|
||||||
import com.massivecraft.factions.integration.EssentialsFeatures;
|
import com.massivecraft.factions.integration.EssentialsFeatures;
|
||||||
@ -53,7 +54,7 @@ public class CmdFactionsHome extends FCommand
|
|||||||
if ( ! myFaction.hasHome())
|
if ( ! myFaction.hasHome())
|
||||||
{
|
{
|
||||||
fme.msg("<b>Your faction does not have a home. " + (fme.getRole().isLessThan(Rel.OFFICER) ? "<i> Ask your leader to:" : "<i>You should:"));
|
fme.msg("<b>Your faction does not have a home. " + (fme.getRole().isLessThan(Rel.OFFICER) ? "<i> Ask your leader to:" : "<i>You should:"));
|
||||||
fme.sendMessage(p.cmdBase.cmdFactionsSethome.getUseageTemplate());
|
fme.sendMessage(Factions.get().getOuterCmdFactions().cmdFactionsSethome.getUseageTemplate());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ import com.massivecraft.factions.ConfServer;
|
|||||||
import com.massivecraft.factions.FPerm;
|
import com.massivecraft.factions.FPerm;
|
||||||
import com.massivecraft.factions.FPlayer;
|
import com.massivecraft.factions.FPlayer;
|
||||||
import com.massivecraft.factions.Faction;
|
import com.massivecraft.factions.Faction;
|
||||||
|
import com.massivecraft.factions.Factions;
|
||||||
import com.massivecraft.factions.Perm;
|
import com.massivecraft.factions.Perm;
|
||||||
import com.massivecraft.factions.cmd.arg.ARFPlayer;
|
import com.massivecraft.factions.cmd.arg.ARFPlayer;
|
||||||
import com.massivecraft.factions.cmd.arg.ARFaction;
|
import com.massivecraft.factions.cmd.arg.ARFaction;
|
||||||
@ -33,7 +34,7 @@ public class CmdFactionsInvite extends FCommand
|
|||||||
if (you.getFaction() == myFaction)
|
if (you.getFaction() == myFaction)
|
||||||
{
|
{
|
||||||
msg("%s<i> is already a member of %s", you.getName(), myFaction.getTag());
|
msg("%s<i> is already a member of %s", you.getName(), myFaction.getTag());
|
||||||
msg("<i>You might want to: " + p.cmdBase.cmdFactionsKick.getUseageTemplate(false));
|
msg("<i>You might want to: " + Factions.get().getOuterCmdFactions().cmdFactionsKick.getUseageTemplate(false));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ public class CmdFactionsJoin extends FCommand
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ! (faction.isOpen() || faction.isInvited(fplayer) || fme.hasAdminMode() || Perm.JOIN_ANY.has(sender, false)))
|
if( ! (faction.isOpen() || faction.isInvited(fplayer) || fme.isUsingAdminMode() || Perm.JOIN_ANY.has(sender, false)))
|
||||||
{
|
{
|
||||||
msg("<i>This faction requires invitation.");
|
msg("<i>This faction requires invitation.");
|
||||||
if (samePlayer)
|
if (samePlayer)
|
||||||
|
@ -34,11 +34,11 @@ public class CmdFactionsKick extends FCommand
|
|||||||
if (fme == you)
|
if (fme == you)
|
||||||
{
|
{
|
||||||
msg("<b>You cannot kick yourself.");
|
msg("<b>You cannot kick yourself.");
|
||||||
msg("<i>You might want to: %s", p.cmdBase.cmdFactionsLeave.getUseageTemplate(false));
|
msg("<i>You might want to: %s", Factions.get().getOuterCmdFactions().cmdFactionsLeave.getUseageTemplate(false));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (you.getRole() == Rel.LEADER && !(this.senderIsConsole || fme.hasAdminMode()))
|
if (you.getRole() == Rel.LEADER && !(this.senderIsConsole || fme.isUsingAdminMode()))
|
||||||
{
|
{
|
||||||
msg("<b>The leader can not be kicked.");
|
msg("<b>The leader can not be kicked.");
|
||||||
return;
|
return;
|
||||||
|
@ -38,7 +38,7 @@ public class CmdFactionsLeader extends FCommand
|
|||||||
FPlayer targetFactionCurrentLeader = targetFaction.getFPlayerLeader();
|
FPlayer targetFactionCurrentLeader = targetFaction.getFPlayerLeader();
|
||||||
|
|
||||||
// We now have fplayer and the target faction
|
// We now have fplayer and the target faction
|
||||||
if (this.senderIsConsole || fme.hasAdminMode() || Perm.LEADER_ANY.has(sender, false))
|
if (this.senderIsConsole || fme.isUsingAdminMode() || Perm.LEADER_ANY.has(sender, false))
|
||||||
{
|
{
|
||||||
// Do whatever you wish
|
// Do whatever you wish
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package com.massivecraft.factions.cmd;
|
|||||||
import com.massivecraft.factions.BoardColl;
|
import com.massivecraft.factions.BoardColl;
|
||||||
import com.massivecraft.factions.ConfServer;
|
import com.massivecraft.factions.ConfServer;
|
||||||
import com.massivecraft.factions.Perm;
|
import com.massivecraft.factions.Perm;
|
||||||
|
import com.massivecraft.mcore.cmd.arg.ARBoolean;
|
||||||
import com.massivecraft.mcore.cmd.req.ReqHasPerm;
|
import com.massivecraft.mcore.cmd.req.ReqHasPerm;
|
||||||
import com.massivecraft.mcore.cmd.req.ReqIsPlayer;
|
import com.massivecraft.mcore.cmd.req.ReqIsPlayer;
|
||||||
import com.massivecraft.mcore.ps.PS;
|
import com.massivecraft.mcore.ps.PS;
|
||||||
@ -23,34 +24,33 @@ public class CmdFactionsMap extends FCommand
|
|||||||
@Override
|
@Override
|
||||||
public void perform()
|
public void perform()
|
||||||
{
|
{
|
||||||
if (this.argIsSet(0))
|
if (!this.argIsSet(0))
|
||||||
{
|
|
||||||
if (this.argAsBool(0, ! fme.isMapAutoUpdating()))
|
|
||||||
{
|
|
||||||
// Turn on
|
|
||||||
|
|
||||||
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
|
|
||||||
if ( ! payForCommand(ConfServer.econCostMap, "to show the map", "for showing the map")) return;
|
|
||||||
|
|
||||||
fme.setMapAutoUpdating(true);
|
|
||||||
msg("<i>Map auto update <green>ENABLED.");
|
|
||||||
|
|
||||||
// And show the map once
|
|
||||||
showMap();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Turn off
|
|
||||||
fme.setMapAutoUpdating(false);
|
|
||||||
msg("<i>Map auto update <red>DISABLED.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
|
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
|
||||||
if ( ! payForCommand(ConfServer.econCostMap, "to show the map", "for showing the map")) return;
|
if ( ! payForCommand(ConfServer.econCostMap, "to show the map", "for showing the map")) return;
|
||||||
|
|
||||||
showMap();
|
showMap();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.arg(0, ARBoolean.get(), !fme.isMapAutoUpdating()))
|
||||||
|
{
|
||||||
|
// Turn on
|
||||||
|
|
||||||
|
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
|
||||||
|
if ( ! payForCommand(ConfServer.econCostMap, "to show the map", "for showing the map")) return;
|
||||||
|
|
||||||
|
fme.setMapAutoUpdating(true);
|
||||||
|
msg("<i>Map auto update <green>ENABLED.");
|
||||||
|
|
||||||
|
// And show the map once
|
||||||
|
showMap();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Turn off
|
||||||
|
fme.setMapAutoUpdating(false);
|
||||||
|
msg("<i>Map auto update <red>DISABLED.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,10 @@ import com.massivecraft.factions.FPerm;
|
|||||||
import com.massivecraft.factions.Faction;
|
import com.massivecraft.factions.Faction;
|
||||||
import com.massivecraft.factions.Perm;
|
import com.massivecraft.factions.Perm;
|
||||||
import com.massivecraft.factions.Rel;
|
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.ARFaction;
|
||||||
|
import com.massivecraft.factions.cmd.arg.ARRel;
|
||||||
|
import com.massivecraft.mcore.cmd.arg.ARBoolean;
|
||||||
import com.massivecraft.mcore.cmd.req.ReqHasPerm;
|
import com.massivecraft.mcore.cmd.req.ReqHasPerm;
|
||||||
import com.massivecraft.mcore.util.Txt;
|
import com.massivecraft.mcore.util.Txt;
|
||||||
|
|
||||||
@ -40,8 +43,9 @@ public class CmdFactionsPerm extends FCommand
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
FPerm perm = this.argAsFactionPerm(1);
|
FPerm perm = this.arg(1, ARFPerm.get());
|
||||||
if (perm == null) return;
|
if (perm == null) return;
|
||||||
|
|
||||||
if ( ! this.argIsSet(2))
|
if ( ! this.argIsSet(2))
|
||||||
{
|
{
|
||||||
msg(Txt.titleize("Perm for " + faction.describeTo(fme, true)));
|
msg(Txt.titleize("Perm for " + faction.describeTo(fme, true)));
|
||||||
@ -53,10 +57,10 @@ public class CmdFactionsPerm extends FCommand
|
|||||||
// Do the sender have the right to change perms for this faction?
|
// Do the sender have the right to change perms for this faction?
|
||||||
if ( ! FPerm.PERMS.has(sender, faction, true)) return;
|
if ( ! FPerm.PERMS.has(sender, faction, true)) return;
|
||||||
|
|
||||||
Rel rel = this.argAsRel(2);
|
Rel rel = this.arg(2, ARRel.get());
|
||||||
if (rel == null) return;
|
if (rel == null) return;
|
||||||
|
|
||||||
Boolean val = this.argAsBool(3, null);
|
Boolean val = this.arg(3, ARBoolean.get(), null);
|
||||||
if (val == null) return;
|
if (val == null) return;
|
||||||
|
|
||||||
// Do the change
|
// Do the change
|
||||||
|
@ -4,6 +4,9 @@ import com.massivecraft.factions.Faction;
|
|||||||
import com.massivecraft.factions.FPlayer;
|
import com.massivecraft.factions.FPlayer;
|
||||||
import com.massivecraft.factions.Factions;
|
import com.massivecraft.factions.Factions;
|
||||||
import com.massivecraft.factions.Perm;
|
import com.massivecraft.factions.Perm;
|
||||||
|
import com.massivecraft.factions.cmd.arg.ARFPlayer;
|
||||||
|
import com.massivecraft.factions.cmd.arg.ARFaction;
|
||||||
|
import com.massivecraft.mcore.cmd.arg.ARDouble;
|
||||||
import com.massivecraft.mcore.cmd.req.ReqHasPerm;
|
import com.massivecraft.mcore.cmd.req.ReqHasPerm;
|
||||||
|
|
||||||
public class CmdFactionsPowerBoost extends FCommand
|
public class CmdFactionsPowerBoost extends FCommand
|
||||||
@ -35,32 +38,29 @@ public class CmdFactionsPowerBoost extends FCommand
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Double targetPower = this.argAsDouble(2);
|
Double targetPower = this.arg(2, ARDouble.get());
|
||||||
if (targetPower == null)
|
if (targetPower == null) return;
|
||||||
{
|
|
||||||
msg("<b>You must specify a valid numeric value for the power bonus/penalty amount.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String target;
|
String target;
|
||||||
|
|
||||||
if (doPlayer)
|
if (doPlayer)
|
||||||
{
|
{
|
||||||
FPlayer targetPlayer = this.argAsBestFPlayerMatch(1);
|
FPlayer targetPlayer = this.arg(1, ARFPlayer.getStartAny());
|
||||||
if (targetPlayer == null) return;
|
if (targetPlayer == null) return;
|
||||||
|
|
||||||
targetPlayer.setPowerBoost(targetPower);
|
targetPlayer.setPowerBoost(targetPower);
|
||||||
target = "Player \""+targetPlayer.getName()+"\"";
|
target = "Player \""+targetPlayer.getName()+"\"";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Faction targetFaction = this.argAsFaction(1);
|
Faction targetFaction = this.arg(1, ARFaction.get());
|
||||||
if (targetFaction == null) return;
|
if (targetFaction == null) return;
|
||||||
|
|
||||||
targetFaction.setPowerBoost(targetPower);
|
targetFaction.setPowerBoost(targetPower);
|
||||||
target = "Faction \""+targetFaction.getTag()+"\"";
|
target = "Faction \""+targetFaction.getTag()+"\"";
|
||||||
}
|
}
|
||||||
|
|
||||||
msg("<i>"+target+" now has a power bonus/penalty of "+targetPower+" to min and max power levels.");
|
msg("<i>"+target+" now has a power bonus/penalty of "+targetPower+" to min and max power levels.");
|
||||||
if (!senderIsConsole)
|
Factions.get().log(fme.getName()+" has set the power bonus/penalty for "+target+" to "+targetPower+".");
|
||||||
Factions.get().log(fme.getName()+" has set the power bonus/penalty for "+target+" to "+targetPower+".");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import com.massivecraft.factions.BoardColl;
|
|||||||
import com.massivecraft.factions.ConfServer;
|
import com.massivecraft.factions.ConfServer;
|
||||||
import com.massivecraft.factions.FPerm;
|
import com.massivecraft.factions.FPerm;
|
||||||
import com.massivecraft.factions.Faction;
|
import com.massivecraft.factions.Faction;
|
||||||
|
import com.massivecraft.factions.Factions;
|
||||||
import com.massivecraft.factions.Perm;
|
import com.massivecraft.factions.Perm;
|
||||||
import com.massivecraft.factions.cmd.arg.ARFaction;
|
import com.massivecraft.factions.cmd.arg.ARFaction;
|
||||||
import com.massivecraft.mcore.cmd.req.ReqHasPerm;
|
import com.massivecraft.mcore.cmd.req.ReqHasPerm;
|
||||||
@ -40,7 +41,7 @@ public class CmdFactionsSethome extends FCommand
|
|||||||
// Can the player set the faction home HERE?
|
// Can the player set the faction home HERE?
|
||||||
if
|
if
|
||||||
(
|
(
|
||||||
! fme.hasAdminMode()
|
! fme.isUsingAdminMode()
|
||||||
&&
|
&&
|
||||||
ConfServer.homesMustBeInClaimedTerritory
|
ConfServer.homesMustBeInClaimedTerritory
|
||||||
&&
|
&&
|
||||||
@ -57,7 +58,7 @@ public class CmdFactionsSethome extends FCommand
|
|||||||
faction.setHome(me.getLocation());
|
faction.setHome(me.getLocation());
|
||||||
|
|
||||||
faction.msg("%s<i> set the home for your faction. You can now use:", fme.describeTo(myFaction, true));
|
faction.msg("%s<i> set the home for your faction. You can now use:", fme.describeTo(myFaction, true));
|
||||||
faction.sendMessage(p.cmdBase.cmdFactionsHome.getUseageTemplate());
|
faction.sendMessage(Factions.get().getOuterCmdFactions().cmdFactionsHome.getUseageTemplate());
|
||||||
if (faction != myFaction)
|
if (faction != myFaction)
|
||||||
{
|
{
|
||||||
fme.msg("<b>You have set the home for the "+faction.getTag(fme)+"<i> faction.");
|
fme.msg("<b>You have set the home for the "+faction.getTag(fme)+"<i> faction.");
|
||||||
|
@ -64,7 +64,7 @@ public abstract class FCommand extends MCommand
|
|||||||
// if economy is enabled and they're not on the bypass list, make 'em pay; returns true unless person can't afford the cost
|
// if economy is enabled and they're not on the bypass list, make 'em pay; returns true unless person can't afford the cost
|
||||||
public boolean payForCommand(double cost, String toDoThis, String forDoingThis)
|
public boolean payForCommand(double cost, String toDoThis, String forDoingThis)
|
||||||
{
|
{
|
||||||
if ( ! Econ.shouldBeUsed() || this.fme == null || cost == 0.0 || fme.hasAdminMode()) return true;
|
if ( ! Econ.shouldBeUsed() || this.fme == null || cost == 0.0 || fme.isUsingAdminMode()) return true;
|
||||||
|
|
||||||
if(ConfServer.bankEnabled && ConfServer.bankFactionPaysCosts && fme.hasFaction())
|
if(ConfServer.bankEnabled && ConfServer.bankFactionPaysCosts && fme.hasFaction())
|
||||||
return Econ.modifyMoney(myFaction, -cost, toDoThis, forDoingThis);
|
return Econ.modifyMoney(myFaction, -cost, toDoThis, forDoingThis);
|
||||||
@ -75,7 +75,7 @@ public abstract class FCommand extends MCommand
|
|||||||
// like above, but just make sure they can pay; returns true unless person can't afford the cost
|
// like above, but just make sure they can pay; returns true unless person can't afford the cost
|
||||||
public boolean canAffordCommand(double cost, String toDoThis)
|
public boolean canAffordCommand(double cost, String toDoThis)
|
||||||
{
|
{
|
||||||
if ( ! Econ.shouldBeUsed() || this.fme == null || cost == 0.0 || fme.hasAdminMode()) return true;
|
if ( ! Econ.shouldBeUsed() || this.fme == null || cost == 0.0 || fme.isUsingAdminMode()) return true;
|
||||||
|
|
||||||
if(ConfServer.bankEnabled && ConfServer.bankFactionPaysCosts && fme.hasFaction())
|
if(ConfServer.bankEnabled && ConfServer.bankFactionPaysCosts && fme.hasFaction())
|
||||||
return Econ.hasAtLeast(myFaction, cost, toDoThis);
|
return Econ.hasAtLeast(myFaction, cost, toDoThis);
|
||||||
|
@ -90,7 +90,7 @@ public class Econ
|
|||||||
if (fI == null) return true;
|
if (fI == null) return true;
|
||||||
|
|
||||||
// Bypassing players can do any kind of transaction
|
// Bypassing players can do any kind of transaction
|
||||||
if (i instanceof FPlayer && ((FPlayer)i).hasAdminMode()) return true;
|
if (i instanceof FPlayer && ((FPlayer)i).isUsingAdminMode()) return true;
|
||||||
|
|
||||||
// You can deposit to anywhere you feel like. It's your loss if you can't withdraw it again.
|
// You can deposit to anywhere you feel like. It's your loss if you can't withdraw it again.
|
||||||
if (i == you) return true;
|
if (i == you) return true;
|
||||||
|
@ -88,7 +88,7 @@ public class FactionsBlockListener implements Listener
|
|||||||
if (ConfServer.playersWhoBypassAllProtection.contains(name)) return true;
|
if (ConfServer.playersWhoBypassAllProtection.contains(name)) return true;
|
||||||
|
|
||||||
FPlayer me = FPlayer.get(name);
|
FPlayer me = FPlayer.get(name);
|
||||||
if (me.hasAdminMode()) return true;
|
if (me.isUsingAdminMode()) return true;
|
||||||
|
|
||||||
PS ps = PS.valueOf(location);
|
PS ps = PS.valueOf(location);
|
||||||
Faction factionHere = BoardColl.get().getFactionAt(ps);
|
Faction factionHere = BoardColl.get().getFactionAt(ps);
|
||||||
|
@ -205,7 +205,7 @@ public class FactionsPlayerListener implements Listener
|
|||||||
if (ConfServer.playersWhoBypassAllProtection.contains(name)) return true;
|
if (ConfServer.playersWhoBypassAllProtection.contains(name)) return true;
|
||||||
|
|
||||||
FPlayer me = FPlayerColl.get().get(name);
|
FPlayer me = FPlayerColl.get().get(name);
|
||||||
if (me.hasAdminMode()) return true;
|
if (me.isUsingAdminMode()) return true;
|
||||||
if (Const.MATERIALS_EDIT_TOOLS.contains(material) && ! FPerm.BUILD.has(me, loc, ! justCheck)) return false;
|
if (Const.MATERIALS_EDIT_TOOLS.contains(material) && ! FPerm.BUILD.has(me, loc, ! justCheck)) return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -215,7 +215,7 @@ public class FactionsPlayerListener implements Listener
|
|||||||
if (ConfServer.playersWhoBypassAllProtection.contains(name)) return true;
|
if (ConfServer.playersWhoBypassAllProtection.contains(name)) return true;
|
||||||
|
|
||||||
FPlayer me = FPlayerColl.get().get(name);
|
FPlayer me = FPlayerColl.get().get(name);
|
||||||
if (me.hasAdminMode()) return true;
|
if (me.isUsingAdminMode()) return true;
|
||||||
Location loc = block.getLocation();
|
Location loc = block.getLocation();
|
||||||
Material material = block.getType();
|
Material material = block.getType();
|
||||||
|
|
||||||
@ -293,7 +293,7 @@ public class FactionsPlayerListener implements Listener
|
|||||||
FPlayer me = FPlayerColl.get().get(player);
|
FPlayer me = FPlayerColl.get().get(player);
|
||||||
|
|
||||||
// With adminmode no commands are denied.
|
// With adminmode no commands are denied.
|
||||||
if (me.hasAdminMode()) return;
|
if (me.isUsingAdminMode()) return;
|
||||||
|
|
||||||
// The full command is converted to lowercase and does include the slash in the front
|
// The full command is converted to lowercase and does include the slash in the front
|
||||||
String fullCmd = event.getMessage().toLowerCase();
|
String fullCmd = event.getMessage().toLowerCase();
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
package com.massivecraft.factions.zcore;
|
|
||||||
|
|
||||||
public enum CommandVisibility
|
|
||||||
{
|
|
||||||
VISIBLE, // Visible commands are visible to anyone. Even those who don't have permission to use it or is of invalid sender type.
|
|
||||||
SECRET, // Secret commands are visible only to those who can use the command. These commands are usually some kind of admin commands.
|
|
||||||
INVISIBLE, // Invisible commands are invisible to everyone, even those who can use the command.
|
|
||||||
;
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
package com.massivecraft.factions.zcore;
|
|
||||||
|
|
||||||
public class Lang
|
|
||||||
{
|
|
||||||
public static final String permForbidden = "<b>You don't have permission to %s.";
|
|
||||||
public static final String permDoThat = "do that";
|
|
||||||
|
|
||||||
public static final String commandSenderMustBePlayer = "<b>This command can only be used by ingame players.";
|
|
||||||
public static final String commandToFewArgs = "<b>Too few arguments. <i>Use like this:";
|
|
||||||
public static final String commandToManyArgs = "<b>Strange argument \"<p>%s<b>\". <i>Use the command like this:";
|
|
||||||
}
|
|
@ -1,469 +0,0 @@
|
|||||||
package com.massivecraft.factions.zcore;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import com.massivecraft.factions.zcore.MCommand;
|
|
||||||
import com.massivecraft.factions.zcore.MPlugin;
|
|
||||||
import com.massivecraft.mcore.util.PermUtil;
|
|
||||||
import com.massivecraft.mcore.util.Txt;
|
|
||||||
|
|
||||||
|
|
||||||
public abstract class MCommand<T extends MPlugin>
|
|
||||||
{
|
|
||||||
public T p;
|
|
||||||
|
|
||||||
// The sub-commands to this command
|
|
||||||
public List<MCommand<?>> subCommands;
|
|
||||||
public void addSubCommand(MCommand<?> subCommand)
|
|
||||||
{
|
|
||||||
subCommand.commandChain.addAll(this.commandChain);
|
|
||||||
subCommand.commandChain.add(this);
|
|
||||||
this.subCommands.add(subCommand);
|
|
||||||
}
|
|
||||||
|
|
||||||
// The different names this commands will react to
|
|
||||||
public List<String> aliases;
|
|
||||||
|
|
||||||
// Information on the args
|
|
||||||
public List<String> requiredArgs;
|
|
||||||
public LinkedHashMap<String, String> optionalArgs;
|
|
||||||
public boolean errorOnToManyArgs = true;
|
|
||||||
|
|
||||||
// FIELD: Help Short
|
|
||||||
// This field may be left blank and will in such case be loaded from the permissions node instead.
|
|
||||||
// Thus make sure the permissions node description is an action description like "eat hamburgers" or "do admin stuff".
|
|
||||||
private String helpShort;
|
|
||||||
public void setHelpShort(String val) { this.helpShort = val; }
|
|
||||||
public String getHelpShort()
|
|
||||||
{
|
|
||||||
if (this.helpShort == null)
|
|
||||||
{
|
|
||||||
String pdesc = PermUtil.getDescription(permission);
|
|
||||||
if (pdesc != null)
|
|
||||||
{
|
|
||||||
return pdesc;
|
|
||||||
}
|
|
||||||
return "*info unavailable*";
|
|
||||||
}
|
|
||||||
return this.helpShort;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> helpLong;
|
|
||||||
public CommandVisibility visibility;
|
|
||||||
|
|
||||||
// Some information on permissions
|
|
||||||
public boolean senderMustBePlayer;
|
|
||||||
public String permission;
|
|
||||||
|
|
||||||
// Information available on execution of the command
|
|
||||||
public CommandSender sender; // Will always be set
|
|
||||||
public Player me; // Will only be set when the sender is a player
|
|
||||||
public boolean senderIsConsole;
|
|
||||||
public List<String> args; // Will contain the arguments, or and empty list if there are none.
|
|
||||||
public List<MCommand<?>> commandChain = new ArrayList<MCommand<?>>(); // The command chain used to execute this command
|
|
||||||
|
|
||||||
public MCommand(T p)
|
|
||||||
{
|
|
||||||
this.p = p;
|
|
||||||
|
|
||||||
this.permission = null;
|
|
||||||
|
|
||||||
this.subCommands = new ArrayList<MCommand<?>>();
|
|
||||||
this.aliases = new ArrayList<String>();
|
|
||||||
|
|
||||||
this.requiredArgs = new ArrayList<String>();
|
|
||||||
this.optionalArgs = new LinkedHashMap<String, String>();
|
|
||||||
|
|
||||||
this.helpShort = null;
|
|
||||||
this.helpLong = new ArrayList<String>();
|
|
||||||
this.visibility = CommandVisibility.VISIBLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// The commandChain is a list of the parent command chain used to get to this command.
|
|
||||||
public void execute(CommandSender sender, List<String> args, List<MCommand<?>> commandChain)
|
|
||||||
{
|
|
||||||
// Set the execution-time specific variables
|
|
||||||
this.sender = sender;
|
|
||||||
if (sender instanceof Player)
|
|
||||||
{
|
|
||||||
this.me = (Player)sender;
|
|
||||||
this.senderIsConsole = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.me = null;
|
|
||||||
this.senderIsConsole = true;
|
|
||||||
}
|
|
||||||
this.args = args;
|
|
||||||
this.commandChain = commandChain;
|
|
||||||
|
|
||||||
// Is there a matching sub command?
|
|
||||||
if (args.size() > 0 )
|
|
||||||
{
|
|
||||||
for (MCommand<?> subCommand: this.subCommands)
|
|
||||||
{
|
|
||||||
if (subCommand.aliases.contains(args.get(0)))
|
|
||||||
{
|
|
||||||
args.remove(0);
|
|
||||||
commandChain.add(this);
|
|
||||||
subCommand.execute(sender, args, commandChain);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( ! validCall(this.sender, this.args)) return;
|
|
||||||
|
|
||||||
if ( ! this.isEnabled()) return;
|
|
||||||
|
|
||||||
perform();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void execute(CommandSender sender, List<String> args)
|
|
||||||
{
|
|
||||||
execute(sender, args, new ArrayList<MCommand<?>>());
|
|
||||||
}
|
|
||||||
|
|
||||||
// This is where the command action is performed.
|
|
||||||
public abstract void perform();
|
|
||||||
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// Call Validation
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
/**
|
|
||||||
* In this method we validate that all prerequisites to perform this command has been met.
|
|
||||||
*/
|
|
||||||
// TODO: There should be a boolean for silence
|
|
||||||
public boolean validCall(CommandSender sender, List<String> args)
|
|
||||||
{
|
|
||||||
if ( ! validSenderType(sender, true))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( ! validSenderPermissions(sender, true))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( ! validArgs(args, sender))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isEnabled()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean validSenderType(CommandSender sender, boolean informSenderIfNot)
|
|
||||||
{
|
|
||||||
if (this.senderMustBePlayer && ! (sender instanceof Player))
|
|
||||||
{
|
|
||||||
if (informSenderIfNot)
|
|
||||||
{
|
|
||||||
msg(Lang.commandSenderMustBePlayer);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean validSenderPermissions(CommandSender sender, boolean informSenderIfNot)
|
|
||||||
{
|
|
||||||
if (this.permission == null) return true;
|
|
||||||
return PermUtil.has(sender, this.permission, informSenderIfNot);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean validArgs(List<String> args, CommandSender sender)
|
|
||||||
{
|
|
||||||
if (args.size() < this.requiredArgs.size())
|
|
||||||
{
|
|
||||||
if (sender != null)
|
|
||||||
{
|
|
||||||
msg(Lang.commandToFewArgs);
|
|
||||||
sender.sendMessage(this.getUseageTemplate());
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args.size() > this.requiredArgs.size() + this.optionalArgs.size() && this.errorOnToManyArgs)
|
|
||||||
{
|
|
||||||
if (sender != null)
|
|
||||||
{
|
|
||||||
// Get the to many string slice
|
|
||||||
List<String> theToMany = args.subList(this.requiredArgs.size() + this.optionalArgs.size(), args.size());
|
|
||||||
msg(Lang.commandToManyArgs, Txt.implode(theToMany, " "));
|
|
||||||
sender.sendMessage(this.getUseageTemplate());
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
public boolean validArgs(List<String> args)
|
|
||||||
{
|
|
||||||
return this.validArgs(args, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// Help and Usage information
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
public String getUseageTemplate(List<MCommand<?>> commandChain, boolean addShortHelp)
|
|
||||||
{
|
|
||||||
StringBuilder ret = new StringBuilder();
|
|
||||||
ret.append(Txt.parse("<c>"));
|
|
||||||
ret.append('/');
|
|
||||||
|
|
||||||
for (MCommand<?> mc : commandChain)
|
|
||||||
{
|
|
||||||
ret.append(Txt.implode(mc.aliases, ","));
|
|
||||||
ret.append(' ');
|
|
||||||
}
|
|
||||||
|
|
||||||
ret.append(Txt.implode(this.aliases, ","));
|
|
||||||
|
|
||||||
List<String> args = new ArrayList<String>();
|
|
||||||
|
|
||||||
for (String requiredArg : this.requiredArgs)
|
|
||||||
{
|
|
||||||
args.add("<"+requiredArg+">");
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Entry<String, String> optionalArg : this.optionalArgs.entrySet())
|
|
||||||
{
|
|
||||||
String val = optionalArg.getValue();
|
|
||||||
if (val == null)
|
|
||||||
{
|
|
||||||
val = "";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
val = "="+val;
|
|
||||||
}
|
|
||||||
args.add("["+optionalArg.getKey()+val+"]");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args.size() > 0)
|
|
||||||
{
|
|
||||||
ret.append(Txt.parse("<p> "));
|
|
||||||
ret.append(Txt.implode(args, " "));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (addShortHelp)
|
|
||||||
{
|
|
||||||
ret.append(Txt.parse(" <i>"));
|
|
||||||
ret.append(this.getHelpShort());
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUseageTemplate(boolean addShortHelp)
|
|
||||||
{
|
|
||||||
return getUseageTemplate(this.commandChain, addShortHelp);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUseageTemplate()
|
|
||||||
{
|
|
||||||
return getUseageTemplate(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// Message Sending Helpers
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
public void msg(String str, Object... args)
|
|
||||||
{
|
|
||||||
sender.sendMessage(Txt.parse(str, args));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void sendMessage(String msg)
|
|
||||||
{
|
|
||||||
sender.sendMessage(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void sendMessage(List<String> msgs)
|
|
||||||
{
|
|
||||||
for(String msg : msgs)
|
|
||||||
{
|
|
||||||
this.sendMessage(msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// Argument Readers
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
// Is set? ======================
|
|
||||||
public boolean argIsSet(int idx)
|
|
||||||
{
|
|
||||||
if (this.args.size() < idx+1)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// STRING ======================
|
|
||||||
public String argAsString(int idx, String def)
|
|
||||||
{
|
|
||||||
if (this.args.size() < idx+1)
|
|
||||||
{
|
|
||||||
return def;
|
|
||||||
}
|
|
||||||
return this.args.get(idx);
|
|
||||||
}
|
|
||||||
public String argAsString(int idx)
|
|
||||||
{
|
|
||||||
return this.argAsString(idx, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
// INT ======================
|
|
||||||
public Integer strAsInt(String str, Integer def)
|
|
||||||
{
|
|
||||||
if (str == null) return def;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Integer ret = Integer.parseInt(str);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
return def;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public Integer argAsInt(int idx, Integer def)
|
|
||||||
{
|
|
||||||
return strAsInt(this.argAsString(idx), def);
|
|
||||||
}
|
|
||||||
public Integer argAsInt(int idx)
|
|
||||||
{
|
|
||||||
return this.argAsInt(idx, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Double ======================
|
|
||||||
public Double strAsDouble(String str, Double def)
|
|
||||||
{
|
|
||||||
if (str == null) return def;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Double ret = Double.parseDouble(str);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
return def;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public Double argAsDouble(int idx, Double def)
|
|
||||||
{
|
|
||||||
return strAsDouble(this.argAsString(idx), def);
|
|
||||||
}
|
|
||||||
public Double argAsDouble(int idx)
|
|
||||||
{
|
|
||||||
return this.argAsDouble(idx, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Go through the str conversion for the other arg-readers as well.
|
|
||||||
// Boolean ======================
|
|
||||||
public Boolean strAsBool(String str)
|
|
||||||
{
|
|
||||||
str = str.toLowerCase();
|
|
||||||
if (str.startsWith("y") || str.startsWith("t") || str.startsWith("on") || str.startsWith("+") || str.startsWith("1"))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
public Boolean argAsBool(int idx, Boolean def)
|
|
||||||
{
|
|
||||||
String str = this.argAsString(idx);
|
|
||||||
if (str == null) return def;
|
|
||||||
|
|
||||||
return strAsBool(str);
|
|
||||||
}
|
|
||||||
public Boolean argAsBool(int idx)
|
|
||||||
{
|
|
||||||
return this.argAsBool(idx, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
// PLAYER ======================
|
|
||||||
public Player strAsPlayer(String name, Player def, boolean msg)
|
|
||||||
{
|
|
||||||
Player ret = def;
|
|
||||||
|
|
||||||
if (name != null)
|
|
||||||
{
|
|
||||||
Player player = Bukkit.getServer().getPlayer(name);
|
|
||||||
if (player != null)
|
|
||||||
{
|
|
||||||
ret = player;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (msg && ret == null)
|
|
||||||
{
|
|
||||||
this.msg("<b>No player \"<p>%s<b>\" could not be found.", name);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Player argAsPlayer(int idx, Player def, boolean msg)
|
|
||||||
{
|
|
||||||
return this.strAsPlayer(this.argAsString(idx), def, msg);
|
|
||||||
}
|
|
||||||
public Player argAsPlayer(int idx, Player def)
|
|
||||||
{
|
|
||||||
return this.argAsPlayer(idx, def, true);
|
|
||||||
}
|
|
||||||
public Player argAsPlayer(int idx)
|
|
||||||
{
|
|
||||||
return this.argAsPlayer(idx, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
// BEST PLAYER MATCH ======================
|
|
||||||
public Player strAsBestPlayerMatch(String name, Player def, boolean msg)
|
|
||||||
{
|
|
||||||
Player ret = def;
|
|
||||||
|
|
||||||
if (name != null)
|
|
||||||
{
|
|
||||||
List<Player> players = Bukkit.getServer().matchPlayer(name);
|
|
||||||
if (players.size() > 0)
|
|
||||||
{
|
|
||||||
ret = players.get(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (msg && ret == null)
|
|
||||||
{
|
|
||||||
this.msg("<b>No player match found for \"<p>%s<b>\".", name);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
public Player argAsBestPlayerMatch(int idx, Player def, boolean msg)
|
|
||||||
{
|
|
||||||
return this.strAsBestPlayerMatch(this.argAsString(idx), def, msg);
|
|
||||||
}
|
|
||||||
public Player argAsBestPlayerMatch(int idx, Player def)
|
|
||||||
{
|
|
||||||
return this.argAsBestPlayerMatch(idx, def, true);
|
|
||||||
}
|
|
||||||
public Player argAsBestPlayerMatch(int idx)
|
|
||||||
{
|
|
||||||
return this.argAsPlayer(idx, null);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,89 +0,0 @@
|
|||||||
package com.massivecraft.factions.zcore;
|
|
||||||
|
|
||||||
import java.lang.reflect.Modifier;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
|
|
||||||
import com.massivecraft.mcore.util.Txt;
|
|
||||||
import com.massivecraft.mcore.xlib.gson.Gson;
|
|
||||||
import com.massivecraft.mcore.xlib.gson.GsonBuilder;
|
|
||||||
|
|
||||||
|
|
||||||
public abstract class MPlugin extends JavaPlugin
|
|
||||||
{
|
|
||||||
// Persist related
|
|
||||||
public Gson gson;
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// ENABLE
|
|
||||||
// -------------------------------------------- //
|
|
||||||
private long timeEnableStart;
|
|
||||||
public boolean preEnable()
|
|
||||||
{
|
|
||||||
log("=== ENABLE START ===");
|
|
||||||
timeEnableStart = System.currentTimeMillis();
|
|
||||||
|
|
||||||
// Ensure basefolder exists!
|
|
||||||
this.getDataFolder().mkdirs();
|
|
||||||
|
|
||||||
this.gson = this.getGsonBuilder().create();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void postEnable()
|
|
||||||
{
|
|
||||||
log("=== ENABLE DONE (Took "+(System.currentTimeMillis()-timeEnableStart)+"ms) ===");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onDisable()
|
|
||||||
{
|
|
||||||
log("Disabled");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void suicide()
|
|
||||||
{
|
|
||||||
log("Now I suicide!");
|
|
||||||
this.getServer().getPluginManager().disablePlugin(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// Some inits...
|
|
||||||
// You are supposed to override these in the plugin if you aren't satisfied with the defaults
|
|
||||||
// The goal is that you always will be satisfied though.
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
public GsonBuilder getGsonBuilder()
|
|
||||||
{
|
|
||||||
return new GsonBuilder()
|
|
||||||
.setPrettyPrinting()
|
|
||||||
.disableHtmlEscaping()
|
|
||||||
.serializeNulls()
|
|
||||||
.excludeFieldsWithModifiers(Modifier.TRANSIENT, Modifier.VOLATILE);
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// LOGGING
|
|
||||||
// -------------------------------------------- //
|
|
||||||
public void log(Object msg)
|
|
||||||
{
|
|
||||||
log(Level.INFO, msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void log(String str, Object... args)
|
|
||||||
{
|
|
||||||
log(Level.INFO, Txt.parse(str, args));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void log(Level level, String str, Object... args)
|
|
||||||
{
|
|
||||||
log(level, Txt.parse(str, args));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void log(Level level, Object msg)
|
|
||||||
{
|
|
||||||
Bukkit.getLogger().log(level, "["+this.getDescription().getFullName()+"] "+msg);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user