-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added messages config option for a list of message strings Added random-order config option to toggle sequential vs random Added example config for message set and improved auto generated config Refactored loading messages from config Removed RepeatingMessage class since its only purpose was to hold a variable that was only used once Incremented version number to 1.9.1
- Loading branch information
Showing
6 changed files
with
215 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/main/java/org/simplemc/simpleannounce/message/MessageGroup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package org.simplemc.simpleannounce.message; | ||
|
||
import org.simplemc.simpleannounce.SimpleAnnounce; | ||
|
||
import java.util.List; | ||
import java.util.Random; | ||
|
||
/** | ||
* @author Taylor Becker | ||
*/ | ||
public class MessageGroup extends Message | ||
{ | ||
private List<String> messages; // messages in this message group | ||
private int current; // index of current message | ||
private Random random; // random generator to use if messages are in random order | ||
|
||
/** | ||
* Create message | ||
* | ||
* @param plugin plugin instance | ||
* @param label message label from config | ||
* @param messages messages in this message group | ||
* @param delay message's delay | ||
* @param random whether the message group should run in random order | ||
*/ | ||
public MessageGroup(SimpleAnnounce plugin, String label, List<String> messages, int delay, boolean random) | ||
{ | ||
super(plugin, label, "", delay); | ||
|
||
this.messages = messages; | ||
|
||
// init random if message is meant to be random | ||
if (random) | ||
{ | ||
this.random = new Random(); | ||
} | ||
|
||
logger.finer(String.format("Message group %s created with %d messages. Random order? %b", label, messages.size(), random)); | ||
} | ||
|
||
@Override | ||
public String getMessage() | ||
{ | ||
String message; | ||
|
||
if (random != null) | ||
{ | ||
message = messages.get(random.nextInt(messages.size())); | ||
} | ||
else | ||
{ | ||
// get next message | ||
message = messages.get(current++); | ||
|
||
// if we've reached the end of the list, reset | ||
if (current == messages.size()) | ||
{ | ||
current = 0; | ||
} | ||
} | ||
|
||
return message; | ||
} | ||
} |
35 changes: 0 additions & 35 deletions
35
src/main/java/org/simplemc/simpleannounce/message/RepeatingMessage.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.