Skip to content

Commit

Permalink
Merge pull request #95 from LewMC/next-update
Browse files Browse the repository at this point in the history
Next update
  • Loading branch information
lewmilburn authored Jul 1, 2024
2 parents 004333c + dd10651 commit 3eb3ff1
Show file tree
Hide file tree
Showing 36 changed files with 1,943 additions and 283 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
- 🌐 **Help Translate Essence** - https://crowdin.com/project/lewmc-essence
- ⭐ Enjoying Essence? We'd love to hear your feedback on Spigot. Leave us a review [here](https://www.spigotmc.org/resources/essence.114553/).

[![Crowdin](https://badges.crowdin.net/lewmc-essence/localized.svg)](https://crowdin.com/project/lewmc-essence) [![Maven Build](https://github.com/LewMC/Essence/actions/workflows/maven.yml/badge.svg)](https://github.com/LewMC/Essence/actions/workflows/maven.yml)

## Creating a local copy.

### Clone the repository.
Expand Down
2 changes: 1 addition & 1 deletion crowdin.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
files:
- source: /src/main/resources/language/en-gb.yml
- source: /src/main/resources/language/en-GB.yml
translation: /src/main/resources/language/%locale%.yml
12 changes: 11 additions & 1 deletion dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>net.lewmc</groupId>
<artifactId>essence</artifactId>
<name>Essence</name>
<version>1.5.3</version>
<version>1.6.0</version>
<build>
<resources>
<resource>
Expand Down Expand Up @@ -64,6 +64,10 @@
<id>devmart-other</id>
<url>https://nexuslite.gcnt.net/repos/other/</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<dependency>
Expand All @@ -72,6 +76,12 @@
<version>1.20.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>
</dependencies>
<properties>
<java.version>11</java.version>
Expand Down
12 changes: 11 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>net.lewmc</groupId>
<artifactId>essence</artifactId>
<version>1.5.3</version>
<version>1.6.0</version>
<packaging>jar</packaging>

<name>Essence</name>
Expand Down Expand Up @@ -78,6 +78,10 @@
<id>devmart-other</id>
<url>https://nexuslite.gcnt.net/repos/other/</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

<dependencies>
Expand Down Expand Up @@ -109,5 +113,11 @@
<version>0.3.4</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.github.MilkBowl</groupId>
<artifactId>VaultAPI</artifactId>
<version>1.7</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
124 changes: 96 additions & 28 deletions src/main/java/net/lewmc/essence/Essence.java
Original file line number Diff line number Diff line change
@@ -1,39 +1,35 @@
package net.lewmc.essence;

import com.tcoded.folialib.FoliaLib;
import net.lewmc.essence.commands.KitCommand;
import net.lewmc.essence.commands.TeamCommands;
import net.lewmc.essence.commands.*;
import net.lewmc.essence.commands.admin.*;
import net.lewmc.essence.commands.chat.*;
import net.lewmc.essence.commands.economy.BalanceCommand;
import net.lewmc.essence.commands.economy.PayCommand;
import net.lewmc.essence.commands.inventories.*;
import net.lewmc.essence.commands.EssenceCommands;
import net.lewmc.essence.commands.GamemodeCommands;
import net.lewmc.essence.commands.stats.*;
import net.lewmc.essence.commands.teleportation.*;
import net.lewmc.essence.commands.teleportation.home.DelhomeCommand;
import net.lewmc.essence.commands.teleportation.home.HomeCommand;
import net.lewmc.essence.commands.teleportation.home.HomesCommand;
import net.lewmc.essence.commands.teleportation.home.SethomeCommand;
import net.lewmc.essence.commands.teleportation.home.team.DelthomeCommand;
import net.lewmc.essence.commands.teleportation.home.team.SetthomeCommand;
import net.lewmc.essence.commands.teleportation.home.team.ThomeCommand;
import net.lewmc.essence.commands.teleportation.home.team.ThomesCommand;
import net.lewmc.essence.commands.teleportation.home.*;
import net.lewmc.essence.commands.teleportation.home.team.*;
import net.lewmc.essence.commands.teleportation.tp.*;
import net.lewmc.essence.commands.teleportation.warp.DelwarpCommand;
import net.lewmc.essence.commands.teleportation.warp.SetwarpCommand;
import net.lewmc.essence.commands.teleportation.warp.WarpCommand;
import net.lewmc.essence.commands.teleportation.warp.WarpsCommand;
import net.lewmc.essence.commands.teleportation.warp.*;
import net.lewmc.essence.events.*;
import net.lewmc.essence.tabcompleter.*;
import net.lewmc.essence.utils.CommandUtil;
import net.lewmc.essence.utils.LogUtil;
import net.lewmc.essence.utils.UpdateUtil;
import net.lewmc.essence.utils.economy.VaultEconomy;
import net.milkbowl.vault.economy.Economy;
import org.bstats.bukkit.Metrics;
import org.bstats.charts.SimplePie;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.ServicePriority;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.File;
import java.util.Arrays;
import java.util.HashMap;

/**
Expand All @@ -50,13 +46,25 @@ public class Essence extends JavaPlugin {
*/
public boolean verbose;

/**
* The Vault economy handler.
*/
private Economy economy = null;

/**
* Stores pending teleport requests.
* String = The requested player's name.
* String[] = The requester and if the requested player should teleport to them or not ("true" or "false")
*/
public HashMap<String, String[]> teleportRequests = new HashMap<>();

/**
* Stores message history.
* CommandSender = The receiver.
* CommandSender = The sender.
*/
public HashMap<CommandSender, CommandSender> msgHistory = new HashMap<>();

/**
* This function runs when Essence is enabled.
*/
Expand All @@ -79,7 +87,8 @@ public void onEnable() {
this.log.info("Beginning startup...");
this.log.info("");
int pluginId = 20768; // <-- Replace with the id of your plugin!
new Metrics(this, pluginId);
Metrics metrics = new Metrics(this, pluginId);
metrics.addCustomChart(new SimplePie("language", () -> getConfig().getString("language")));

this.verbose = this.getConfig().getBoolean("verbose");

Expand All @@ -90,22 +99,57 @@ public void onEnable() {
this.log.info("");
}

checkForEssentials();
checkForPaper();
this.checkForEssentials();
this.checkForPaper();

this.initFileSystem();
this.loadCommands();
this.loadEventHandlers();
this.loadTabCompleters();

initFileSystem();
loadCommands();
loadEventHandlers();
loadTabCompleters();
if (!setupEconomy()) {
this.log.warn("Vault not found! Using local economy.");
}

UpdateUtil update = new UpdateUtil(this);
update.VersionCheck();
update.UpdateConfig();
update.UpdateLanguage();

this.checkLanguageSystem();

this.log.info("Startup completed.");
}

/**
* Sets up Vault to use Essence's economy.
* @return boolean - If it could be setup correctly.
*/
private boolean setupEconomy() {
if (getServer().getPluginManager().getPlugin("Vault") == null) {
return false;
}
this.log.info("Vault found, setting up economy service...");

getServer().getServicesManager().register(Economy.class, new VaultEconomy(this), this, ServicePriority.Highest);

RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
if (rsp == null) {
log.severe("No economy service provider found after registration!");
return false;
}

this.economy = rsp.getProvider();

if (this.economy == null) {
this.log.severe("Economy provider is null!");
}

this.log.info("");

return this.economy != null;
}

/**
* Checks if the server is running Paper, and informs the user that they should upgrade if not.
*/
Expand Down Expand Up @@ -147,10 +191,7 @@ private void checkForEssentials() {
private void initFileSystem() {
saveDefaultConfig();

File languageFile = new File(getDataFolder() + File.separator + "language" + File.separator + "en-gb.yml");
if (!languageFile.exists()) {
saveResource("language/en-gb.yml", false);
}
// Language files are in UpdateUtil!

File statsFolder = new File(getDataFolder() + File.separator + "data" + File.separator + "players");
if (!statsFolder.exists() && !statsFolder.mkdirs()) {
Expand Down Expand Up @@ -178,6 +219,23 @@ private void initFileSystem() {
if (!kitsFile.exists()) {
saveResource("data/kits.yml", false);
}

File rulesFile = new File(getDataFolder() + File.separator + "rules.txt");
if (!rulesFile.exists()) {
saveResource("rules.txt", false);
}
}

/**
* Checks the language system.
*/
private void checkLanguageSystem() {
File setLang = new File(getDataFolder() + File.separator + "language" + File.separator + getConfig().getString("language") + ".yml");
if (!setLang.exists()) {
this.log.severe("Language file '"+getConfig().getString("language")+"' does not exist!");
this.log.severe("Please check the file and try again.");
getServer().getPluginManager().disablePlugin(this);
}
}

/**
Expand Down Expand Up @@ -239,13 +297,23 @@ private void loadCommands() {
if (command.isEnabled("back")) { this.getCommand("back").setExecutor(new BackCommand(this)); }

if (command.isEnabled("broadcast")) { this.getCommand("broadcast").setExecutor(new BroadcastCommand(this)); }
if (command.isEnabled("msg")) { this.getCommand("msg").setExecutor(new MsgCommand(this)); }
if (command.isEnabled("reply")) { this.getCommand("reply").setExecutor(new ReplyCommand(this)); }

if (command.isEnabled("pay")) { this.getCommand("pay").setExecutor(new PayCommand(this)); }
if (command.isEnabled("balance")) { this.getCommand("balance").setExecutor(new BalanceCommand(this)); }

if (command.isEnabled("team")) { this.getCommand("team").setExecutor(new TeamCommands(this)); }

if (command.isEnabled("seen")) { this.getCommand("seen").setExecutor(new SeenCommand(this)); }
if (command.isEnabled("info")) { this.getCommand("info").setExecutor(new InfoCommand(this)); }

if (command.isEnabled("rules")) { this.getCommand("rules").setExecutor(new RulesCommands(this)); }
} catch (NullPointerException e) {
this.log.severe("LoadCommands: Unable to load Essence commands.");
this.log.severe("Unable to load Essence commands.");
this.log.severe(e.getMessage());
this.log.severe("");
this.log.severe(Arrays.toString(e.getStackTrace()));
this.log.info("");
}
}
Expand Down
30 changes: 25 additions & 5 deletions src/main/java/net/lewmc/essence/commands/EssenceCommands.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package net.lewmc.essence.commands;

import net.lewmc.essence.utils.FileUtil;
import net.lewmc.essence.utils.MessageUtil;
import net.lewmc.essence.Essence;
import net.lewmc.essence.utils.PermissionHandler;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;

import java.util.Objects;

public class EssenceCommands implements CommandExecutor {
private final Essence plugin;

Expand Down Expand Up @@ -40,13 +44,29 @@ public boolean onCommand(
if ("help".equals(args[0])) {
HelpCommand helpCommand = new HelpCommand(message, args);
return helpCommand.runHelpCommand();
} else if ("reload".equals(args[0])) {
PermissionHandler perms = new PermissionHandler(commandSender, message);
if (perms.has("essence.admin.reload")) {
this.plugin.reloadConfig();
this.plugin.verbose = this.plugin.getConfig().getBoolean("verbose");
message.send("generic", "reload");
return true;
} else {
return perms.not();
}
}
} else {
message.PrivateMessage("about", "version", plugin.getDescription().getVersion());
message.PrivateMessage("about", "description");
message.PrivateMessage("about", "author");
message.PrivateMessage("about", "issues");
message.PrivateMessage("about", "more");
message.send("about", "version", new String[] { plugin.getDescription().getVersion() });
message.send("about", "description");
message.send("about", "author");
if (!Objects.equals(this.plugin.getConfig().getString("language"), "en-GB")) {
FileUtil lang = new FileUtil(this.plugin);
lang.load("language/"+this.plugin.getConfig().getString("language")+".yml");
message.send("about", "authorLang", new String[] { lang.getString("meta.language"), lang.getString("meta.author") });
lang.close();
}
message.send("about", "issues");
message.send("about", "more");

return true;
}
Expand Down
Loading

0 comments on commit 3eb3ff1

Please sign in to comment.