Skip to content

Commit

Permalink
Config & Features
Browse files Browse the repository at this point in the history
- Reworked configuration mechanisms
- Added interface SubCommand for standerdization & simplification
- Added option 'shapeCircle', when set to false a square will be used
  • Loading branch information
TobiasDeBruijn committed Jun 13, 2021
1 parent 4909d8a commit 295b5cc
Show file tree
Hide file tree
Showing 23 changed files with 615 additions and 332 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ dependencies {
implementation 'commons-io:commons-io:2.6'
implementation 'dev.array21:bukkit-reflection-util:1.0'
implementation 'dev.array21:pluginstatlib:1.0.5'
implementation 'dev.array21:classvalidator:1.0.0'
implementation 'com.github.TheDutchMC:HttpLib:1.1'

}
Expand Down
127 changes: 0 additions & 127 deletions src/main/java/nl/thedutchmc/harotorch/ConfigurationHandler.java

This file was deleted.

53 changes: 30 additions & 23 deletions src/main/java/nl/thedutchmc/harotorch/HaroTorch.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import net.md_5.bungee.api.ChatColor;
import nl.thedutchmc.harotorch.commands.TorchCommandExecutor;
import nl.thedutchmc.harotorch.commands.TorchCommandTabCompleter;
import nl.thedutchmc.harotorch.config.ConfigHandler;
import nl.thedutchmc.harotorch.config.ConfigManifest;
import nl.thedutchmc.harotorch.events.*;
import nl.thedutchmc.harotorch.lang.LangHandler;
import nl.thedutchmc.harotorch.torch.Recipe;
Expand All @@ -21,13 +23,17 @@

