This commit is contained in:
Olof Larsson 2014-10-02 16:12:16 +02:00
parent 422c896631
commit a09ee5f1f4
8 changed files with 246 additions and 0 deletions

View File

@ -5,5 +5,6 @@ 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 FACTION_NOMOTD = Txt.parse("<em><silver>no message of the day set");
public static final String PLAYER_NOTITLE = Txt.parse("<em><silver>no title set");
}

View File

@ -44,6 +44,7 @@ public enum Perm
MONEY_F2P("money.f2p"),
MONEY_P2F("money.p2f"),
MONEY_WITHDRAW("money.withdraw"),
MOTD("motd"),
OFFICER("officer"),
OFFICER_ANY("officer.any"),
OPEN("open"),

View File

@ -24,6 +24,7 @@ public class CmdFactions extends FactionsCommand
public CmdFactionsCreate cmdFactionsCreate = new CmdFactionsCreate();
public CmdFactionsName cmdFactionsName = new CmdFactionsName();
public CmdFactionsDescription cmdFactionsDescription = new CmdFactionsDescription();
public CmdFactionsMotd cmdFactionsMotd = new CmdFactionsMotd();
public CmdFactionsSethome cmdFactionsSethome = new CmdFactionsSethome();
public CmdFactionsUnsethome cmdFactionsUnsethome = new CmdFactionsUnsethome();
public CmdFactionsInvite cmdFactionsInvite = new CmdFactionsInvite();
@ -69,6 +70,7 @@ public class CmdFactions extends FactionsCommand
this.addSubCommand(this.cmdFactionsCreate);
this.addSubCommand(this.cmdFactionsName);
this.addSubCommand(this.cmdFactionsDescription);
this.addSubCommand(this.cmdFactionsMotd);
this.addSubCommand(this.cmdFactionsSethome);
this.addSubCommand(this.cmdFactionsUnsethome);
this.addSubCommand(this.cmdFactionsInvite);

View File

