This repository has been archived by the owner on Jan 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
221 additions
and
27 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
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
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
32 changes: 32 additions & 0 deletions
32
src/main/java/net/flectone/chat/module/serverMessage/greeting/GreetingListener.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,32 @@ | ||
package net.flectone.chat.module.serverMessage.greeting; | ||
|
||
import net.flectone.chat.FlectoneChat; | ||
import net.flectone.chat.module.FListener; | ||
import net.flectone.chat.module.FModule; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.player.PlayerJoinEvent; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class GreetingListener extends FListener { | ||
|
||
public GreetingListener(FModule module) { | ||
super(module); | ||
init(); | ||
} | ||
|
||
@Override | ||
public void init() { | ||
registerEvents(); | ||
} | ||
|
||
@EventHandler | ||
public void playerJoinEvent(@NotNull PlayerJoinEvent event) { | ||
Player player = event.getPlayer(); | ||
if (hasNoPermission(player)) return; | ||
|
||
Bukkit.getScheduler().runTaskAsynchronously(FlectoneChat.getPlugin(), () -> | ||
((GreetingModule) getModule()).send(player)); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/main/java/net/flectone/chat/module/serverMessage/greeting/GreetingModule.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,56 @@ | ||
package net.flectone.chat.module.serverMessage.greeting; | ||
|
||
import net.flectone.chat.component.FImageComponent; | ||
import net.flectone.chat.model.player.FPlayer; | ||
import net.flectone.chat.model.player.Settings; | ||
import net.flectone.chat.module.FModule; | ||
import net.flectone.chat.util.MessageUtil; | ||
import net.flectone.chat.util.PlayerUtil; | ||
import org.bukkit.entity.Player; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.List; | ||
|
||
public class GreetingModule extends FModule { | ||
|
||
public GreetingModule(FModule module, String name) { | ||
super(module, name); | ||
init(); | ||
} | ||
|
||
@Override | ||
public void init() { | ||
if (!isEnabled()) return; | ||
register(); | ||
|
||
actionManager.add(new GreetingListener(this)); | ||
} | ||
|
||
public void send(@NotNull Player player) { | ||
if (!isEnabledFor(player)) return; | ||
|
||
FPlayer fPlayer = playerManager.get(player); | ||
if (fPlayer == null) return; | ||
if (fPlayer.getSettings() == null) return; | ||
|
||
String join = fPlayer.getSettings().getValue(Settings.Type.GREETING); | ||
boolean enabled = join == null || Integer.parseInt(join) != -1; | ||
if (!enabled) return; | ||
|
||
String imageUrl = PlayerUtil.constructAvatarUrl(player); | ||
FImageComponent fImageComponent = new FImageComponent(imageUrl); | ||
String convertedImage = fImageComponent.getConvertedImage().substring(1); | ||
|
||
List<String> messageList = locale.getVaultStringList(player, this + ".message"); | ||
String message = String.join("\n", messageList); | ||
|
||
for (String pixels : convertedImage.split("\n")) { | ||
message = message.replaceFirst("########", pixels); | ||
} | ||
|
||
message = MessageUtil.formatAll(player, MessageUtil.formatPlayerString(player, message)); | ||
player.sendMessage(message); | ||
|
||
fPlayer.playSound(player, player, this.toString()); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -124,6 +124,9 @@ default: | |
first-time: | ||
enable: true | ||
|
||
greeting: | ||
enable: true | ||
|
||
quit: | ||
enable: true | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,7 @@ chatsettings: | |
- advancement | ||
- death | ||
- join | ||
- greeting | ||
- quit | ||
- auto-message | ||
- me | ||
|
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
Oops, something went wrong.