Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.eternalcode.core.feature.joinmessage;


import com.eternalcode.commons.RandomElementUtil;
import com.eternalcode.core.feature.vanish.VanishService;
import com.eternalcode.core.injector.annotations.Inject;
Expand Down Expand Up @@ -34,20 +33,19 @@ void onPlayerJoin(PlayerJoinEvent event) {
return;
}

if (!player.hasPlayedBefore()) {
this.noticeService.create()
.noticeOptional(translation -> RandomElementUtil.randomElement(translation.join().playerJoinedServerFirstTime()))
.placeholder("{PLAYER}", player.getName())
.onlinePlayers()
.send();
}

event.setJoinMessage(EMPTY_MESSAGE);

boolean firstTime = !player.hasPlayedBefore();

this.noticeService.create()
.noticeOptional(translation -> RandomElementUtil.randomElement(translation.join().playerJoinedServer()))
.placeholder("{PLAYER}", player.getName())
.onlinePlayers()
.sendAsync();
.noticeOptional(translation -> {
if (firstTime) {
return RandomElementUtil.randomElement(translation.join().playerJoinedServerFirstTime());
}
return RandomElementUtil.randomElement(translation.join().playerJoinedServer());
})
.placeholder("{PLAYER}", player.getName())
.onlinePlayers()
.sendAsync();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.eternalcode.core.feature.quitmessage;


import com.eternalcode.commons.RandomElementUtil;
import com.eternalcode.core.feature.vanish.VanishService;
import com.eternalcode.core.injector.annotations.Inject;
Expand Down Expand Up @@ -40,6 +39,6 @@ void onPlayerQuit(PlayerQuitEvent event) {
.noticeOptional(translation -> RandomElementUtil.randomElement(translation.quit().playerLeftServer()))
.placeholder("{PLAYER}", player.getName())
.onlinePlayers()
.send();
.sendAsync();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,18 @@
import com.eternalcode.core.user.User;
import com.eternalcode.core.user.UserManager;
import com.eternalcode.multification.viewer.ViewerProvider;
import java.util.List;
import java.util.Collection;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import org.bukkit.Server;
import org.bukkit.command.BlockCommandSender;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.command.RemoteConsoleCommandSender;
import org.bukkit.entity.Player;

import java.util.Collection;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;

@Service
public class BukkitViewerProvider implements ViewerProvider<Viewer>, ViewerService {

Expand All @@ -42,10 +40,10 @@ public Collection<Viewer> all() {

@Override
public Collection<Viewer> onlinePlayers() {
Collection<? extends Player> players = this.server.getOnlinePlayers();
Set<Viewer> audiences = new HashSet<>(players.size());

Set<Viewer> audiences = new HashSet<>();

for (Player player : this.server.getOnlinePlayers()) {
for (Player player : players) {
audiences.add(this.player(player.getUniqueId()));
}

Expand All @@ -54,9 +52,10 @@ public Collection<Viewer> onlinePlayers() {

@Override
public Collection<Viewer> onlinePlayers(String permission) {
Set<Viewer> audiences = new HashSet<>();
Collection<? extends Player> players = this.server.getOnlinePlayers();
Set<Viewer> audiences = new HashSet<>(players.size());

for (Player player : this.server.getOnlinePlayers()) {
for (Player player : players) {
if (player.hasPermission(permission)) {
audiences.add(this.player(player.getUniqueId()));
}
Expand Down Expand Up @@ -98,11 +97,11 @@ public Viewer any(Object any) {
return BukkitViewerImpl.player(player.getUniqueId());
}

if (any instanceof ConsoleCommandSender || any instanceof RemoteConsoleCommandSender || any instanceof BlockCommandSender) {
if (any instanceof ConsoleCommandSender || any instanceof RemoteConsoleCommandSender
|| any instanceof BlockCommandSender) {
return BukkitViewerImpl.console();
}

throw new IllegalArgumentException("Unsupported sender type: " + any.getClass().getName());
}

}