Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
Expand Up @@ -57,51 +57,50 @@ private void handleEntityKill(Player victim, Entity killer) {
EntityType mobType = killer.getType();

this.noticeService.create()
.noticeOptional(translation -> {
List<Notice> mobMessages = translation.deathMessage().playerKilledByMobType().get(mobType);

if (mobMessages != null && !mobMessages.isEmpty()) {
return RandomElementUtil.randomElement(mobMessages);
}

List<Notice> genericMobMessages = translation.deathMessage().playerKilledByEntity();
if (genericMobMessages != null && !genericMobMessages.isEmpty()) {
return RandomElementUtil.randomElement(genericMobMessages);
}

return RandomElementUtil.randomElement(translation.deathMessage().playerDiedByUnknownCause());
})
.placeholder("{PLAYER}", victimName)
.placeholder("{MOB}", mobName)
.placeholder("{MOB_TYPE}", mobType.name())
.onlinePlayers()
.send();
.noticeOptional(translation -> {
List<Notice> mobMessages = translation.deathMessage().playerKilledByMobType().get(mobType);

if (mobMessages != null && !mobMessages.isEmpty()) {
return RandomElementUtil.randomElement(mobMessages);
}

List<Notice> genericMobMessages = translation.deathMessage().playerKilledByEntity();
if (genericMobMessages != null && !genericMobMessages.isEmpty()) {
return RandomElementUtil.randomElement(genericMobMessages);
}

return RandomElementUtil.randomElement(translation.deathMessage().playerDiedByUnknownCause());
})
.placeholder("{PLAYER}", victimName)
.placeholder("{MOB}", mobName)
.placeholder("{MOB_TYPE}", mobType.name())
.onlinePlayers()
.sendAsync();
}

private void handleEnvironmentDeath(String victimName, EntityDamageEvent.DamageCause cause) {
this.noticeService.create()
.noticeOptional(translation -> {
List<Notice> causeMessages = translation.deathMessage().playerDiedByDamageCause().get(cause);

if (causeMessages != null && !causeMessages.isEmpty()) {
return RandomElementUtil.randomElement(causeMessages);
}

return RandomElementUtil.randomElement(translation.deathMessage().playerDiedByUnknownCause());
})
.placeholder("{PLAYER}", victimName)
.placeholder("{CAUSE}", this.formatCauseName(cause))
.onlinePlayers()
.send();
.noticeOptional(translation -> {
List<Notice> causeMessages = translation.deathMessage().playerDiedByDamageCause().get(cause);

if (causeMessages != null && !causeMessages.isEmpty()) {
return RandomElementUtil.randomElement(causeMessages);
}

return RandomElementUtil.randomElement(translation.deathMessage().playerDiedByUnknownCause());
})
.placeholder("{PLAYER}", victimName)
.placeholder("{CAUSE}", this.formatCauseName(cause))
.onlinePlayers()
.sendAsync();
}

private void handleUnknownDeath(String victimName) {
this.noticeService.create()
.noticeOptional(translation -> RandomElementUtil.randomElement(translation.deathMessage()
.playerDiedByUnknownCause()))
.placeholder("{PLAYER}", victimName)
.onlinePlayers()
.send();
.noticeOptional(translation -> RandomElementUtil.randomElement(translation.deathMessage().playerDiedByUnknownCause()))
.placeholder("{PLAYER}", victimName)
.onlinePlayers()
.sendAsync();
}

private String getMobName(Entity entity) {
Expand All @@ -119,8 +118,8 @@ private String formatName(String name) {
for (String word : words) {
if (word.length() > 0) {
formatted.append(Character.toUpperCase(word.charAt(0)))
.append(word.substring(1))
.append(" ");
.append(word.substring(1))
.append(" ");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ public void handle(DeathContext context) {
String killerName = killer.getName();

ItemStack weapon = killer.getInventory().getItemInMainHand().getType() != Material.AIR
? killer.getInventory().getItemInMainHand()
: killer.getInventory().getItemInOffHand();
? killer.getInventory().getItemInMainHand()
: killer.getInventory().getItemInOffHand();
String weaponName = this.getWeaponName(weapon);

this.noticeService.create()
.noticeOptional(translation -> RandomElementUtil.randomElement(translation.deathMessage().playerKilledByOtherPlayer()))
.placeholder("{PLAYER}", victimName)
.placeholder("{KILLER}", killerName)
.placeholder("{WEAPON}", weaponName)
.onlinePlayers()
.send();
.noticeOptional(translation -> RandomElementUtil.randomElement(translation.deathMessage().playerKilledByOtherPlayer()))
.placeholder("{PLAYER}", victimName)
.placeholder("{KILLER}", killerName)
.placeholder("{WEAPON}", weaponName)
.onlinePlayers()
.sendAsync();
}

private String getWeaponName(ItemStack weapon) {
Expand Down
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,18 +33,16 @@ 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()))
.noticeOptional(translation -> RandomElementUtil.randomElement(
firstTime
? translation.join().playerJoinedServerFirstTime()
: translation.join().playerJoinedServer()
))
.placeholder("{PLAYER}", player.getName())
.onlinePlayers()
.sendAsync();
Expand Down
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());
}

}