Skip to content
Open
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
10 changes: 6 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@

<groupId>com.tcoded</groupId>
<artifactId>PlayerBountiesPlus</artifactId>
<version>1.0.0</version>
<version>1.0.0-ALPHA-02</version>
<packaging>jar</packaging>

<name>PlayerBountiesPlus</name>

<description>Claim bounties only if you are not on the same clan</description>
<properties>
<java.version>1.8</java.version>
<java.version>11</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<url>https://tcoded.com</url>

<build>
<defaultGoal>clean package</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down Expand Up @@ -86,11 +86,13 @@
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>23.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.Loving11ish</groupId>
<artifactId>ClansLite</artifactId>
<version>v1.3.6</version>
<version>v1.3.7</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
197 changes: 140 additions & 57 deletions src/main/java/com/tcoded/playerbountiesplus/PlayerBountiesPlus.java
Original file line number Diff line number Diff line change
@@ -1,94 +1,177 @@
package com.tcoded.playerbountiesplus;

import com.tcoded.playerbountiesplus.command.BountyCommand;
import com.tcoded.playerbountiesplus.hook.VaultHook;
import com.tcoded.playerbountiesplus.hook.clan.AbstractClanHook;
import com.tcoded.playerbountiesplus.command.BountyCommandTabCompleter;
import com.tcoded.playerbountiesplus.files.BountiesFileManager;
import com.tcoded.playerbountiesplus.hooks.VaultHook;
import com.tcoded.playerbountiesplus.hooks.clan.AbstractClanHook;
import com.tcoded.playerbountiesplus.listener.DeathListener;
import org.bukkit.command.PluginCommand;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.event.HandlerList;
import org.bukkit.plugin.java.JavaPlugin;
import com.tcoded.playerbountiesplus.utils.BountiesStorageUtils;
import com.tcoded.playerbountiesplus.utils.ColorUtils;
import org.bukkit.Bukkit;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin;;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.logging.Logger;

