Files
src
build.gradle
settings.gradle
Code
14 1,139
src/main/java/com/kodari/youtubersonly/YouTubersOnlyPlugin.java
package com.kodari.youtubersonly;
import com.kodari.youtubersonly.command.SubscriberCommand;
import com.kodari.youtubersonly.command.WithdrawCommand;
import com.kodari.youtubersonly.listener.SubscriberBottleListener;
import com.kodari.youtubersonly.listener.SubscriberPlayerListener;
import com.kodari.youtubersonly.placeholder.SubscribersExpansion;
import com.kodari.youtubersonly.scoreboard.SubscriberScoreboard;
import com.kodari.youtubersonly.service.MessageService;
import com.kodari.youtubersonly.storage.SubscriberManager;
import org.bukkit.BanList;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class YouTubersOnlyPlugin extends JavaPlugin {
private SubscriberManager subscriberManager;
private MessageService messageService;
private SubscriberScoreboard subscriberScoreboard;
private SubscribersExpansion subscribersExpansion;
@Override
public void onEnable() {
saveDefaultConfig();
this.messageService = new MessageService(this);
this.subscriberManager = new SubscriberManager(this, this::eliminatePlayer);
this.subscriberManager.load();
this.subscriberManager.startAutoSave();
if (getConfig().getBoolean("scoreboard", true)) {
this.subscriberScoreboard = new SubscriberScoreboard(this, subscriberManager, messageService);
this.subscriberScoreboard.start();
}
SubscriberCommand subscriberCommand = new SubscriberCommand(
subscriberManager,
messageService,
subscriberScoreboard
);
WithdrawCommand withdrawCommand = new WithdrawCommand(
subscriberManager,
messageService,
new com.kodari.youtubersonly.service.SubscriberBottleService(this, subscriberManager, messageService)
);
getCommand("subscribers").setExecutor(subscriberCommand);
getCommand("subscribers").setTabCompleter(subscriberCommand);
getCommand("withdraw").setExecutor(withdrawCommand);
getCommand("withdraw").setTabCompleter(withdrawCommand);
Bukkit.getPluginManager().registerEvents(
new SubscriberBottleListener(this, subscriberManager, messageService),
this
);
Bukkit.getPluginManager().registerEvents(
new SubscriberPlayerListener(subscriberManager, subscriberScoreboard),
this
);
if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
this.subscribersExpansion = new SubscribersExpansion(this, subscriberManager);
this.subscribersExpansion.register();
}
}
@Override
public void onDisable() {
if (subscribersExpansion != null) {
subscribersExpansion.unregister();
}
if (subscriberScoreboard != null) {
subscriberScoreboard.stop();
}
if (subscriberManager != null) {
subscriberManager.shutdown();
}
}
private void eliminatePlayer(java.util.UUID uniqueId) {
Player onlinePlayer = Bukkit.getPlayer(uniqueId);
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uniqueId);
String playerName = onlinePlayer != null
? onlinePlayer.getName()
: offlinePlayer.getName();
if (playerName == null || playerName.isBlank()) {
playerName = uniqueId.toString();
}
Bukkit.broadcastMessage(messageService.format("eliminated", "player", playerName));
Bukkit.getBanList(BanList.Type.NAME).addBan(
playerName,
"You have lost all of your subscribers.",
null,
getName()
);
if (onlinePlayer != null) {
onlinePlayer.kickPlayer(messageService.format("eliminated", "player", playerName));
}
}
}