@ -0,0 +1,91 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Perm;
import com.massivecraft.factions.Rel;
import com.massivecraft.factions.cmd.req.ReqRoleIsAtLeast;
import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
import com.massivecraft.massivecore.mixin.Mixin;
import com.massivecraft.massivecore.util.MUtil;
import com.massivecraft.massivecore.util.Txt;
public class CmdFactionsMotd extends FactionsCommand
{
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public CmdFactionsMotd()
{
// Aliases
this.addAliases("motd");
// Args
this.addOptionalArg("new", "read");
this.setErrorOnToManyArgs(false);
// Requirements
this.addRequirements(ReqHasPerm.get(Perm.MOTD.node));
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public void perform()
{
// Read
if ( ! this.argIsSet(0))
{
sendMessage(msenderFaction.getMotdMessages());
return;
}
// Check Role
if ( ! ReqRoleIsAtLeast.get(Rel.OFFICER).apply(sender, this))
{
sendMessage(ReqRoleIsAtLeast.get(Rel.OFFICER).createErrorMessage(sender, this));
return;
}
// Args
String target = this.argConcatFrom(0);
target = target.trim();
target = Txt.parse(target);
// Removal
if (target != null && MUtil.set("", "r", "remove", "d", "delete", "del", "e", "erase", "none", "null", "nothing").contains(target))
{
target = null;
}
// Get Old
String old = null;
if (msenderFaction.hasMotd())
{
old = msenderFaction.getMotd();
}
// Target Desc
String targetDesc = target;
if (targetDesc == null) targetDesc = Txt.parse("<silver>nothing");
// NoChange
if (MUtil.equals(old, target))
{
msg("<i>The motd for %s <i>is already: <h>%s", msenderFaction.describeTo(msender, true), target);
return;
}
// Apply
msenderFaction.setMotd(target);
// Inform
for (MPlayer follower : msenderFaction.getMPlayers())
{
follower.msg("<i>%s <i>set your faction motd to:\n%s", Mixin.getDisplayName(sender, follower), msenderFaction.getMotd());
}
}
}

View File

@ -43,6 +43,7 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
{
this.setName(that.name);
this.setDescription(that.description);
this.setMotd(that.motd);
this.setCreatedAtMillis(that.createdAtMillis);
this.setHome(that.home);
this.setPowerBoost(that.powerBoost);
@ -87,6 +88,11 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
// Null means the faction has no description.
private String description = null;
// Factions can optionally set a message of the day.
// This message will be shown when logging on to the server.
// Null means the faction has no motd
private String motd = null;
// We store the creation date for the faction.
// It can be displayed on info pages etc.
private long createdAtMillis = System.currentTimeMillis();
@ -232,6 +238,56 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
this.changed();
}
// -------------------------------------------- //
// FIELD: motd
// -------------------------------------------- //
// RAW
public boolean hasMotd()
{
return this.motd != null;
}
public String getMotd()
{
if (this.hasMotd()) return Txt.parse(this.motd);
return Lang.FACTION_NOMOTD;
}
public void setMotd(String motd)
{
// Clean input
String target = motd;
if (target != null)
{
target = target.trim();
if (target.length() == 0)
{
target = null;
}
}
// Detect Nochange
if (MUtil.equals(this.motd, target)) return;
// Apply
this.motd = target;
// Mark as changed
this.changed();
}
// FINER
public List<String> getMotdMessages()
{
final String title = Txt.titleize(this.getName() + " - Message of the Day");
final String motd = "<i>" + this.getMotd();
final List<String> messages = Txt.parse(MUtil.list(title, motd));
return messages;
}
// -------------------------------------------- //
// FIELD: createdAtMillis
// -------------------------------------------- //

View File

@ -102,6 +102,13 @@ public class MConf extends Entity<MConf>
public String defaultPlayerFactionId = Factions.ID_NONE;
public Rel defaultPlayerRole = Rel.RECRUIT;
public double defaultPlayerPower = 0.0;
// -------------------------------------------- //
// MOTD
// -------------------------------------------- //
public EventPriority motdPriority = EventPriority.NORMAL;
public int motdDelayTicks = -1;
// -------------------------------------------- //
// POWER

View File

@ -49,6 +49,7 @@ import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.event.player.PlayerBucketFillEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
@ -68,6 +69,7 @@ import com.massivecraft.factions.event.EventFactionsPvpDisallowed;
import com.massivecraft.factions.event.EventFactionsPowerChange;
import com.massivecraft.factions.event.EventFactionsPowerChange.PowerChangeReason;
import com.massivecraft.factions.util.VisualizeUtil;
import com.massivecraft.massivecore.mixin.Mixin;
import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.util.MUtil;
import com.massivecraft.massivecore.util.PlayerUtil;
@ -92,6 +94,89 @@ public class FactionsListenerMain implements Listener
Bukkit.getPluginManager().registerEvents(this, Factions.get());
}
// -------------------------------------------- //
// MOTD
// -------------------------------------------- //
public static void motd(PlayerJoinEvent event, EventPriority currentPriority)
{
// Gather info ...
final Player player = event.getPlayer();
final MPlayer mplayer = MPlayer.get(player);
final Faction faction = mplayer.getFaction();
// ... if there is a motd ...
if ( ! faction.hasMotd()) return;
// ... and this is the priority we are supposed to act on ...
if (currentPriority != MConf.get().motdPriority) return;
// ... and this is an actual join ...
if (!Mixin.isActualJoin(event)) return;
// ... then prepare the messages ...
final List<String> messages = faction.getMotdMessages();
// ... and send to the player.
if (MConf.get().motdDelayTicks < 0)
{
Mixin.messageOne(player, messages);
}
else
{
Bukkit.getScheduler().scheduleSyncDelayedTask(Factions.get(), new Runnable()
{
@Override
public void run()
{
Mixin.messageOne(player, messages);
}
}, MConf.get().motdDelayTicks);
}
}
// Can't be cancelled
@EventHandler(priority = EventPriority.LOWEST)
public void motdLowest(PlayerJoinEvent event)
{
motd(event, EventPriority.LOWEST);
}
// Can't be cancelled
@EventHandler(priority = EventPriority.LOW)
public void motdLow(PlayerJoinEvent event)
{
motd(event, EventPriority.LOW);
}
// Can't be cancelled
@EventHandler(priority = EventPriority.NORMAL)
public void motdNormal(PlayerJoinEvent event)
{
motd(event, EventPriority.NORMAL);
}
// Can't be cancelled
@EventHandler(priority = EventPriority.HIGH)
public void motdHigh(PlayerJoinEvent event)
{
motd(event, EventPriority.HIGH);
}
// Can't be cancelled
@EventHandler(priority = EventPriority.HIGHEST)
public void motdHighest(PlayerJoinEvent event)
{
motd(event, EventPriority.HIGHEST);
}
// Can't be cancelled
@EventHandler(priority = EventPriority.MONITOR)
public void motdMonitor(PlayerJoinEvent event)
{
motd(event, EventPriority.MONITOR);
}
// -------------------------------------------- //
// CHUNK CHANGE: DETECT
// -------------------------------------------- //

View File

@ -44,6 +44,7 @@ permissions:
factions.money.f2p: {description: transfer f --> p, default: false}
factions.money.p2f: {description: transfer p --> f, default: false}
factions.money.withdraw: {description: withdraw from faction, default: false}
factions.motd: {description: faction motd, default: false}
factions.officer: {description: make player officer, default: false}
factions.officer.any: {description: set officers for another faction, default: false}
factions.open: {description: set if invitation is required to join, default: false}
@ -101,6 +102,7 @@ permissions:
factions.money.f2p: true
factions.money.p2f: true
factions.money.withdraw: true
factions.motd: true
factions.officer: true
factions.officer.any: true
factions.open: true
@ -179,6 +181,7 @@ permissions:
factions.money.f2p: true
factions.money.p2f: true
factions.money.withdraw: true
factions.motd: true
factions.officer: true
factions.open: true
factions.perm: true