Skip to content

Commit

Permalink
Added a message channel option closes #6
Browse files Browse the repository at this point in the history
-Added the bungeecord API through Maven so that messages can be fully visible on screen
-Added an option in config.yml: "messages_in_chat"
-Rewrote the creation of an instance of Lang in the constructor of Management
-Added a system in Lang.java so that messages can be sent in chat or on screen
  • Loading branch information
Nuytemans-Dieter committed Jul 18, 2019
1 parent 4d84e13 commit 96425ee
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 5 deletions.
20 changes: 20 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>bungeecord-repo</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
</repositories>

<dependencies>
Expand All @@ -27,6 +31,22 @@
<version>1.14.3-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-api</artifactId>
<version>1.14-SNAPSHOT</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-api</artifactId>
<version>1.14-SNAPSHOT</version>
<type>javadoc</type>
<scope>provided</scope>
</dependency>

</dependencies>
<!--
<dependency>
Expand Down
40 changes: 36 additions & 4 deletions src/main/java/be/dezijwegel/files/Lang.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import be.dezijwegel.BetterSleeping;
import be.dezijwegel.interfaces.Reloadable;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

Expand All @@ -13,10 +16,17 @@ public class Lang implements Reloadable {

private BetterSleeping plugin;
private ConfigAPI configAPI;
private SendType sendType;

public Lang (BetterSleeping plugin)
public enum SendType {
CHAT,
SCREEN
}

public Lang (BetterSleeping plugin, SendType sendType)
{
this.plugin = plugin;
this.sendType = sendType;

configAPI = new ConfigAPI(ConfigAPI.FileType.LANG, plugin);
configAPI.reportMissingOptions();
Expand All @@ -29,14 +39,36 @@ public Lang (BetterSleeping plugin)
*/
private void sendRaw(String message, CommandSender receiver)
{
// Cancel if message is set to ignored
if (message.equals(""))
{
return;
}

if (message.contains("<receiver>"))
receiver.sendMessage(message.replace("<receiver>", receiver.getName()));
else receiver.sendMessage(message);
// Replace receiver by the player's name
if (message.contains("<receiver>")) {
message = message.replace("<receiver>", receiver.getName());
} else receiver.sendMessage(message);

// Send message to the receiver through screen or chat, depending on the setting
if (sendType == SendType.SCREEN || !(receiver instanceof Player) )
{

receiver.sendMessage( message );

}
else if (sendType == SendType.CHAT)
{

Player player = (Player) receiver;
Player.Spigot p = player.spigot();

BaseComponent bc = new TextComponent();
bc.addExtra( message );
ChatMessageType type = ChatMessageType.ACTION_BAR;
p.sendMessage(type, bc);

}
}

/**
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/be/dezijwegel/management/Management.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ public class Management {
public Management (BetterSleeping plugin) {
this.plugin = plugin;
config = new Config(plugin);
lang = new Lang(plugin);

boolean sendMessagesInChat = config.getBoolean("messages_in_chat");
Lang.SendType sendType;
if (sendMessagesInChat) sendType = Lang.SendType.CHAT;
else sendType = Lang.SendType.SCREEN;

lang = new Lang(plugin, sendType);

buffs = new BuffManagement(plugin);
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ sleep_delay: 40
# Default: 10
bed_enter_delay: 10

# Choose where the messages will appear
# Setting this to true will result in the messages being sent to the chat
# Setting this to false will result in the messages being shown on screen
# Default: true
messages_in_chat: true

# Choose whether BetterSleeping should treat every world seperate from eachother (true)
# percentage_needed: 30 would mean that 30% of all players IN WORLD X should be sleeping
# If this condition is met, the night/storm will ONLY be skipped in that same world
Expand Down

0 comments on commit 96425ee

Please sign in to comment.