Skip to content

Commit

Permalink
v5.0.0-beta (#26)
Browse files Browse the repository at this point in the history
* Added sounds to events of the game (join, leave, watch, teleport, victory, death)
* Every command and subcommand is now editable
* Added config to block commands for EVERYONE during a game
* Added ACTION BAR message with the remaining opponents count when a player dies
* Added Russian translation
* Added new game mode: Elimination Tournament
* Added config for enabling/disabling Killer on games
* Added prizes for first, second, third place and killer
* Broadcasts can be disabled if the message is empty
* Fixed events
* Removed Vault support
* Added support for PlaceholderAPI
* Clears the inventory before giving kit
* Teleports dead players to the watchroom
* Gets messages from English if not found in others
* Added killer to ParticipantDeathEvent
* Adds countdown title before battle
* Changes sound config to use ENUMs
* Warns of invalid sounds
* Adds hidden config for disabling ff messages
* Sorts the game configuration alphabetically for better reading
* Removes built-in support for Factions
* Adds ability to run commands before/after fights
* Adds option to disable PvP in games
  • Loading branch information
RoinujNosde committed Mar 18, 2021
1 parent 3f75f6e commit 6983d35
Show file tree
Hide file tree
Showing 50 changed files with 2,040 additions and 1,582 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/dev_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,17 @@ jobs:

steps:
- uses: actions/checkout@v2

- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Install MassiveCore
run: mvn install:install-file "-Dfile=./repo/com/MassiveCraft/MassiveCore/2.14.0/MassiveCore-2.14.0.jar" "-DgroupId=com.MassiveCraft.MassiveCore" "-DartifactId=MassiveCore" "-Dversion=2.14.0" "-Dpackaging=jar" "-DgeneratePom=true"
- name: Install Factions
run: mvn install:install-file "-Dfile=./repo/com/MassiveCraft/Factions/2.14.0/Factions-2.14.0.jar" "-DgroupId=com.MassiveCraft.Factions" "-DartifactId=Factions" "-Dversion=2.14.0" "-Dpackaging=jar" "-DgeneratePom=true"
- name: Build with Maven
run: mvn -B package --file pom.xml

- name: Create Staging
run: mkdir staging && cp target/TitansBattle*.jar staging

- name: Upload a Build Artifact
uses: actions/upload-artifact@v2
with:
Expand Down
57 changes: 21 additions & 36 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>me.roinujnosde</groupId>
<artifactId>TitansBattle</artifactId>
<version>4.1.0-beta</version>
<version>5.0.0-beta</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -79,22 +79,22 @@
</build>

<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>bintray-roinujnosde-bukkit-plugins</id>
<url>https://dl.bintray.com/roinujnosde/bukkit-plugins</url>
<id>codemc-repo</id>
<url>https://repo.codemc.io/repository/maven-public/</url>
</repository>
<repository>
<id>aikar</id>
<url>https://repo.aikar.co/content/groups/aikar/</url>
</repository>
<repository>
<id>placeholderapi-repo</id>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
</repositories>
<dependencies>
<dependency>
Expand All @@ -105,25 +105,7 @@
<dependency>
<groupId>net.sacredlabyrinth.phaed.simpleclans</groupId>
<artifactId>SimpleClans</artifactId>
<version>2.14.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.sxskdev</groupId>
<artifactId>LegendChat</artifactId>
<version>3.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.MassiveCraft.MassiveCore</groupId>
<artifactId>MassiveCore</artifactId>
<version>2.14.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.MassiveCraft.Factions</groupId>
<artifactId>Factions</artifactId>
<version>2.14.0</version>
<version>2.15.0</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand All @@ -132,12 +114,6 @@
<version>1.9.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.MilkBowl</groupId>
<artifactId>VaultAPI</artifactId>
<version>1.7</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
Expand All @@ -149,14 +125,23 @@
<artifactId>acf-paper</artifactId>
<version>0.5.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.10.9</version>
<scope>provided</scope>
</dependency>
</dependencies>
<name>TitansBattle</name>

<distributionManagement>
<repository>
<id>bintray-roinujnosde-bukkit-plugins</id>
<name>roinujnosde-bukkit-plugins</name>
<url>https://api.bintray.com/maven/roinujnosde/bukkit-plugins/TitansBattle/;publish=1</url>
<id>codemc-releases</id>
<url>https://repo.codemc.io/repository/maven-releases/</url>
</repository>
<snapshotRepository>
<id>codemc-snapshots</id>
<url>https://repo.codemc.io/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
</project>
Binary file not shown.
Binary file not shown.
94 changes: 94 additions & 0 deletions src/main/java/me/roinujnosde/titansbattle/TBExpansion.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package me.roinujnosde.titansbattle;

import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import me.roinujnosde.titansbattle.dao.GameConfigurationDao;
import me.roinujnosde.titansbattle.types.GameConfiguration;
import me.roinujnosde.titansbattle.types.Winners;
import org.bukkit.OfflinePlayer;
import org.jetbrains.annotations.NotNull;

import java.util.List;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class TBExpansion extends PlaceholderExpansion {

private final TitansBattle plugin;
private static final Pattern PREFIX_PATTERN = Pattern.compile("(?<game>^[A-Za-z]+)_(?<type>winner|killer)_prefix");

public TBExpansion(TitansBattle plugin) {
this.plugin = plugin;
}

@Override
public boolean persist() {
return true;
}

@Override
public boolean canRegister() {
return true;
}

@Override
public @NotNull String getIdentifier() {
return plugin.getName().toLowerCase();
}

@Override
public @NotNull String getAuthor() {
return plugin.getDescription().getAuthors().toString();
}

@Override
public @NotNull String getVersion() {
return plugin.getDescription().getVersion();
}

@Override
public String onRequest(OfflinePlayer player, @NotNull String params) {
Matcher matcher = PREFIX_PATTERN.matcher(params);
if (player != null && matcher.find()) {
String game = matcher.group("game");
String type = matcher.group("type").toLowerCase();
switch (type) {
case "killer":
return getKillerPrefix(player, game);
case "winner":
return getWinnerPrefix(player, game);
}
}
return "";
}

@NotNull
public String getWinnerPrefix(@NotNull OfflinePlayer player, @NotNull String game) {
GameConfiguration gameConfig = GameConfigurationDao.getInstance(plugin).getGameConfiguration(game);
if (gameConfig == null) {
return "";
}
Winners latestWinners = plugin.getDatabaseManager().getLatestWinners();
List<UUID> playerWinners = latestWinners.getPlayerWinners(game);
if (playerWinners == null || !playerWinners.contains(player.getUniqueId())) {
return "";
}
String prefix = gameConfig.getWinnerPrefix();
return prefix != null ? prefix : "";
}

@NotNull
public String getKillerPrefix(@NotNull OfflinePlayer player, @NotNull String game) {
GameConfiguration gameConfig = GameConfigurationDao.getInstance(plugin).getGameConfiguration(game);
if (gameConfig == null) {
return "";
}
Winners latestWinners = plugin.getDatabaseManager().getLatestWinners();
UUID killerUuid = latestWinners.getKiller(game);
if (killerUuid == null || !killerUuid.equals(player.getUniqueId())) {
return "";
}
String prefix = gameConfig.getKillerPrefix();
return prefix != null ? prefix : "";
}
}
61 changes: 26 additions & 35 deletions src/main/java/me/roinujnosde/titansbattle/TitansBattle.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,20 @@
import co.aikar.commands.PaperCommandManager;
import me.roinujnosde.titansbattle.commands.TBCommands;
import me.roinujnosde.titansbattle.dao.GameConfigurationDao;
import me.roinujnosde.titansbattle.games.Game;
import me.roinujnosde.titansbattle.listeners.*;
import me.roinujnosde.titansbattle.managers.*;
import me.roinujnosde.titansbattle.types.*;
import me.roinujnosde.titansbattle.types.GameConfiguration;
import me.roinujnosde.titansbattle.types.Kit;
import me.roinujnosde.titansbattle.types.Prizes;
import me.roinujnosde.titansbattle.types.Winners;
import me.roinujnosde.titansbattle.utils.ConfigUtils;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.configuration.serialization.ConfigurationSerialization;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand All @@ -62,14 +64,11 @@ public final class TitansBattle extends JavaPlugin {
private DatabaseManager databaseManager;
private @Nullable GroupManager groupManager;
private GameConfigurationDao gameConfigurationDao;
private Economy economy;

@Override
public void onEnable() {
saveDefaultConfig();
ConfigurationSerialization.registerClass(GameConfiguration.class);
ConfigurationSerialization.registerClass(Kit.class);
ConfigurationSerialization.registerClass(Prizes.class);
registerSerializationClasses();
instance = this;
gameManager = new GameManager();
configManager = new ConfigManager();
Expand All @@ -83,14 +82,23 @@ public void onEnable() {
databaseManager.setup();

loadGroupsPlugin();
setupEconomy();

pcm = new PaperCommandManager(this);
pcm.enableUnstableAPI("help");
configureCommands();
registerEvents();
databaseManager.loadDataToMemory();
gameManager.startOrSchedule();
if (getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) {
new TBExpansion(this).register();
}
}

private void registerSerializationClasses() {
ConfigurationSerialization.registerClass(GameConfiguration.Prize.class);
ConfigurationSerialization.registerClass(GameConfiguration.class);
ConfigurationSerialization.registerClass(Kit.class);
ConfigurationSerialization.registerClass(Prizes.class);
}

private void configureCommands() {
Expand Down Expand Up @@ -120,7 +128,7 @@ private void registerReplacements() {
}

private void registerContexts() {
pcm.getCommandContexts().registerIssuerOnlyContext(Game.class, supplier -> gameManager.getCurrentGame());
pcm.getCommandContexts().registerIssuerOnlyContext(Game.class, supplier -> gameManager.getCurrentGame().orElse(null));
pcm.getCommandContexts().registerContext(Date.class, supplier -> {
try {
return new SimpleDateFormat(configManager.getDateFormat()).parse(supplier.popFirstArg());
Expand All @@ -137,7 +145,7 @@ private void registerCommands() {

private void registerConditions() {
pcm.getCommandConditions().addCondition("happening", handler -> {
if (gameManager.getCurrentGame() == null) {
if (!gameManager.getCurrentGame().isPresent()) {
handler.getIssuer().sendMessage(getLang("not-starting-or-started"));
throw new ConditionFailedException();
}
Expand Down Expand Up @@ -182,8 +190,6 @@ private void registerDependencies() {
private void loadGroupsPlugin() {
if (Bukkit.getPluginManager().getPlugin("SimpleClans") != null) {
setGroupManager(new SimpleClansGroupManager(this));
} else if (Bukkit.getPluginManager().getPlugin("Factions") != null) {
setGroupManager(new FactionsGroupManager(this));
}
}

Expand All @@ -193,31 +199,16 @@ private void registerEvents() {
Bukkit.getPluginManager().registerEvents(new PlayerJoinListener(), this);
Bukkit.getPluginManager().registerEvents(new PlayerDeathListener(), this);
Bukkit.getPluginManager().registerEvents(new EntityDamageListener(), this);
Bukkit.getPluginManager().registerEvents(new PlayerRespawnListener(), this);
}

public DatabaseManager getDatabaseManager() {
return databaseManager;
}

public @Nullable Economy getEconomy() {
return economy;
}

private void setupEconomy() {
if (getServer().getPluginManager().getPlugin("Vault") == null) {
return;
}
RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
if (rsp == null) {
return;
}
economy = rsp.getProvider();
debug("Vault and economy plugin found.", false);
}

@Override
public void onDisable() {
gameManager.finishGame(null, null, null, null);
gameManager.getCurrentGame().ifPresent(g -> g.cancel(Bukkit.getConsoleSender()));
databaseManager.close();
}

Expand Down Expand Up @@ -268,7 +259,8 @@ public LanguageManager getLanguageManager() {
language = config.getString("language." + path);
}
if (language == null) {
language = getLanguageManager().getConfig().getString(path, "Missing key: " + path);
language = getLanguageManager().getConfig().getString(path,
getLanguageManager().getEnglishLanguageFile().getString(path, "<MISSING KEY: " + path + ">"));
}
return ChatColor.translateAlternateColorCodes('&', language);
}
Expand All @@ -291,7 +283,8 @@ public String getLang(@NotNull String path) {
* @return the overrider language if found, or from the default language
* file
*/
public String getLang(@NotNull String path, @Nullable Game game) {
@NotNull
public String getLang(@NotNull String path, Game game) {
YamlConfiguration configFile = null;
if (game != null) {
configFile = gameConfigurationDao.getConfigFile(game.getConfig());
Expand All @@ -306,10 +299,8 @@ public String getLang(@NotNull String path, @Nullable Game game) {
* @param respectUserDecision should the message be sent if debug is false?
*/
public void debug(String message, boolean respectUserDecision) {
if (respectUserDecision) {
if (!configManager.isDebug()) {
return;
}
if (respectUserDecision && !configManager.isDebug()) {
return;
}
Bukkit.getConsoleSender().sendMessage(ChatColor.BLUE + "[TitansBattle] " + message);
}
Expand Down
Loading

0 comments on commit 6983d35

Please sign in to comment.