mirror of
https://github.com/MassiveCraft/Factions.git
synced 2024-11-23 18:55:25 +01:00
Add faction announcements to send to all players and show to players when they login if they were not online when it was first sent as requested in issue #82.
This commit is contained in:
parent
047fe0937a
commit
bed6fe0741
@ -563,7 +563,9 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
|
||||
|
||||
/**
|
||||
* Check if the scoreboard should be shown. Simple method to be used by above method.
|
||||
*
|
||||
* @param toShow Faction to be shown.
|
||||
*
|
||||
* @return true if should show, otherwise false.
|
||||
*/
|
||||
private boolean shouldShowScoreboard(Faction toShow) {
|
||||
@ -629,6 +631,7 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
|
||||
}
|
||||
}
|
||||
|
||||
myFaction.removeAnnouncements(this);
|
||||
this.resetFactionData();
|
||||
|
||||
if (myFaction.isNormal() && !perm && myFaction.getFPlayers().isEmpty()) {
|
||||
|
@ -33,6 +33,37 @@ public class Faction extends Entity implements EconomyParticipator {
|
||||
// speedy lookup of players in faction
|
||||
private transient Set<FPlayer> fplayers = new HashSet<FPlayer>();
|
||||
|
||||
private HashMap<String, List<String>> announcements;
|
||||
|
||||
public HashMap<String, List<String>> getAnnouncements() {
|
||||
return this.announcements;
|
||||
}
|
||||
|
||||
public void addAnnouncement(FPlayer fPlayer, String msg) {
|
||||
List<String> list = announcements.containsKey(fPlayer.getId()) ? announcements.get(fPlayer.getId()) : new ArrayList<String>();
|
||||
list.add(msg);
|
||||
announcements.put(fPlayer.getId(), list);
|
||||
}
|
||||
|
||||
public void sendUnreadAnnouncements(FPlayer fPlayer) {
|
||||
if (!announcements.containsKey(fPlayer.getId())) {
|
||||
return;
|
||||
}
|
||||
fPlayer.sendMessage(ChatColor.LIGHT_PURPLE + "--Unread Faction Announcements--");
|
||||
for (String s : announcements.get(fPlayer.getPlayer().getUniqueId().toString())) {
|
||||
fPlayer.sendMessage(s);
|
||||
}
|
||||
fPlayer.sendMessage(ChatColor.LIGHT_PURPLE + "--Unread Faction Announcements--");
|
||||
announcements.remove(fPlayer.getId());
|
||||
}
|
||||
|
||||
public void removeAnnouncements(FPlayer fPlayer) {
|
||||
if (announcements.containsKey(fPlayer.getId())) {
|
||||
announcements.remove(fPlayer.getId());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// FIELD: invites
|
||||
private Set<String> invites;
|
||||
|
||||
@ -236,6 +267,7 @@ public class Faction extends Entity implements EconomyParticipator {
|
||||
this.permanent = false;
|
||||
this.money = 0.0;
|
||||
this.powerBoost = 0.0;
|
||||
this.announcements = new HashMap<String, List<String>>();
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
|
@ -22,10 +22,7 @@ import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
|
||||
|
||||
@ -125,8 +122,7 @@ public class P extends MPlugin {
|
||||
|
||||
@Override
|
||||
public GsonBuilder getGsonBuilder() {
|
||||
Type mapFLocToStringSetType = new TypeToken<Map<FLocation, Set<String>>>() {
|
||||
}.getType();
|
||||
Type mapFLocToStringSetType = new TypeToken<Map<FLocation, Set<String>>>() {}.getType();
|
||||
|
||||
return new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().excludeFieldsWithModifiers(Modifier.TRANSIENT, Modifier.VOLATILE).registerTypeAdapter(LazyLocation.class, new MyLocationTypeAdapter()).registerTypeAdapter(mapFLocToStringSetType, new MapFLocToStringSetTypeAdapter());
|
||||
}
|
||||
|
42
src/main/java/com/massivecraft/factions/cmd/CmdAnnounce.java
Normal file
42
src/main/java/com/massivecraft/factions/cmd/CmdAnnounce.java
Normal file
@ -0,0 +1,42 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.FPlayer;
|
||||
import com.massivecraft.factions.struct.Permission;
|
||||
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class CmdAnnounce extends FCommand {
|
||||
|
||||
public CmdAnnounce() {
|
||||
super();
|
||||
this.aliases.add("ann");
|
||||
this.aliases.add("announce");
|
||||
|
||||
this.requiredArgs.add("message");
|
||||
this.errorOnToManyArgs = false;
|
||||
|
||||
this.permission = Permission.ANNOUNCE.node;
|
||||
this.disableOnLock = false;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = true;
|
||||
senderMustBeModerator = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
String prefix = ChatColor.GREEN + myFaction.getTag() + ChatColor.YELLOW + " [" + ChatColor.GRAY + me.getName() + ChatColor.YELLOW + "] " + ChatColor.RESET;
|
||||
String message = StringUtils.join(args, " ");
|
||||
|
||||
for (Player player : myFaction.getOnlinePlayers()) {
|
||||
player.sendMessage(prefix + message);
|
||||
}
|
||||
|
||||
// Add for offline players.
|
||||
for (FPlayer fp : myFaction.getFPlayersWhereOnline(false)) {
|
||||
myFaction.addAnnouncement(fp, prefix + message);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -44,6 +44,7 @@ public class CmdInvite extends FCommand {
|
||||
}
|
||||
|
||||
myFaction.invite(you);
|
||||
if(!you.isOnline()) return;
|
||||
|
||||
// Tooltips, colors, and commands only apply to the string immediately before it.
|
||||
FancyMessage message = new FancyMessage(fme.describeTo(you, true))
|
||||
|
@ -54,6 +54,7 @@ public class FCmdRoot extends FCommand {
|
||||
public CmdWarunclaimall cmdWarunclaimall = new CmdWarunclaimall();
|
||||
public CmdSB cmdSB = new CmdSB();
|
||||
public CmdShowInvites cmdShowInvites = new CmdShowInvites();
|
||||
public CmdAnnounce cmdAnnounce = new CmdAnnounce();
|
||||
|
||||
public FCmdRoot() {
|
||||
super();
|
||||
@ -124,6 +125,7 @@ public class FCmdRoot extends FCommand {
|
||||
this.addSubCommand(this.cmdWarunclaimall);
|
||||
this.addSubCommand(this.cmdSB);
|
||||
this.addSubCommand(this.cmdShowInvites);
|
||||
this.addSubCommand(this.cmdAnnounce);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -45,6 +45,16 @@ public class FactionsPlayerListener implements Listener {
|
||||
// Store player's current FLocation and notify them where they are
|
||||
me.setLastStoodAt(new FLocation(event.getPlayer().getLocation()));
|
||||
|
||||
// Check for Faction announcements. Let's delay this so they actually see it.
|
||||
Bukkit.getScheduler().runTaskLater(P.p, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (me.isOnline()) {
|
||||
me.getFaction().sendUnreadAnnouncements(me);
|
||||
}
|
||||
}
|
||||
}, 33L); // Don't ask me why.
|
||||
|
||||
if (P.p.getConfig().getBoolean("scoreboard.default-enabled", false) && P.p.cmdBase.cmdSB.showBoard(me)) {
|
||||
Bukkit.getScheduler().runTaskLater(P.p, new Runnable() { // I think we still have to delay this a few seconds.
|
||||
@Override
|
||||
|
@ -9,6 +9,7 @@ public enum Permission {
|
||||
OWNERSHIP_BYPASS("ownershipbypass"),
|
||||
ADMIN("admin"),
|
||||
ADMIN_ANY("admin.any"),
|
||||
ANNOUNCE("announce"),
|
||||
AUTOCLAIM("autoclaim"),
|
||||
BYPASS("bypass"),
|
||||
CHAT("chat"),
|
||||
|
Loading…
Reference in New Issue
Block a user