Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>com.alpsbte</groupId>
<artifactId>Alps-Essentials</artifactId>
<version>1.5</version>
<version>1.5.1</version>
<packaging>jar</packaging>

<name>Alps-Essentials</name>
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/alpsbte/essentials/AlpsEssentials.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ public void onEnable() {
YamlFileFactory.registerPlugin(this);
ConfigUtil.init();
} catch (ConfigurateException ex) {
this.getComponentLogger().warn(Component.text("Could not load configuration file."));
Bukkit.getConsoleSender().sendMessage(Component.text("The config file must be configured!", NamedTextColor.YELLOW));
this.getComponentLogger().warn(Component.text("Could not load configuration file.")
.append(Component.text("The config file must be configured!", NamedTextColor.YELLOW)),
ex);
this.getServer().getPluginManager().disablePlugin(this);
return;
}
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/com/alpsbte/essentials/EventListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.alpsbte.essentials.config.ConfigUtil;
import com.alpsbte.essentials.utils.io.LangPaths;
import com.alpsbte.essentials.utils.io.LangUtil;
import io.papermc.paper.event.player.PlayerInventorySlotChangeEvent;
import io.papermc.paper.util.Tick;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.event.ClickEvent;
Expand All @@ -26,10 +26,10 @@
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerSwapHandItemsEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;

import java.time.Duration;
import java.util.List;

public class EventListener implements Listener {
Expand All @@ -53,6 +53,8 @@ public void onPlayerQuitEvent(PlayerQuitEvent event) {

@EventHandler
public void onPlayerJoinShowDonationMessage(PlayerJoinEvent event) {
var config = ConfigUtil.getMainConfig().getDonationSection();
if (!config.enabled()) return;
Bukkit.getScheduler().scheduleSyncDelayedTask(AlpsEssentials.getPlugin(), () -> {
Player p = event.getPlayer();

Expand All @@ -71,12 +73,12 @@ public void onPlayerJoinShowDonationMessage(PlayerJoinEvent event) {
p.sendMessage("");
p.sendMessage(Component.text("» ", NamedTextColor.DARK_GRAY)
.append(Component.text(link, NamedTextColor.GREEN)
.clickEvent(ClickEvent.openUrl("https://www.tipeeestream.com/alps-bte/donation"))
.clickEvent(ClickEvent.openUrl(config.url()))
.hoverEvent(HoverEvent.showText(Component.text(linkHover, NamedTextColor.GRAY)))));
p.sendMessage("");
p.sendMessage(Component.text(thanks, NamedTextColor.GRAY));
p.sendMessage("");
}, 20 * 60 * 10L); // in 10 minutes
}, Tick.tick().fromDuration(Duration.ofMinutes(config.minutes())));
}

@EventHandler
Expand Down
14 changes: 8 additions & 6 deletions src/main/java/com/alpsbte/essentials/config/ConfigUtil.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.alpsbte.essentials.config;

import com.alpsbte.alpslib.io.config.ConfigNotImplementedException;
import com.alpsbte.alpslib.io.config.ConfigurationUtil;
import com.alpsbte.essentials.AlpsEssentials;
import org.spongepowered.configurate.CommentedConfigurationNode;
import org.spongepowered.configurate.ConfigurateException;
Expand All @@ -10,23 +8,27 @@
import org.spongepowered.configurate.yaml.NodeStyle;
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;

import java.nio.file.Paths;
import java.io.File;

public class ConfigUtil {
private ConfigUtil() {}

// Main Config
private static MainConfig mainConfig = null;
private static CommentedConfigurationNode configRoot = null;
private static YamlConfigurationLoader configLoader = null;

public static void init() throws ConfigurateException {
File configFile = AlpsEssentials.getPlugin().getDataPath().resolve("config.yml").toFile();
if (!configFile.exists()) {
AlpsEssentials.getPlugin().saveResource("config.yml", false);
}

final ObjectMapper.Factory customFactory = ObjectMapper.factoryBuilder()
.defaultNamingScheme(NamingSchemes.PASSTHROUGH)
.build();

configLoader = YamlConfigurationLoader.builder()
.path(AlpsEssentials.getPlugin().getDataPath().resolve("config.yml"))
.file(configFile)
.nodeStyle(NodeStyle.BLOCK)
.defaultOptions(opts -> opts.serializers(build -> build.registerAnnotatedObjects(customFactory)))
.build();
Expand All @@ -35,7 +37,7 @@ public static void init() throws ConfigurateException {
}

private static void loadConfigFiles() throws ConfigurateException {
configRoot = configLoader.load();
CommentedConfigurationNode configRoot = configLoader.load();
mainConfig = configRoot.get(MainConfig.class);
}

Expand Down
10 changes: 9 additions & 1 deletion src/main/java/com/alpsbte/essentials/config/MainConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,14 @@ public class MainConfig {
@Setting("cosmetics")
private CosmeticSection cosmetics;

@Comment("Configurable donation message")
@Setting("donation-message")
private DonationSection donation;

@SuppressWarnings("unused")
@Comment("NOTE: Do not change!")
@Setting("version")
private int version;
private String version;

public ChatSection getChatSection() {return chat;}

Expand All @@ -64,4 +68,8 @@ public class MainConfig {
public CosmeticSection getCosmeticSection() {
return cosmetics;
}

public DonationSection getDonationSection() {
return donation;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.alpsbte.essentials.config.section;

import org.spongepowered.configurate.objectmapping.ConfigSerializable;
import org.spongepowered.configurate.objectmapping.meta.Comment;

@ConfigSerializable
public record DonationSection(
boolean enabled,
@Comment("After how many minutes the message should be shown")
int minutes,
String url
) {}
9 changes: 8 additions & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,12 @@ cosmetics:
material: 'PAPER'
model-data: ''

# Configurable donation message
donation-message:
enabled: true
# After how many minutes the message should be shown
minutes: 10
url: "https://www.tipeeestream.com/alps-bte/donation"

# NOTE: Do not change
version: 1
version: 1.1
2 changes: 1 addition & 1 deletion src/main/resources/paper-plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Alps-Essentials
version: '1.5'
version: '1.5.1-SNAPSHOT'
main: com.alpsbte.essentials.AlpsEssentials
api-version: '1.21'

Expand Down