Add per-arena setting announcer-type.
Introduces the concept of an Announcer, which is invoked whenever the `announce` methods on the Arena interface are invoked. Previously, all announcements would simply be sent to the arena's Messenger, but this new feature allows us to move them up into titles to help declutter the somewhat overloaded chat box. By default, to help people discover the new feature, the announcer type is `title`, but it is possible to switch back to `chat` for the original behavior. Closes #272
This commit is contained in:
@@ -3,6 +3,9 @@ package com.garbagemule.MobArena;
|
||||
import static com.garbagemule.MobArena.util.config.ConfigUtils.makeSection;
|
||||
|
||||
import com.garbagemule.MobArena.ScoreboardManager.NullScoreboardManager;
|
||||
import com.garbagemule.MobArena.announce.Announcer;
|
||||
import com.garbagemule.MobArena.announce.MessengerAnnouncer;
|
||||
import com.garbagemule.MobArena.announce.TitleAnnouncer;
|
||||
import com.garbagemule.MobArena.steps.Step;
|
||||
import com.garbagemule.MobArena.steps.StepFactory;
|
||||
import com.garbagemule.MobArena.steps.PlayerJoinArena;
|
||||
@@ -75,6 +78,7 @@ public class ArenaImpl implements Arena
|
||||
private String name;
|
||||
private World world;
|
||||
private Messenger messenger;
|
||||
private Announcer announcer;
|
||||
|
||||
// Settings section of the config-file for this arena.
|
||||
private ConfigurationSection settings;
|
||||
@@ -232,6 +236,16 @@ public class ArenaImpl implements Arena
|
||||
String prefix = settings.getString("prefix", "");
|
||||
this.messenger = !prefix.isEmpty() ? new Messenger(prefix) : plugin.getGlobalMessenger();
|
||||
|
||||
// Announcer
|
||||
String announcerType = settings.getString("announcer-type", "chat");
|
||||
if (announcerType.equals("chat")) {
|
||||
announcer = new MessengerAnnouncer(this.messenger);
|
||||
} else if (announcerType.equals("title")) {
|
||||
announcer = new TitleAnnouncer(5, 60, 10);
|
||||
} else {
|
||||
throw new ConfigError("Unsupported announcer type: " + announcerType);
|
||||
}
|
||||
|
||||
// Actions
|
||||
this.histories = new HashMap<>();
|
||||
this.playerJoinArena = PlayerJoinArena.create(this);
|
||||
@@ -454,7 +468,7 @@ public class ArenaImpl implements Arena
|
||||
@Override
|
||||
public void announce(String msg) {
|
||||
for (Player p : getAllPlayers()) {
|
||||
messenger.tell(p, msg);
|
||||
announcer.announce(p, msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.garbagemule.MobArena.announce;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface Announcer {
|
||||
|
||||
/**
|
||||
* Announce the given message to the given player.
|
||||
*
|
||||
* @param player a player to send a message to, non-null
|
||||
* @param message the message to send, non-null
|
||||
*/
|
||||
void announce(Player player, String message);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.garbagemule.MobArena.announce;
|
||||
|
||||
import com.garbagemule.MobArena.Messenger;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class MessengerAnnouncer implements Announcer {
|
||||
|
||||
private final Messenger messenger;
|
||||
|
||||
public MessengerAnnouncer(Messenger messenger) {
|
||||
this.messenger = messenger;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void announce(Player player, String message) {
|
||||
messenger.tell(player, message);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.garbagemule.MobArena.announce;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class TitleAnnouncer implements Announcer {
|
||||
|
||||
private final int fadeIn;
|
||||
private final int stay;
|
||||
private final int fadeOut;
|
||||
|
||||
public TitleAnnouncer(int fadeIn, int stay, int fadeOut) {
|
||||
this.fadeIn = fadeIn;
|
||||
this.stay = stay;
|
||||
this.fadeOut = fadeOut;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void announce(Player player, String message) {
|
||||
player.sendTitle("", message, fadeIn, stay, fadeOut);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user