public final class PlayerBountiesPlus extends JavaPlugin {

private File bountiesFile;
private FileConfiguration bountiesConfig;
private final PluginDescriptionFile pluginInfo = getDescription();
private final String pluginVersion = pluginInfo.getVersion();
Logger logger = this.getLogger();

private static PlayerBountiesPlus plugin;
public BountiesFileManager bountiesFileManager;

private HashMap<UUID, Integer> bounties;
private VaultHook vault;
private AbstractClanHook clanHook;

@Override
public void onEnable() {
// Config
//Plugin startup logic
plugin = this;

//Server version compatibility check
if (!(Bukkit.getServer().getVersion().contains("1.13")||Bukkit.getServer().getVersion().contains("1.14")||
Bukkit.getServer().getVersion().contains("1.15")||Bukkit.getServer().getVersion().contains("1.16")||
Bukkit.getServer().getVersion().contains("1.17")||Bukkit.getServer().getVersion().contains("1.18")||
Bukkit.getServer().getVersion().contains("1.19"))){
logger.warning(ColorUtils.translateColorCodes("&4-------------------------------------------"));
logger.warning(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &4This plugin is only supported on the Minecraft versions listed below:"));
logger.warning(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &41.13.x"));
logger.warning(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &41.14.x"));
logger.warning(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &41.15.x"));
logger.warning(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &41.16.x"));
logger.warning(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &41.17.x"));
logger.warning(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &41.18.x"));
logger.warning(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &41.19.x"));
logger.warning(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &4Is now disabling!"));
logger.warning(ColorUtils.translateColorCodes("&4-------------------------------------------"));
Bukkit.getPluginManager().disablePlugin(this);
return;
}else {
logger.info(ColorUtils.translateColorCodes("&a-------------------------------------------"));
logger.info(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &aA supported Minecraft version has been detected"));
logger.info(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &6Continuing plugin startup"));
logger.info(ColorUtils.translateColorCodes("&a-------------------------------------------"));
}

//Load the plugin configs
getConfig().options().copyDefaults();
saveDefaultConfig();

// Bounties file
String bountiesFileName = "bounties.yml";
bountiesFile = new File(bountiesFileName);
this.saveResource(bountiesFileName, false);
bountiesConfig = YamlConfiguration.loadConfiguration(bountiesFile);
//Load bounties.yml
this.bountiesFileManager = new BountiesFileManager();
bountiesFileManager.BountiesFileManager(this);

// Load bounties
Set<String> keys = bountiesConfig.getKeys(false);
for (String key: keys) {
//Restore bounties to hashmap
if (bountiesFileManager.getBountiesConfig().contains("bounties.data")){
try {
this.bounties.put(UUID.fromString(key), bountiesConfig.getInt(key));
} catch (Exception ex) {
ex.printStackTrace();
BountiesStorageUtils bountiesStorageUtils = new BountiesStorageUtils();
bountiesStorageUtils.restoreBounties();
bountiesStorageUtils.runStrippedBountyValuePopulate();
} catch (IOException e) {
logger.severe(ColorUtils.translateColorCodes("-------------------------------------------"));
logger.severe(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &4Failed to load data from bounties.yml!"));
logger.severe(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &4See below for errors!"));
logger.severe(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &4Disabling Plugin!"));
e.printStackTrace();
logger.severe(ColorUtils.translateColorCodes("-------------------------------------------"));
Bukkit.getPluginManager().disablePlugin(this);
return;
}
}

// Hooks
//Load plugin hooks
this.vault = new VaultHook(this);
this.vault.init();
if (!this.vault.init()){
logger.severe(ColorUtils.translateColorCodes("-------------------------------------------"));
logger.severe(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &4Failed to hooks into Vault"));
logger.severe(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &4This plugin requires Vault"));
logger.severe(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &4Please install Vault and restart your server!"));
logger.severe(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &4Disabling Plugin!"));
Bukkit.getPluginManager().disablePlugin(this);
logger.severe(ColorUtils.translateColorCodes("-------------------------------------------"));
return;
}else {
logger.info(ColorUtils.translateColorCodes("-------------------------------------------"));
logger.info(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &aSuccessfully hooked into Vault"));
logger.info(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &6Continuing startup"));
logger.info(ColorUtils.translateColorCodes("-------------------------------------------"));
}
this.clanHook = AbstractClanHook.findClanHook(this);
if (clanHook == null){
logger.severe(ColorUtils.translateColorCodes("-------------------------------------------"));
logger.severe(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &4Failed to hooks into ClansLite"));
logger.severe(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &4This plugin requires ClansLite"));
logger.severe(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &4Please install ClansLite and restart your server!"));
logger.severe(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &4Disabling Plugin!"));
logger.severe(ColorUtils.translateColorCodes("-------------------------------------------"));
Bukkit.getPluginManager().disablePlugin(this);
return;
}else {
logger.info(ColorUtils.translateColorCodes("-------------------------------------------"));
logger.info(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &aSuccessfully hooked into ClansLite"));
logger.info(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &6Continuing startup"));
logger.info(ColorUtils.translateColorCodes("-------------------------------------------"));
}

// Commands
PluginCommand bountyCmd = this.getCommand("bounty");
BountyCommand bountyExec = new BountyCommand(this);
bountyCmd.setExecutor(bountyExec);
bountyCmd.setTabCompleter(bountyExec);
//Register commands
this.getCommand("bounty").setExecutor(new BountyCommand());

// Listener
this.getServer().getPluginManager().registerEvents(new DeathListener(this), this);
}
//Register tab completer
this.getCommand("bounty").setTabCompleter(new BountyCommandTabCompleter());

@Override
public void onDisable() {
HandlerList.unregisterAll(this);
}
//Register listeners
this.getServer().getPluginManager().registerEvents(new DeathListener(), this);

public HashMap<UUID, Integer> getBounties() {
return this.bounties;
//Plugin startup message
logger.info(ColorUtils.translateColorCodes("-------------------------------------------"));
logger.info(ColorUtils.translateColorCodes("&6ClansLite: &3Plugin by: &b&lLoving11ish & TCoded"));
logger.info(ColorUtils.translateColorCodes("&6ClansLite: &3has been loaded successfully"));
logger.info(ColorUtils.translateColorCodes("&6ClansLite: &3Plugin Version: &d&l" + pluginVersion));
logger.info(ColorUtils.translateColorCodes("-------------------------------------------"));
}

public void saveBounties() {
// Clear existing
Set<String> keys = bountiesConfig.getKeys(false);
for (String key: keys) {
bountiesConfig.set(key, null);
}
@Override
public void onDisable(){
//Plugin shutdown logic
BountiesStorageUtils bountiesStorageUtils = new BountiesStorageUtils();

// Write changes
for (Map.Entry<UUID, Integer> entry : this.bounties.entrySet()) {
this.bountiesConfig.set(entry.getKey().toString(), entry.getValue());
//Safely stop the background tasks if running
logger.info(ColorUtils.translateColorCodes("-------------------------------------------"));
logger.info(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &3Plugin by: &b&lLoving11ish & TCoded"));
try {
if (Bukkit.getScheduler().isCurrentlyRunning(bountiesStorageUtils.taskID1)||Bukkit.getScheduler().isQueued(bountiesStorageUtils.taskID1)){
Bukkit.getScheduler().cancelTask(bountiesStorageUtils.taskID1);
}
logger.info(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &3Background tasks have disabled successfully!"));
}catch (Exception e){
logger.info(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &3Background tasks have disabled successfully!"));
}

// Save to file
try {
this.bountiesConfig.save(this.bountiesFile);
} catch (IOException e) {
e.printStackTrace();
//Save Bounties HashMap to bounties.yml
if (!bountiesStorageUtils.getRawBountiesList().isEmpty()){
try {
bountiesStorageUtils.saveBounties();
logger.info(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &3All bounties saved to bounties.yml successfully!"));
} catch (IOException e) {
logger.severe(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &4Failed to save bounties to bounties.yml!"));
logger.severe(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &4See below error for reason!"));
e.printStackTrace();
}
}

//Final plugin shutdown message
logger.info(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &3Plugin Version: &d&l" + pluginVersion));
logger.info(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &3Has been shutdown successfully"));
logger.info(ColorUtils.translateColorCodes("&6PlayerBountiesPlus: &3Goodbye!"));
logger.info(ColorUtils.translateColorCodes("-------------------------------------------"));
}

public static PlayerBountiesPlus getPlugin() {
return plugin;
}

public VaultHook getVaultHook() {
Expand Down

This file was deleted.

Loading