public class HaroTorch extends JavaPlugin {

private static ConfigurationHandler CONFIG;
private static HaroTorch INSTANCE;

private ConfigHandler configHandler;

public static double RANGE;
public static final String NMS_VERSION = Bukkit.getServer().getClass().getPackage().getName().substring(23);

@Override
public void onEnable() {
INSTANCE = this;

new Thread(new Runnable() {
@Override
public void run() {
Expand All @@ -36,15 +42,16 @@ public void run() {
}
}, "HaroTorch UpdateChecker Thread").start();

CONFIG = new ConfigurationHandler(this);
CONFIG.loadConfig();
String jVersion = System.getProperty("java.version");
System.out.println(jVersion);
if(!CONFIG.disableStat) {
this.configHandler = new ConfigHandler(this);
this.configHandler.readConfig();

ConfigManifest manifest = this.configHandler.getManifest();

if(!manifest.disableStat) {
PluginStat stat = PluginStatBuilder.createDefault()
.setLogErrFn(this::logWarn)
.setSetUuidFn(CONFIG::setUuid)
.setUuid(CONFIG.statUuid)
.setLogErrFn(HaroTorch::logWarn)
.setSetUuidFn(this.configHandler::setStatUuid)
.setUuid(manifest.statUuid)
.build();

stat.start();
Expand All @@ -54,9 +61,9 @@ public void run() {
LangHandler langHandler = new LangHandler(this);
langHandler.load();

this.logInfo(LangHandler.activeLang.getLangMessages().get("welcome"));
HaroTorch.logInfo(LangHandler.activeLang.getLangMessages().get("welcome"));

RANGE = Math.pow(CONFIG.torchRange, 2);
RANGE = Math.pow(manifest.torchRange, 2);

//TorchHandler
TorchHandler torchHandler = new TorchHandler(this);
Expand All @@ -67,9 +74,9 @@ public void run() {
this.getServer().addRecipe(recipe.getTorchRecipe());

//Minecraft events
Bukkit.getPluginManager().registerEvents(new BlockBreakEventListener(), this);
Bukkit.getPluginManager().registerEvents(new BlockBreakEventListener(this), this);
Bukkit.getPluginManager().registerEvents(new BlockPlaceEventListener(this), this);
Bukkit.getPluginManager().registerEvents(new CreatureSpawnEventListener(), this);
Bukkit.getPluginManager().registerEvents(new CreatureSpawnEventListener(this), this);
Bukkit.getPluginManager().registerEvents(new BlockFromToEventListener(), this);
Bukkit.getPluginManager().registerEvents(new BlockExplodeEventListener(), this);
Bukkit.getPluginManager().registerEvents(new EntityExplodeEventListener(), this);
Expand All @@ -84,7 +91,7 @@ public void run() {
this.getCommand("torch").setTabCompleter(new TorchCommandTabCompleter());

//Scheduler for particles
if(CONFIG.enableTorchParticles) {
if(manifest.enableTorchParticles) {
new BukkitRunnable() {

@Override
Expand All @@ -108,23 +115,23 @@ public void run() {

@Override
public void onDisable() {
logInfo(LangHandler.activeLang.getLangMessages().get("goodbye"));
HaroTorch.logInfo("Thankyou for using HaroTorch. Have a good day!");
}

public void logInfo(Object log) {
this.getLogger().info(log.toString());
public static void logInfo(Object log) {
INSTANCE.getLogger().info(log.toString());
}

public void logWarn(Object log) {
this.getLogger().warning(log.toString());
}

public static ConfigurationHandler getConfigHandler() {
return HaroTorch.CONFIG;
public static void logWarn(Object log) {
INSTANCE.getLogger().warning(log.toString());
}

public static String getMessagePrefix() {
return ChatColor.GRAY + "[" + ChatColor.AQUA + "HT" + ChatColor.GRAY + "] " + ChatColor.RESET;
}

public ConfigManifest getConfigManifest() {
return this.configHandler.getManifest();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package nl.thedutchmc.harotorch.commands;

import org.bukkit.command.CommandSender;

import nl.thedutchmc.harotorch.HaroTorch;

public interface SubCommand {
public boolean run(HaroTorch plugin, CommandSender sender, String[] args);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package nl.thedutchmc.harotorch.commands;

import java.util.HashMap;

import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
Expand All @@ -15,78 +17,37 @@

public class TorchCommandExecutor implements CommandExecutor {

private HaroTorch plugin;
private final HaroTorch plugin;
private final HashMap<String, SubCommand> subcommands;

public TorchCommandExecutor(HaroTorch plugin) {
this.plugin = plugin;

HashMap<String, SubCommand> subCommands = new HashMap<>();
subCommands.put("help", new HelpExecutor());
subCommands.put("version", new VersionExecutor());
subCommands.put("convert", new ConvertExecutor());
subCommands.put("give", new GiveExecutor());
subCommands.put("highlight", new HighlightExecutor());
subCommands.put("aoe", new HighlightAreaOfEffectExecutor());
this.subcommands = subCommands;
}

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {

if(args.length < 1) {
String msg = LangHandler.activeLang.getLangMessages().get("missingArguments").replaceAll("%HELP_COMMAND%", ChatColor.RED + "/torch help" + ChatColor.GOLD);
sender.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.GOLD + msg);
return true;
}

if(args[0].equalsIgnoreCase("help")) {
if(!sender.hasPermission("harotorch.help")) {
sender.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.RED + LangHandler.activeLang.getLangMessages().get("noPermission"));
return true;
}

return HelpExecutor.help(sender);
}

else if(args[0].equalsIgnoreCase("version")) {
if(!sender.hasPermission("harotorch.version")) {
sender.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.RED + LangHandler.activeLang.getLangMessages().get("noPermission"));
return true;
}

return VersionExecutor.version(sender, plugin);
}

else if(args[0].equalsIgnoreCase("convert")) {
if(!sender.hasPermission("harotorch.convert")) {
sender.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.RED + LangHandler.activeLang.getLangMessages().get("noPermission"));
return true;
}

return ConvertExecutor.convert(sender);
}

else if(args[0].equalsIgnoreCase("give")) {
if(!sender.hasPermission("harotorch.give")) {
sender.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.RED + LangHandler.activeLang.getLangMessages().get("noPermission"));
return true;
}

return GiveExecutor.give(sender, args);
}

else if(args[0].equalsIgnoreCase("highlight")) {
if(!sender.hasPermission("harotorch.highlight")) {
sender.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.RED + LangHandler.activeLang.getLangMessages().get("noPermission"));
return true;
}

return HighlightExecutor.highlight(sender, args, plugin);
}

else if(args[0].equalsIgnoreCase("aoe")) {
if(!sender.hasPermission("harotorch.aoe")) {
sender.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.RED + LangHandler.activeLang.getLangMessages().get("noPermission"));
return true;
}

HighlightAreaOfEffectExecutor.aoe(sender, plugin);

SubCommand c = this.subcommands.get(args[0]);
if(!sender.hasPermission("harotorch." + args[0])) {
sender.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.RED + LangHandler.activeLang.getLangMessages().get("noPermission"));
return true;
}

return false;
return c.run(this.plugin, sender, args);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
import net.md_5.bungee.api.ChatColor;
import nl.thedutchmc.haro_torch.plugin.torch.Torchy;
import nl.thedutchmc.harotorch.HaroTorch;
import nl.thedutchmc.harotorch.commands.SubCommand;
import nl.thedutchmc.harotorch.lang.LangHandler;
import nl.thedutchmc.harotorch.torch.Torch;
import nl.thedutchmc.harotorch.torch.TorchHandler;

public class ConvertExecutor {
public class ConvertExecutor implements SubCommand {

public static boolean convert(CommandSender sender) {
public boolean run(HaroTorch plugin, CommandSender sender, String[] args) {

if(Bukkit.getPluginManager().getPlugin("HaroTorch") == null) {
sender.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.GOLD + LangHandler.activeLang.getLangMessages().get("v1NotInstalledMessage"));
Expand Down
Loading

0 comments on commit 295b5cc

Please sign in to comment.