🚧 add scoreboard configuration

This commit is contained in:
Maxlego08 2024-02-22 12:00:18 +01:00
parent f260e51552
commit b081162d42
9 changed files with 236 additions and 11 deletions

38
pom.xml
View File

@ -91,6 +91,14 @@
<id>papermc</id> <id>papermc</id>
<url>https://repo.papermc.io/repository/maven-public/</url> <url>https://repo.papermc.io/repository/maven-public/</url>
</repository> </repository>
<repository>
<id>krypton</id>
<url>https://repo.kryptonmc.org/releases</url>
</repository>
<repository>
<id>william278.net</id>
<url>https://repo.william278.net/releases</url>
</repository>
</repositories> </repositories>
<dependencies> <dependencies>
<dependency> <dependency>
@ -127,5 +135,35 @@
<artifactId>fastboard</artifactId> <artifactId>fastboard</artifactId>
<version>2.0.2</version> <version>2.0.2</version>
</dependency> </dependency>
<dependency>
<groupId>com.github.booksaw</groupId>
<artifactId>BetterTeams</artifactId>
<version>4.8.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.MrUniverse44</groupId>
<artifactId>ScaredClansAPI</artifactId>
<version>0.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>me.neznamy</groupId>
<artifactId>tab-api</artifactId>
<version>4.0.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.william278</groupId>
<artifactId>husktowns</artifactId>
<version>2.6.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.angeschossen</groupId>
<artifactId>LandsAPI</artifactId>
<version>6.44.6</version>
<scope>provided</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -109,7 +109,7 @@ public class KothManager extends ZUtils implements Savable {
} }
String fileName = name.replace(" ", "_"); String fileName = name.replace(" ", "_");
Koth koth = new ZKoth(fileName, kothType, name, capture, minLocation, maxLocation, new ArrayList<>(), new ArrayList<>()); Koth koth = new ZKoth(fileName, kothType, name, capture, minLocation, maxLocation);
KothCreateEvent event = new KothCreateEvent(koth); KothCreateEvent event = new KothCreateEvent(koth);
event.call(); event.call();

View File

