Skip to content

Commit 7e4f555

Browse files
SimpleScoreboards VERSION 1.0.0
1 parent e14485e commit 7e4f555

8 files changed

Lines changed: 245 additions & 30 deletions

File tree

build.gradle.kts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ plugins {
66
}
77

88
// TODO: Update the group to yours
9-
group = "org.allaymc"
9+
group = "com.mythicalgames.scoreboard"
1010
// TODO: Update the description to yours
11-
description = "Java plugin template for allay server"
12-
version = "0.1.0"
11+
description = "Rollout to AllayMC, The greatest MCBE server software OAT"
12+
version = "1.0.0"
1313

1414
java {
1515
toolchain {
@@ -19,12 +19,15 @@ java {
1919

2020
repositories {
2121
mavenCentral()
22+
maven("https://storehouse.okaeri.eu/repository/maven-public")
2223
}
2324

2425
dependencies {
2526
// TODO: Update the version of api to the latest
2627
compileOnly(group = "org.allaymc.allay", name = "api", version = "0.12.0")
28+
compileOnly(group = "org.allaymc", name = "papi", version = "0.1.0")
2729
compileOnly(group = "org.projectlombok", name = "lombok", version = "1.18.34")
30+
implementation("eu.okaeri:okaeri-configs-yaml-snakeyaml:6.0.0-beta.1")
2831

2932
annotationProcessor(group = "org.projectlombok", name = "lombok", version = "1.18.34")
3033
}

settings.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
rootProject.name = "JavaPluginTemplate"
1+
rootProject.name = "SimpleScoreboard"
22

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.mythicalgames.scoreboard;
2+
3+
import eu.okaeri.configs.OkaeriConfig;
4+
import eu.okaeri.configs.annotation.Comment;
5+
import eu.okaeri.configs.annotation.Header;
6+
import java.util.List;
7+
8+
@Header({
9+
"###############################################",
10+
"# Thank you for downloading SimpleScoreboards",
11+
"# You are now part of our Mythical Ecosystem",
12+
"###############################################"
13+
})
14+
public class Config extends OkaeriConfig {
15+
16+
@Comment({
17+
"How often scoreboard should be updated in ticks (20 ticks = 1 second)",
18+
"0 = disabled, ENABLE THIS IF YOU USE PLACEHOLDERS"
19+
})
20+
public int update = 0;
21+
22+
@Comment("Scoreboard title")
23+
public String title = "§l§bHeavenPE §fNetwork";
24+
25+
@Comment({
26+
"Scoreboard lines",
27+
"You can use § for colors and placeholders from PlaceholderAPI",
28+
"https://github.com/AllayMC/PlaceholderAPI",
29+
"Note: two lines can't display the same text"
30+
})
31+
public List<String> text = List.of(
32+
"§l§7-------------",
33+
"§l§bMythicalGames",
34+
"§l§8| §l§7Gamemode: §r§c{game_mode}",
35+
"§l§8| §l§7Os: §r§f{device_os}",
36+
"§l§8| §l§7ʟᴏʙʙʏ: §r§f#1",
37+
"§l",
38+
"§l§bServers",
39+
"§l§6⚔ §l§7Factions: §r§b✔",
40+
"§l§c❤ §l§7Lifesteal: §r§b✔",
41+
"§l§e⚡ §l§7Bedwars: §r§b✔",
42+
" ",
43+
"§r§l§7-------------",
44+
"§bplay.heavenpe.net"
45+
);
46+
47+
@Comment("List of worlds where the scoreboard should be disabled")
48+
public List<String> noScoreboardWorlds = List.of("exampleWorld");
49+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.mythicalgames.scoreboard;
2+
3+
import org.allaymc.api.entity.interfaces.EntityPlayer;
4+
import org.allaymc.api.eventbus.EventHandler;
5+
import org.allaymc.api.eventbus.event.player.PlayerJoinEvent;
6+
import org.allaymc.api.eventbus.event.player.PlayerQuitEvent;
7+
//import org.allaymc.api.eventbus.event.player.PlayerLevelChangeEvent;
8+
9+
public class PlayerListener {
10+
11+
@EventHandler
12+
public void onJoin(PlayerJoinEvent event) {
13+
EntityPlayer player = event.getPlayer();
14+
PlayerScoreboardManager.create(player);
15+
}
16+
17+
@EventHandler
18+
public void onQuit(PlayerQuitEvent event) {
19+
EntityPlayer player = event.getPlayer();
20+
PlayerScoreboardManager.remove(player);
21+
}
22+
23+
// TO HANDLE MULTIPLE WORLD SOON.
24+
}
25+
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package com.mythicalgames.scoreboard;
2+
3+
import org.allaymc.api.entity.interfaces.EntityPlayer;
4+
import org.allaymc.api.scoreboard.Scoreboard;
5+
import org.allaymc.api.scoreboard.data.DisplaySlot;
6+
import org.allaymc.api.server.Server;
7+
8+
import java.util.HashMap;
9+
import java.util.List;
10+
import java.util.Map;
11+
import java.util.stream.Collectors;
12+
13+
public class PlayerScoreboardManager {
14+
15+
private static final Map<String, Scoreboard> scoreboards = new HashMap<>();
16+
17+
public static void create(EntityPlayer player) {
18+
if (shouldDisableInWorld(player)) return;
19+
20+
Config config = SimpleScoreboard.INSTANCE.CONFIG;
21+
String title = config.title;
22+
23+
if (isPlaceholderApiLoaded()) {
24+
try {
25+
title = org.allaymc.papi.PlaceholderAPI.getAPI().setPlaceholders(player, title);
26+
if (title == null || title.isBlank()) title = config.title;
27+
} catch (Exception e) {
28+
title = config.title;
29+
}
30+
}
31+
32+
Scoreboard scoreboard = new Scoreboard(title);
33+
scoreboards.put(player.getOriginName(), scoreboard);
34+
scoreboard.addViewer(player, DisplaySlot.SIDEBAR);
35+
36+
update(player);
37+
}
38+
39+
public static void remove(EntityPlayer player) {
40+
Scoreboard scoreboard = scoreboards.remove(player.getOriginName());
41+
if (scoreboard != null) {
42+
scoreboard.removeViewer(player, DisplaySlot.SIDEBAR);
43+
}
44+
}
45+
46+
public static boolean hasScoreboard(EntityPlayer player) {
47+
return scoreboards.containsKey(player.getOriginName());
48+
}
49+
50+
public static void update(EntityPlayer player) {
51+
if (shouldDisableInWorld(player)) {
52+
remove(player);
53+
return;
54+
}
55+
56+
Scoreboard scoreboard = scoreboards.get(player.getOriginName());
57+
if (scoreboard == null) {
58+
create(player);
59+
return;
60+
}
61+
62+
Config config = SimpleScoreboard.INSTANCE.CONFIG;
63+
64+
List<String> processedLines;
65+
66+
if (isPlaceholderApiLoaded()) {
67+
try {
68+
processedLines = config.text.stream()
69+
.map(line -> {
70+
try {
71+
String replaced = org.allaymc.papi.PlaceholderAPI.getAPI().setPlaceholders(player, line);
72+
return (replaced == null || replaced.isBlank()) ? line : replaced;
73+
} catch (Exception e) {
74+
return line;
75+
}
76+
})
77+
.filter(line -> !line.isBlank())
78+
.distinct()
79+
.collect(Collectors.toList());
80+
} catch (Exception e) {
81+
processedLines = config.text;
82+
}
83+
} else {
84+
processedLines = config.text;
85+
}
86+
87+
scoreboard.setLines(processedLines);
88+
}
89+
90+
private static boolean shouldDisableInWorld(EntityPlayer player) {
91+
String worldName = player.getWorld().getName();
92+
return SimpleScoreboard.INSTANCE.CONFIG.noScoreboardWorlds.contains(worldName);
93+
}
94+
95+
private static boolean isPlaceholderApiLoaded() {
96+
return Server.getInstance().getPluginManager().getPlugin("PlaceholderAPI") != null;
97+
}
98+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package com.mythicalgames.scoreboard;
2+
3+
import org.allaymc.api.entity.interfaces.EntityPlayer;
4+
import org.allaymc.api.plugin.Plugin;
5+
import org.allaymc.api.server.Server;
6+
import org.allaymc.api.scheduler.Task;
7+
8+
import eu.okaeri.configs.ConfigManager;
9+
import eu.okaeri.configs.yaml.snakeyaml.YamlSnakeYamlConfigurer;
10+
import lombok.extern.slf4j.Slf4j;
11+
12+
@Slf4j
13+
public class SimpleScoreboard extends Plugin {
14+
15+
public static SimpleScoreboard INSTANCE;
16+
public Config CONFIG;
17+
18+
@Override
19+
public void onLoad() {
20+
INSTANCE = this;
21+
log.info("Loading configuration file...");
22+
CONFIG = ConfigManager.create(Config.class, config -> {
23+
config.withConfigurer(new YamlSnakeYamlConfigurer());
24+
config.withBindFile(pluginContainer.dataFolder().resolve("config.yml"));
25+
config.withRemoveOrphans(true);
26+
config.saveDefaults();
27+
config.load(true);
28+
});
29+
}
30+
31+
@Override
32+
public void onEnable() {
33+
Server.getInstance().getEventBus().registerListener(new PlayerListener());
34+
35+
int updateInterval = CONFIG.update;
36+
37+
if (updateInterval > 0) {
38+
log.info("Starting scoreboard updater every {} ticks.", updateInterval);
39+
40+
Server.getInstance().getScheduler().scheduleRepeating(INSTANCE, new Task() {
41+
@Override
42+
public boolean onRun() {
43+
for (EntityPlayer player : Server.getInstance().getPlayerManager().getPlayers().values()) {
44+
PlayerScoreboardManager.update(player);
45+
}
46+
return true;
47+
}
48+
},
49+
updateInterval, true
50+
);
51+
} else {
52+
log.info("Scoreboard auto-updating is disabled (update=0 in config).");
53+
}
54+
55+
log.info("SimpleScoreboard has been enabled!");
56+
}
57+
58+
@Override
59+
public void onDisable() {
60+
log.info("SimpleScoreboard has been disabled!");
61+
}
62+
}

src/main/java/org/allaymc/javaplugintemplate/JavaPluginTemplate.java

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/main/resources/plugin.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"entrance": "org.allaymc.javaplugintemplate.JavaPluginTemplate",
3-
"name": "JavaPluginTemplate",
4-
"authors": ["YourNameHere"],
5-
"version": "0.1.0"
2+
"entrance": "com.mythicalgames.scoreboard.SimpleScoreboard",
3+
"name": "SimpleScoreboard",
4+
"authors": ["ACKTAR"],
5+
"version": "1.0.0"
66
}

0 commit comments

Comments
 (0)