parent
80c761dff9
commit
db45a310ae
14 changed files with 480 additions and 74 deletions
@ -0,0 +1,55 @@ |
||||
package xyz.soukup.ecocraftVelocity.chat; |
||||
|
||||
import com.velocitypowered.api.proxy.Player; |
||||
|
||||
import java.time.Duration; |
||||
import java.time.Instant; |
||||
import java.util.ArrayList; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
|
||||
public class Recipients { |
||||
HashMap<Player, Instant> recipients; |
||||
|
||||
public Recipients() { |
||||
this.recipients = new HashMap<>(); |
||||
} |
||||
|
||||
public void add(Player player){ |
||||
recipients.put(player, Instant.now()); |
||||
} |
||||
|
||||
|
||||
public List<Player> getPlayers(){ |
||||
List<Player> players = new ArrayList<>(); |
||||
Instant lastEligibleInstant = Instant.now().minus(Duration.ofMinutes(5)); |
||||
|
||||
recipients.forEach((player, date) -> { |
||||
if (date.isBefore(lastEligibleInstant) || !player.isActive()){ |
||||
recipients.remove(player); |
||||
}else { |
||||
players.add(player); |
||||
} |
||||
}); |
||||
|
||||
return players; |
||||
} |
||||
|
||||
public List<String> getUsernames(){ |
||||
List<String> usernames = new ArrayList<>(); |
||||
|
||||
for (Player player : getPlayers()){ |
||||
usernames.add(player.getUsername()); |
||||
} |
||||
|
||||
return usernames; |
||||
} |
||||
|
||||
public int count(){ |
||||
return getPlayers().size(); |
||||
} |
||||
|
||||
public Player getFirst(){ |
||||
return getPlayers().get(0); |
||||
} |
||||
} |
||||
@ -0,0 +1,74 @@ |
||||
package xyz.soukup.ecocraftVelocity.configuration; |
||||
|
||||
import com.velocitypowered.api.proxy.Player; |
||||
import dev.dejvokep.boostedyaml.YamlDocument; |
||||
import net.kyori.adventure.text.Component; |
||||
import net.kyori.adventure.text.ComponentBuilder; |
||||
import net.kyori.adventure.text.minimessage.MiniMessage; |
||||
|
||||
import javax.swing.plaf.PanelUI; |
||||
import java.util.List; |
||||
import java.util.concurrent.ThreadLocalRandom; |
||||
|
||||
public class LangManager { |
||||
private final MiniMessage miniMessage = MiniMessage.miniMessage(); |
||||
private final YamlDocument langDocument; |
||||
|
||||
public LangManager(YamlDocument langDocument) { |
||||
this.langDocument = langDocument; |
||||
} |
||||
|
||||
public String getRaw(String key){ |
||||
String raw = null; |
||||
|
||||
if (langDocument.isList(key)){ |
||||
List<String> strings = langDocument.getStringList(key); |
||||
raw = String.join("<br>", strings); |
||||
} |
||||
|
||||
if (raw == null){ |
||||
raw = langDocument.getString(key); |
||||
} |
||||
|
||||
if (raw == null){ |
||||
return key; |
||||
} |
||||
|
||||
return raw; |
||||
} |
||||
public Component get(String key){ |
||||
String raw = getRaw(key); |
||||
return miniMessage.deserialize(raw); |
||||
} |
||||
|
||||
public Component get(String key, Replace... replaces){ |
||||
String raw = getRaw(key); |
||||
|
||||
for (Replace replace : replaces){ |
||||
raw = replace.replace(raw); |
||||
} |
||||
|
||||
return miniMessage.deserialize(raw); |
||||
} |
||||
|
||||
public Component getRandom(String key){ |
||||
List<String> list = langDocument.getStringList(key); |
||||
|
||||
if (list == null){ |
||||
return miniMessage.deserialize(key); |
||||
} |
||||
|
||||
int randomInt = ThreadLocalRandom.current().nextInt(list.size()); |
||||
String raw = list.get(randomInt); |
||||
|
||||
return miniMessage.deserialize(raw); |
||||
} |
||||
|
||||
public void send(String key, Player player, Replace... replaces){ |
||||
Component message = get(key, replaces); |
||||
player.sendMessage(message); |
||||
} |
||||
|
||||
|
||||
} |
||||
; |
||||
@ -0,0 +1,42 @@ |
||||
package xyz.soukup.ecocraftVelocity.configuration; |
||||
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage; |
||||
|
||||
public class Replace { |
||||
private final String key; |
||||
private final String value; |
||||
private final Boolean allowFormatting; |
||||
private final MiniMessage miniMessage = MiniMessage.miniMessage(); |
||||
|
||||
public Replace(String key, String value){ |
||||
this.key = key; |
||||
this.value = value; |
||||
this.allowFormatting = false; |
||||
} |
||||
|
||||
public Replace(String key, String value, Boolean allowFormatting) { |
||||
this.key = key; |
||||
this.value = value; |
||||
this.allowFormatting = allowFormatting; |
||||
} |
||||
|
||||
public String getKey() { |
||||
return key; |
||||
} |
||||
|
||||
public String getValue() { |
||||
return value; |
||||
} |
||||
|
||||
public Boolean getAllowFormatting() { |
||||
return allowFormatting; |
||||
} |
||||
|
||||
public String replace(String string){ |
||||
if (allowFormatting){ |
||||
return string.replace("<" + key + ">", value); |
||||
}else{ |
||||
return string.replace("<" + key + ">", miniMessage.stripTags(value)); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,43 @@ |
||||
package xyz.soukup.ecocraftVelocity.motd; |
||||
|
||||
import com.velocitypowered.api.event.Subscribe; |
||||
import com.velocitypowered.api.event.proxy.ProxyPingEvent; |
||||
import com.velocitypowered.api.proxy.server.ServerPing; |
||||
import com.velocitypowered.api.util.Favicon; |
||||
import net.kyori.adventure.text.Component; |
||||
import xyz.soukup.ecocraftVelocity.configuration.LangManager; |
||||
|
||||
import java.io.IOException; |
||||
import java.nio.file.Path; |
||||
|
||||
public class MotdRequestEvent { |
||||
private final LangManager langManager; |
||||
private final Path dataDirectory; |
||||
|
||||
public MotdRequestEvent(LangManager langManager, Path dataDirectory) { |
||||
this.langManager = langManager; |
||||
this.dataDirectory = dataDirectory; |
||||
} |
||||
|
||||
|
||||
@Subscribe |
||||
public void onServerPing(ProxyPingEvent event){ |
||||
|
||||
Component motd = langManager.get("motd.line1") |
||||
.append(Component.newline()) |
||||
.append(langManager.getRandom("motd.quotes")); |
||||
|
||||
|
||||
ServerPing serverPing = event.getPing(); |
||||
ServerPing.Builder builder = serverPing.asBuilder(); |
||||
builder.description(motd); |
||||
|
||||
try { |
||||
builder.favicon(Favicon.create(dataDirectory.resolve("server-icon.png"))); |
||||
} catch (IOException e) { |
||||
throw new RuntimeException(e); |
||||
} |
||||
|
||||
event.setPing(builder.build()); |
||||
} |
||||
} |
||||
@ -0,0 +1,38 @@ |
||||
motd: |
||||
line1: "<bold><gold>Eco<yellow>Craft<white>.cz </bold><green>CZ/SK Ekonomický Server" |
||||
new-message: "<aqua><bold>Čeká na tebe nová zpráva!" |
||||
quotes: |
||||
- "<gray>„Kdo jinému jámu kopá, ten je u něj na brigádě“" |
||||
- "<gray>„Ta java to je hrozný jazyk“" |
||||
- "<gray>„Sníh padá jinak, když kráčí vůdce“" |
||||
- "<gray>„Kdo mi to tu krade obilí?“" |
||||
- "<gray>„Není ta hora až moc velká?“" |
||||
- "<gray>„I use arch linux btw“" |
||||
- "<gray>„co jste provedli XD“" |
||||
- "<gray>„Kdo tu staví ty hákáče?“" |
||||
tab: |
||||
header: |
||||
- "" |
||||
- "<gold><bold>EcoCraft.cz" |
||||
- "<aqua><bold> BETA SERVER </bold>" |
||||
- "" |
||||
footer: |
||||
- "" |
||||
- " <yellow>www.soukup.xyz" |
||||
- "" |
||||
name-format: "<white><bold><name>" |
||||
chat-format: |
||||
join: "<gray>[<green>+<gray>] <name>" |
||||
leave: "<gray>[<red>-<gray>] <name>" |
||||
player-message: "<hover:show_text:'<yellow><bold><name><br><white>Klikni pro napsání hráči'><click:suggest_command:/msg <name>><yellow><bold><name></click></hover>: <white><msg>" |
||||
direct: |
||||
reply: |
||||
multiple-receivers: |
||||
prefix: "<gold><bold>Vyber příjemce:<reset><br>" |
||||
suffix: "" |
||||
separator: "<br>" |
||||
name-format: "<hover:show_text:'<green>Odeslat hráči <name>'><click:run_command:'/msg <name> <msg>'><white> <b>-> </b><name></click></hover>" |
||||
error: |
||||
no-recipients: "<red>Nemáš komu odepsat" |
||||
sender: "<hover:show_text:'<yellow><bold><name></bold><br><white>Klikni pro odepsání'><click:suggest_command:/msg <name>><blue>já <white><bold>▶ </bold><blue><name></click></hover><gray>: <white><msg>" |
||||
receiver: "<hover:show_text:'<yellow><bold><name></bold><br><white>Klikni pro odepsání'><click:suggest_command:/msg <name>><blue><name> <white><bold>▶ </bold><blue>já</click></hover><gray>: <white><msg>" |
||||
|
After Width: | Height: | Size: 2.2 KiB |
Loading…
Reference in new issue