@ -2,6 +2,7 @@ package fr.maxlego08.koth;
import fr.maxlego08.koth.api.Koth; import fr.maxlego08.koth.api.Koth;
import fr.maxlego08.koth.api.KothType; import fr.maxlego08.koth.api.KothType;
import fr.maxlego08.koth.api.utils.ScoreboardConfiguration;
import fr.maxlego08.koth.zcore.utils.Cuboid; import fr.maxlego08.koth.zcore.utils.Cuboid;
import org.bukkit.Location; import org.bukkit.Location;
@ -12,6 +13,8 @@ public class ZKoth implements Koth {
private final String fileName; private final String fileName;
private final KothType kothType; private final KothType kothType;
private final ScoreboardConfiguration cooldownScoreboard;
private final ScoreboardConfiguration startScoreboard;
private String name; private String name;
private int captureSeconds; private int captureSeconds;
private Location minLocation; private Location minLocation;
@ -19,7 +22,7 @@ public class ZKoth implements Koth {
private List<String> startCommands = new ArrayList<>(); private List<String> startCommands = new ArrayList<>();
private List<String> endCommands = new ArrayList<>(); private List<String> endCommands = new ArrayList<>();
public ZKoth(String fileName, KothType kothType, String name, int captureSeconds, Location minLocation, Location maxLocation, List<String> startCommands, List<String> endCommands) { public ZKoth(String fileName, KothType kothType, String name, int captureSeconds, Location minLocation, Location maxLocation, List<String> startCommands, List<String> endCommands, ScoreboardConfiguration cooldownScoreboard, ScoreboardConfiguration startScoreboard) {
this.fileName = fileName; this.fileName = fileName;
this.kothType = kothType; this.kothType = kothType;
this.name = name; this.name = name;
@ -28,6 +31,19 @@ public class ZKoth implements Koth {
this.maxLocation = maxLocation; this.maxLocation = maxLocation;
this.startCommands = startCommands; this.startCommands = startCommands;
this.endCommands = endCommands; this.endCommands = endCommands;
this.startScoreboard = startScoreboard;
this.cooldownScoreboard = cooldownScoreboard;
}
public ZKoth(String fileName, KothType kothType, String name, int captureSeconds, Location minLocation, Location maxLocation) {
this.fileName = fileName;
this.kothType = kothType;
this.name = name;
this.captureSeconds = captureSeconds;
this.minLocation = minLocation;
this.maxLocation = maxLocation;
this.startScoreboard = new ScoreboardConfiguration();
this.cooldownScoreboard = new ScoreboardConfiguration();
} }
@Override @Override
@ -96,4 +112,14 @@ public class ZKoth implements Koth {
public void setCaptureSeconds(int captureSeconds) { public void setCaptureSeconds(int captureSeconds) {
this.captureSeconds = captureSeconds; this.captureSeconds = captureSeconds;
} }
@Override
public ScoreboardConfiguration getCooldownScoreboard() {
return this.cooldownScoreboard;
}
@Override
public ScoreboardConfiguration getStartScoreboard() {
return this.startScoreboard;
}
} }

View File

@ -1,5 +1,6 @@
package fr.maxlego08.koth.api; package fr.maxlego08.koth.api;
import fr.maxlego08.koth.api.utils.ScoreboardConfiguration;
import fr.maxlego08.koth.zcore.utils.Cuboid; import fr.maxlego08.koth.zcore.utils.Cuboid;
import org.bukkit.Location; import org.bukkit.Location;
@ -32,4 +33,8 @@ public interface Koth {
int getCaptureSeconds(); int getCaptureSeconds();
void setCaptureSeconds(int captureSeconds); void setCaptureSeconds(int captureSeconds);
ScoreboardConfiguration getCooldownScoreboard();
ScoreboardConfiguration getStartScoreboard();
} }

View File

@ -0,0 +1,33 @@
package fr.maxlego08.koth.api.utils;
import java.util.Collections;
import java.util.List;
public class ScoreboardConfiguration {
private final boolean isEnable;
private final String title;
private final List<String> lines;
public ScoreboardConfiguration(boolean isEnable, String title, List<String> lines) {
this.isEnable = isEnable;
this.title = title;
this.lines = lines;
}
public ScoreboardConfiguration() {
this(false, "zKoth", Collections.singletonList("Default Configuration"));
}
public boolean isEnable() {
return isEnable;
}
public String getTitle() {
return title;
}
public List<String> getLines() {
return lines;
}
}

View File

@ -0,0 +1,36 @@
package fr.maxlego08.koth.hook.scoreboard;
import fr.maxlego08.koth.api.KothScoreboard;
import me.neznamy.tab.api.TabAPI;
import me.neznamy.tab.api.TabPlayer;
import me.neznamy.tab.api.scoreboard.ScoreboardManager;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import java.util.function.Consumer;
public class TabHook implements KothScoreboard {
private final Plugin plugin;
public TabHook(Plugin plugin) {
super();
this.plugin = plugin;
}
@Override
public void toggle(Player player, Consumer<Player> after) {
TabAPI api = TabAPI.getInstance();
TabPlayer tabPlayer = api.getPlayer(player.getUniqueId());
ScoreboardManager manager = TabAPI.getInstance().getScoreboardManager();
if (tabPlayer != null && manager != null) {
manager.toggleScoreboard(tabPlayer, false);
Bukkit.getScheduler().runTaskLater(this.plugin, () -> after.accept(player), 10);
}
}
@Override
public void hide(Player player, Consumer<Player> after) {
this.toggle(player, after);
}
}

View File

@ -3,6 +3,7 @@ package fr.maxlego08.koth.loader;
import fr.maxlego08.koth.ZKoth; import fr.maxlego08.koth.ZKoth;
import fr.maxlego08.koth.api.Koth; import fr.maxlego08.koth.api.Koth;
import fr.maxlego08.koth.api.KothType; import fr.maxlego08.koth.api.KothType;
import fr.maxlego08.koth.api.utils.ScoreboardConfiguration;
import fr.maxlego08.koth.zcore.utils.ZUtils; import fr.maxlego08.koth.zcore.utils.ZUtils;
import fr.maxlego08.koth.zcore.utils.loader.Loader; import fr.maxlego08.koth.zcore.utils.loader.Loader;
import org.bukkit.Location; import org.bukkit.Location;
@ -14,6 +15,7 @@ import java.util.List;
public class KothLoader extends ZUtils implements Loader<Koth> { public class KothLoader extends ZUtils implements Loader<Koth> {
private final Loader<Location> locationLoader = new LocationLoader(); private final Loader<Location> locationLoader = new LocationLoader();
private final Loader<ScoreboardConfiguration> scoreboardLoaderLoader = new ScoreboardLoader();
@Override @Override
public Koth load(YamlConfiguration configuration, String path, File file) { public Koth load(YamlConfiguration configuration, String path, File file) {
@ -26,20 +28,24 @@ public class KothLoader extends ZUtils implements Loader<Koth> {
List<String> endCommands = configuration.getStringList("endCommands"); List<String> endCommands = configuration.getStringList("endCommands");
Location minLocation = locationLoader.load(configuration, "minLocation.", file); Location minLocation = locationLoader.load(configuration, "minLocation.", file);
Location manLocation = locationLoader.load(configuration, "maxLocation.", file); Location manLocation = locationLoader.load(configuration, "maxLocation.", file);
ScoreboardConfiguration cooldownScoreboard = scoreboardLoaderLoader.load(configuration, "scoreboard.cooldown.", file);
ScoreboardConfiguration startScoreboard = scoreboardLoaderLoader.load(configuration, "scoreboard.start.", file);
return new ZKoth(fileName, kothType, name, captureSeconds, minLocation, manLocation, startCommands, endCommands); return new ZKoth(fileName, kothType, name, captureSeconds, minLocation, manLocation, startCommands, endCommands, cooldownScoreboard, startScoreboard);
} }
@Override @Override
public void save(Koth object, YamlConfiguration configuration, String path) { public void save(Koth koth, YamlConfiguration configuration, String path) {
configuration.set("type", object.getKothType().name()); configuration.set("type", koth.getKothType().name());
configuration.set("name", object.getName()); configuration.set("name", koth.getName());
configuration.set("capture", object.getCaptureSeconds()); configuration.set("capture", koth.getCaptureSeconds());
configuration.set("startCommands", object.getStartCommands()); configuration.set("startCommands", koth.getStartCommands());
configuration.set("endCommands", object.getEndCommands()); configuration.set("endCommands", koth.getEndCommands());
locationLoader.save(object.getMinLocation(), configuration, "minLocation."); locationLoader.save(koth.getMinLocation(), configuration, "minLocation.");
locationLoader.save(object.getMaxLocation(), configuration, "manLocation."); locationLoader.save(koth.getMaxLocation(), configuration, "manLocation.");
scoreboardLoaderLoader.save(koth.getCooldownScoreboard(), configuration, "scoreboard.cooldown.");
scoreboardLoaderLoader.save(koth.getStartScoreboard(), configuration, "scoreboard.start.");
} }
} }

View File

@ -0,0 +1,30 @@
package fr.maxlego08.koth.loader;
import fr.maxlego08.koth.api.utils.ScoreboardConfiguration;
import fr.maxlego08.koth.zcore.utils.loader.Loader;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.util.List;
public class ScoreboardLoader implements Loader<ScoreboardConfiguration> {
@Override
public ScoreboardConfiguration load(YamlConfiguration configuration, String path, File file) {
boolean isEnable = configuration.getBoolean(path + "enable", false);
String title = configuration.getString(path + "title", "zKoth");
List<String> lines = configuration.getStringList(path + "lines");
return new ScoreboardConfiguration(isEnable, title, lines);
}
@Override
public void save(ScoreboardConfiguration scoreboardConfiguration, YamlConfiguration configuration, String path) {
configuration.set(path + "enable", scoreboardConfiguration.isEnable());
configuration.set(path + "title", scoreboardConfiguration.getTitle());
configuration.set(path + "lines", scoreboardConfiguration.getLines());
}
}

View File

@ -0,0 +1,51 @@
name: test
type: CAPTURE
capture: 30
startCommands: []
endCommands: []
minLocation:
world: world
x: 81
y: 121
z: 12
manLocation:
world: world
x: 77
y: 123
z: 8
scoreboard:
cooldown:
enable: false
title: "&f&l⌈ &7&ozKoth &f&l⌋"
lines:
- "&r"
- "&6&l⟣ &fKoth: &b%name%"
- "&6&l⟣ &fCoordinate: &b%x% %y% %z%"
- "&6&l⟣ &fStarts in: &d%capture%"
- "&1"
- "&6&l⟣ &fhttps://groupez.dev"
start:
enable: false
title: "&f&l⌈ &7&ozKoth &f&l⌋"
lines:
- "&r"
- "&6&l⟣ &fKoth: &b%name%"
- "&6&l⟣ &b%x% %y% %z%"
- "&6&l⟣ &fFaction: &b%faction%"
- "&0"
- "&6&l⟣ &fTime: &d%capture%"
- "&b"
- "&6&l⟣ &fPoints: &b%points%&f/&a%maxPoints%"
- "&6&l⟣ &fPercent: &b%pointsPercent%&7%"
- "&6&l⟣ &fTimer: &b%timer%"
- "&6&l⟣ &fTimer: &b%timerSeconds%&f/&a%maxTimerSeconds%"
- "&6&l⟣ &fPercent: &b%timerPercent%&7%"
- "&1"
- "&6&l⟣ &fhttps://groupez.dev"