Skip to content

Commit

Permalink
1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jpenilla committed Jul 10, 2020
1 parent c5172e8 commit ac1dea2
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 33 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>xyz.jpenilla</groupId>
<artifactId>MiniMOTD</artifactId>
<version>1.1.0</version>
<version>1.1.1</version>
<packaging>jar</packaging>

<name>MiniMOTD</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import net.kyori.adventure.platform.bungeecord.BungeeAudiences;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.connection.ConnectedPlayer;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Command;

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/xyz/jpenilla/minimotd/bungee/BungeeConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public void reload() {
setJustXMoreEnabled(config.getBoolean(JUST_X_MORE_ENABLED));
setMaxPlayers(config.getInt(MAX_PLAYERS));
setXValue(config.getInt(X_VALUE));
setFakePlayersEnabled(config.getBoolean(FAKE_PLAYERS_ENABLED));
setFakePlayers(config.getString(FAKE_PLAYERS));
}

private Configuration loadFromDisk() {
Expand Down
23 changes: 20 additions & 3 deletions src/main/java/xyz/jpenilla/minimotd/bungee/PingListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import net.md_5.bungee.event.EventHandler;
import net.md_5.bungee.event.EventPriority;

import java.util.concurrent.ThreadLocalRandom;

public class PingListener implements Listener {
private final BungeeConfig cfg;

Expand All @@ -25,9 +27,24 @@ public void onPing(ProxyPingEvent e) {
if (response != null) {
final ServerPing.Players players = response.getPlayers();
int onlinePlayers = players.getOnline();
/*if (cfg.isFakePlayersEnabled()) {
onlinePlayers = onlinePlayers + cfg.getFakePlayersAmount(onlinePlayers);
}*/
if (cfg.isFakePlayersEnabled()) {
try {
if (cfg.getFakePlayers().contains(":")) {
final String[] fakePlayers = cfg.getFakePlayers().split(":");
final int start = Integer.parseInt(fakePlayers[0]);
final int end = Integer.parseInt(fakePlayers[1]);
onlinePlayers = onlinePlayers + ThreadLocalRandom.current().nextInt(start, end);
} else if (cfg.getFakePlayers().contains("%")) {
final double factor = 1 + (Double.parseDouble(cfg.getFakePlayers().replace("%", "")) / 100);
onlinePlayers = (int) Math.ceil(factor * onlinePlayers);
} else {
final int addedPlayers = Integer.parseInt(cfg.getFakePlayers());
onlinePlayers = onlinePlayers + addedPlayers;
}
} catch (NumberFormatException ex) {
System.out.println("[MiniMOTD] fakePlayers config incorrect");
}
}
players.setOnline(onlinePlayers);

int maxPlayers = cfg.getAdjustedMaxPlayers(onlinePlayers, players.getMax());
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/xyz/jpenilla/minimotd/common/MiniMOTDConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,35 @@
import lombok.experimental.FieldNameConstants;

import java.util.ArrayList;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;

@FieldNameConstants
public abstract class MiniMOTDConfig {
private final Random r = new Random();

@Getter private final ArrayList<String> motds = new ArrayList<>();
@Getter @Setter private boolean motdEnabled;
@Getter @Setter private boolean maxPlayersEnabled;
@Getter @Setter private boolean justXMoreEnabled;
@Getter @Setter private boolean fakePlayersEnabled;
@Getter @Setter private int xValue;
@Getter @Setter private int maxPlayers;
@Getter @Setter private String fakePlayers;

public final String MOTDS = "motd." + Fields.motds;
public final String MOTD_ENABLED = "motd." + Fields.motdEnabled;
public final String MAX_PLAYERS_ENABLED = Fields.maxPlayers + "." + Fields.maxPlayersEnabled;
public final String JUST_X_MORE_ENABLED = Fields.maxPlayers + "." + Fields.justXMoreEnabled;
public final String MAX_PLAYERS = Fields.maxPlayers + "." + Fields.maxPlayers;
public final String X_VALUE = Fields.maxPlayers + "." + Fields.xValue;
public final String FAKE_PLAYERS_ENABLED = "bungeeOnly." + Fields.fakePlayersEnabled;
public final String FAKE_PLAYERS = "bungeeOnly." + Fields.fakePlayers;

public abstract void reload();

public String getMOTD(int onlinePlayers, int maxPlayers) {
if (motds.size() == 1) {
return motds.get(0);
} else {
return motds.get(r.nextInt(motds.size()))
return motds.get(ThreadLocalRandom.current().nextInt(motds.size()))
.replace("{onlinePlayers}", String.valueOf(onlinePlayers))
.replace("{maxPlayers}", String.valueOf(maxPlayers));
}
Expand Down
21 changes: 0 additions & 21 deletions src/main/java/xyz/jpenilla/minimotd/common/MiniMessageUtil.java

This file was deleted.

9 changes: 7 additions & 2 deletions src/main/java/xyz/jpenilla/minimotd/spigot/SpigotConfig.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package xyz.jpenilla.minimotd.spigot;

import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.configuration.file.FileConfiguration;
import xyz.jpenilla.minimotd.common.MiniMOTDConfig;
import xyz.jpenilla.minimotd.common.MiniMessageUtil;

public class SpigotConfig extends MiniMOTDConfig {
private final MiniMOTD miniMOTD;
Expand All @@ -25,12 +26,16 @@ public void reload() {
} else {
temp = motd;
}
getMotds().add(MiniMessageUtil.miniMessageToLegacy(temp.replace("{br}", "\n")));
getMotds().add(miniMessageToLegacy(temp.replace("{br}", "\n")));
}
setMotdEnabled(config.getBoolean(MOTD_ENABLED));
setMaxPlayersEnabled(config.getBoolean(MAX_PLAYERS_ENABLED));
setJustXMoreEnabled(config.getBoolean(JUST_X_MORE_ENABLED));
setMaxPlayers(config.getInt(MAX_PLAYERS));
setXValue(config.getInt(X_VALUE));
}

private String miniMessageToLegacy(String message) {
return LegacyComponentSerializer.builder().hexColors().useUnusualXRepeatedCharacterHexFormat().build().serialize(MiniMessage.get().parse(message));
}
}
15 changes: 14 additions & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,17 @@ maxPlayers:
# Changes the Max Players to X more than the online players
# Example: 16/19 players online.
justXMoreEnabled: false
xValue: 3
xValue: 3

bungeeOnly:
# Do you want to enable this feature?
fakePlayersEnabled: false

# Modes: static, random, percent
# static: This many fake players will be added
# ex: fakePlayers: "3"
# random: A random number of fake players in this range will be added
# ex: fakePlayers: "3:6"
# percent: The player count will be inflated by this much, rounding up
# ex: fakePlayers: "25%"
fakePlayers: "25%"

0 comments on commit ac1dea2

Please sign in to comment.