Skip to content

Commit

Permalink
Merge pull request #7 from MylesAndMore/dev
Browse files Browse the repository at this point in the history
refactoring!
  • Loading branch information
MylesAndMore authored Jun 17, 2023
2 parents 3c48bd3 + 19d8ffb commit ee11892
Show file tree
Hide file tree
Showing 20 changed files with 744 additions and 997 deletions.
7 changes: 1 addition & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,13 @@ group 'Tumble'
version '1.0.3'

repositories {
// Use Maven Central for resolving dependencies.
mavenCentral()
// Spigot repo resolve
mavenCentral() // Use Maven Central for resolving dependencies.
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
maven { url 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/' }
// Multiverse repo resolve
maven { url = "https://repo.onarandombox.com/content/groups/public/" }
}

dependencies {
// Spigot 1.19.2 version dependency
compileOnly 'org.spigotmc:spigot-api:1.19.2-R0.1-SNAPSHOT'
// Multiverse dependency
compileOnly 'com.onarandombox.multiversecore:Multiverse-Core:4.3.1'
}
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
rootProject.name = 'tumble'
rootProject.name = 'Tumble'
Original file line number Diff line number Diff line change
@@ -1,39 +1,35 @@
package com.MylesAndMore.tumble;
package com.MylesAndMore.Tumble;

import com.MylesAndMore.tumble.commands.*;
import com.MylesAndMore.tumble.api.Metrics;
import com.MylesAndMore.Tumble.commands.*;
import com.MylesAndMore.Tumble.plugin.Metrics;
import com.MylesAndMore.Tumble.plugin.Constants;
import com.MylesAndMore.Tumble.plugin.EventListener;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;

public class Main extends JavaPlugin{
@Override
public void onEnable() {
// Register our event listener
// Register setup items
getServer().getPluginManager().registerEvents(new EventListener(), this);
// Register commands
this.getCommand("reload").setExecutor(new ReloadCommand());
this.getCommand("reload").setExecutor(new Reload());
this.getCommand("link").setExecutor(new SetWorldConfig());
this.getCommand("start").setExecutor(new StartGame());
this.getCommand("winlocation").setExecutor(new SetWinnerLoc());
this.getCommand("autostart").setExecutor(new SetAutoStart());
// Save the default config file (packaged in the JAR)
this.saveDefaultConfig();

// Register bStats
int pluginId = 16940;
Metrics metrics = new Metrics(this, 16940);
this.saveDefaultConfig(); // Saves the default config file (packaged in the JAR) if we haven't already\

// Check if worlds are null in config
if (TumbleManager.getGameWorld() == null) {
// Check if worlds are null in config and throw warnings if so
if (Constants.getGameWorld() == null) {
Bukkit.getServer().getLogger().warning("[Tumble] It appears you have not configured a game world for Tumble.");
Bukkit.getServer().getLogger().info("[Tumble] If this is your first time running the plugin, you may disregard this message.");
}
if (TumbleManager.getLobbyWorld() == null) {
if (Constants.getLobbyWorld() == null) {
Bukkit.getServer().getLogger().warning("[Tumble] It appears you have not configured a lobby world for Tumble.");
Bukkit.getServer().getLogger().info("[Tumble] If this is your first time running the plugin, you may disregard this message.");
}

// Init message
Bukkit.getServer().getLogger().info("[Tumble] Tumble successfully enabled!");
}
}
22 changes: 22 additions & 0 deletions src/main/java/com/MylesAndMore/Tumble/commands/Reload.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.MylesAndMore.Tumble.commands;

import com.MylesAndMore.Tumble.plugin.Constants;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;

public class Reload implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
if (sender.hasPermission("tumble.reload")) {
Constants.getPlugin().reloadConfig();
sender.sendMessage(ChatColor.GREEN + "Tumble configuration reloaded successfully.");
}
else {
sender.sendMessage(ChatColor.RED + Constants.getPermissionMessage());
}
return true;
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
package com.MylesAndMore.tumble.commands;
package com.MylesAndMore.Tumble.commands;

import com.MylesAndMore.tumble.TumbleManager;
import com.MylesAndMore.Tumble.plugin.Constants;
import org.bukkit.ChatColor;
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 SetAutoStart implements CommandExecutor{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
// Check if sender has perms to run command
public boolean onCommand(CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
if (sender.hasPermission("tumble.autostart")) {
// Check if game and lobby worlds are null
if (TumbleManager.getGameWorld() != null) {
if (TumbleManager.getLobbyWorld() != null) {
// Check the amount of args entered
if (Constants.getGameWorld() != null) {
if (Constants.getLobbyWorld() != null) {
if (args.length == 2) {
// Check the player # argument and parse it into an int
int args0;
Expand All @@ -30,20 +28,19 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
return true;
}
// PlayerAmount & enable/disable were entered
// Check if a playerAmount between 2-8 was entered
if ((args0 >= 2) && (args0 <= 8)) {
if (Objects.equals(args[1], "enable")) {
// Write values to the config
TumbleManager.getPlugin().getConfig().set("autoStart.players", args0);
TumbleManager.getPlugin().getConfig().set("autoStart.enabled", true);
TumbleManager.getPlugin().saveConfig();
Constants.getPlugin().getConfig().set("autoStart.players", args0);
Constants.getPlugin().getConfig().set("autoStart.enabled", true);
Constants.getPlugin().saveConfig();
sender.sendMessage(ChatColor.GREEN + "Configuration saved!");
sender.sendMessage(ChatColor.GREEN + "Run " + ChatColor.GRAY + "/tumble:reload " + ChatColor.GREEN + "the changes to take effect.");
}
else if (Objects.equals(args[1], "disable")) {
TumbleManager.getPlugin().getConfig().set("autoStart.players", args0);
TumbleManager.getPlugin().getConfig().set("autoStart.enabled", false);
TumbleManager.getPlugin().saveConfig();
Constants.getPlugin().getConfig().set("autoStart.players", args0);
Constants.getPlugin().getConfig().set("autoStart.enabled", false);
Constants.getPlugin().saveConfig();
sender.sendMessage(ChatColor.GREEN + "Configuration saved!");
sender.sendMessage(ChatColor.GREEN + "Run " + ChatColor.GRAY + "/tumble:reload " + ChatColor.GREEN + "the changes to take effect.");
}
Expand All @@ -68,8 +65,8 @@ else if (args.length == 1) {
return true;
}
if ((args0 >= 2) && (args0 <= 8)) {
TumbleManager.getPlugin().getConfig().set("autoStart.players", args0);
TumbleManager.getPlugin().saveConfig();
Constants.getPlugin().getConfig().set("autoStart.players", args0);
Constants.getPlugin().saveConfig();
sender.sendMessage(ChatColor.GREEN + "Configuration saved!");
sender.sendMessage(ChatColor.GREEN + "Run " + ChatColor.GRAY + "/tumble:reload " + ChatColor.GREEN + "the changes to take effect.");
}
Expand All @@ -90,7 +87,7 @@ else if (args.length == 1) {
}
}
else {
sender.sendMessage(ChatColor.RED + TumbleManager.getPermissionMessage());
sender.sendMessage(ChatColor.RED + Constants.getPermissionMessage());
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
package com.MylesAndMore.tumble.commands;
package com.MylesAndMore.Tumble.commands;

import com.MylesAndMore.tumble.TumbleManager;
import com.MylesAndMore.Tumble.plugin.Constants;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

public class SetWinnerLoc implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
// Check if sender has perms to run command
public boolean onCommand(CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
if (sender.hasPermission("tumble.winlocation")) {
// Check if the lobby world has been configured
if (TumbleManager.getLobbyWorld() != null) {
// Check if the sender is a player
if (Constants.getLobbyWorld() != null) {
if (sender instanceof Player) {
// Check the sender entered the correct number of args
if (args.length == 3) {
Expand All @@ -32,12 +30,12 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
} catch (Exception e){
sender.sendMessage(ChatColor.RED + "Invalid input arguments.");
}
// Check if any of the args were 0 (this will cause future problems so we prevent it here)
// Check if any of the args were 0 (this will cause future problems, so we prevent it here)
if (!((args0 == 0) || (args1 == 0) || (args2 == 0))) {
TumbleManager.getPlugin().getConfig().set("winnerTeleport.x", args0);
TumbleManager.getPlugin().getConfig().set("winnerTeleport.y", args1);
TumbleManager.getPlugin().getConfig().set("winnerTeleport.z", args2);
TumbleManager.getPlugin().saveConfig();
Constants.getPlugin().getConfig().set("winnerTeleport.x", args0);
Constants.getPlugin().getConfig().set("winnerTeleport.y", args1);
Constants.getPlugin().getConfig().set("winnerTeleport.z", args2);
Constants.getPlugin().saveConfig();
sender.sendMessage(ChatColor.GREEN + "Win location successfully set!");
sender.sendMessage(ChatColor.GREEN + "Run " + ChatColor.GRAY + "/tumble:reload " + ChatColor.GREEN + "the changes to take effect.");
}
Expand All @@ -52,10 +50,10 @@ else if (args.length == 0) {
// if so, check if any of their locations are zero
if (!((senderPos.getX() == 0) || (senderPos.getY() == 0) || (senderPos.getZ() == 0))) {
// set the config values to their current pos
TumbleManager.getPlugin().getConfig().set("winnerTeleport.x", senderPos.getX());
TumbleManager.getPlugin().getConfig().set("winnerTeleport.y", senderPos.getY());
TumbleManager.getPlugin().getConfig().set("winnerTeleport.z", senderPos.getZ());
TumbleManager.getPlugin().saveConfig();
Constants.getPlugin().getConfig().set("winnerTeleport.x", senderPos.getX());
Constants.getPlugin().getConfig().set("winnerTeleport.y", senderPos.getY());
Constants.getPlugin().getConfig().set("winnerTeleport.z", senderPos.getZ());
Constants.getPlugin().saveConfig();
sender.sendMessage(ChatColor.GREEN + "Win location successfully set!");
sender.sendMessage(ChatColor.GREEN + "Run " + ChatColor.GRAY + "/tumble:reload " + ChatColor.GREEN + "the changes to take effect.");
}
Expand All @@ -68,9 +66,7 @@ else if (args.length == 0) {
return false;
}
}
// Check if the sender is the console
else if (sender instanceof ConsoleCommandSender) {
// Check if the correct # of args were entered
if (args.length == 3) {
double args0 = 0;
double args1 = 0;
Expand All @@ -84,12 +80,11 @@ else if (sender instanceof ConsoleCommandSender) {
} catch (Exception e){
sender.sendMessage(ChatColor.RED + "Invalid input arguments.");
}
// Check if any of the args were 0 (this will cause future problems so we prevent it here)
if (!((args0 == 0) || (args1 == 0) || (args2 == 0))) {
TumbleManager.getPlugin().getConfig().set("winnerTeleport.x", args0);
TumbleManager.getPlugin().getConfig().set("winnerTeleport.y", args1);
TumbleManager.getPlugin().getConfig().set("winnerTeleport.z", args2);
TumbleManager.getPlugin().saveConfig();
Constants.getPlugin().getConfig().set("winnerTeleport.x", args0);
Constants.getPlugin().getConfig().set("winnerTeleport.y", args1);
Constants.getPlugin().getConfig().set("winnerTeleport.z", args2);
Constants.getPlugin().saveConfig();
sender.sendMessage(ChatColor.GREEN + "Win location successfully set!");
sender.sendMessage(ChatColor.GREEN + "Run " + ChatColor.GRAY + "/tumble:reload " + ChatColor.GREEN + "the changes to take effect.");
}
Expand All @@ -108,7 +103,7 @@ else if (sender instanceof ConsoleCommandSender) {
}
}
else {
sender.sendMessage(ChatColor.RED + TumbleManager.getPermissionMessage());
sender.sendMessage(ChatColor.RED + Constants.getPermissionMessage());
}
return true;
}
Expand Down
Loading

0 comments on commit ee11892

Please sign in to comment.