From 0d3c83b65fbf1af190a62729b035993dc6a8e712 Mon Sep 17 00:00:00 2001 From: alisolarflare Date: Wed, 2 Nov 2016 16:17:26 -0400 Subject: [PATCH] Fully rethought the structure of what I'm trying to do --- .../modules/events/uhc/MatchState.java | 5 --- .../modules/events/uhc/UHCMatch.java | 16 --------- .../modules/events/uhc/UHCModule.java | 11 +++--- .../modules/events/uhc/commands/AddToUHC.java | 2 +- .../events/uhc/commands/StartMatch.java | 35 +++++++++++++++++++ ...istener.java => MatchCyclingListener.java} | 6 ++-- .../events/uhc/listeners/MatchMainLoop.java | 12 +++++++ .../events/uhc/listeners/PlayerPowerTask.java | 24 ------------- .../modules/events/uhc/memory/MatchState.java | 5 +++ .../events/uhc/memory/PlayerPowerModule.java | 5 --- .../modules/events/uhc/memory/UHCMatch.java | 34 ++++++++++++++++++ 11 files changed, 96 insertions(+), 59 deletions(-) delete mode 100644 src/alisolarflare/modules/events/uhc/MatchState.java delete mode 100644 src/alisolarflare/modules/events/uhc/UHCMatch.java create mode 100644 src/alisolarflare/modules/events/uhc/commands/StartMatch.java rename src/alisolarflare/modules/events/uhc/listeners/{PlayerPowerCyclingListener.java => MatchCyclingListener.java} (63%) create mode 100644 src/alisolarflare/modules/events/uhc/listeners/MatchMainLoop.java delete mode 100644 src/alisolarflare/modules/events/uhc/listeners/PlayerPowerTask.java create mode 100644 src/alisolarflare/modules/events/uhc/memory/MatchState.java delete mode 100644 src/alisolarflare/modules/events/uhc/memory/PlayerPowerModule.java create mode 100644 src/alisolarflare/modules/events/uhc/memory/UHCMatch.java diff --git a/src/alisolarflare/modules/events/uhc/MatchState.java b/src/alisolarflare/modules/events/uhc/MatchState.java deleted file mode 100644 index 9a6e87c..0000000 --- a/src/alisolarflare/modules/events/uhc/MatchState.java +++ /dev/null @@ -1,5 +0,0 @@ -package alisolarflare.modules.events.uhc; - -public enum MatchState { - SETUP, INTRO, PEACE, TENSION, POWER, END -} diff --git a/src/alisolarflare/modules/events/uhc/UHCMatch.java b/src/alisolarflare/modules/events/uhc/UHCMatch.java deleted file mode 100644 index 9b4bad7..0000000 --- a/src/alisolarflare/modules/events/uhc/UHCMatch.java +++ /dev/null @@ -1,16 +0,0 @@ -package alisolarflare.modules.events.uhc; - -import java.util.ArrayList; -import java.util.List; - -import org.bukkit.entity.Player; - -/** - * Class that contains the data for a single UltraHardcore Match, - * which represents a single game. - * @author Alisolarflare - */ -public class UHCMatch { - public List matchPlayerUsernames = new ArrayList(); - -} diff --git a/src/alisolarflare/modules/events/uhc/UHCModule.java b/src/alisolarflare/modules/events/uhc/UHCModule.java index 17fa970..77f3ec2 100644 --- a/src/alisolarflare/modules/events/uhc/UHCModule.java +++ b/src/alisolarflare/modules/events/uhc/UHCModule.java @@ -4,10 +4,11 @@ import org.bukkit.plugin.java.JavaPlugin; import alisolarflare.modules.Module; import alisolarflare.modules.events.uhc.commands.AddToUHC; +import alisolarflare.modules.events.uhc.commands.StartMatch; +import alisolarflare.modules.events.uhc.memory.UHCMatch; public class UHCModule extends Module { - public UHCMatch generalMemory; - public String[] finiteStates = {"SETUP", "INTRO", "PEACE", "TENSION", "POWER", "END"}; + public UHCMatch match; public void register(JavaPlugin plugin){ registerCommands(plugin); @@ -17,10 +18,10 @@ public class UHCModule extends Module { private void registerListeners(JavaPlugin plugin) { } private void registerCommands(JavaPlugin plugin) { - // TODO Auto-generated method stub - registerCommand(plugin, "addToUHC", new AddToUHC(this.generalMemory)); + registerCommand(plugin, "addToUHC", new AddToUHC(this.match)); + registerCommand(plugin, "startMatch", new StartMatch(this.match)); } private void registerMemoryUnits(JavaPlugin plugin){ - generalMemory = new UHCMatch(); + match = new UHCMatch(plugin.getConfig(), plugin.getConfig().getString("UHCMatchState")); } } diff --git a/src/alisolarflare/modules/events/uhc/commands/AddToUHC.java b/src/alisolarflare/modules/events/uhc/commands/AddToUHC.java index 227a7c7..aa0ed34 100644 --- a/src/alisolarflare/modules/events/uhc/commands/AddToUHC.java +++ b/src/alisolarflare/modules/events/uhc/commands/AddToUHC.java @@ -5,7 +5,7 @@ import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import alisolarflare.modules.events.uhc.UHCMatch; +import alisolarflare.modules.events.uhc.memory.UHCMatch; /** * This class handles the specific command /addToUHC which, in-game, diff --git a/src/alisolarflare/modules/events/uhc/commands/StartMatch.java b/src/alisolarflare/modules/events/uhc/commands/StartMatch.java new file mode 100644 index 0000000..8aa5d07 --- /dev/null +++ b/src/alisolarflare/modules/events/uhc/commands/StartMatch.java @@ -0,0 +1,35 @@ +package alisolarflare.modules.events.uhc.commands; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import alisolarflare.modules.events.uhc.memory.MatchState; +import alisolarflare.modules.events.uhc.memory.UHCMatch; + +public class StartMatch implements CommandExecutor { + private UHCMatch match; + public StartMatch(UHCMatch match){ + this.match = match; + } + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (!(sender instanceof Player)){ + sender.sendMessage("You must be a player to use this command! Contact a dev if you think this is wrong"); + } + if (match.getMatchState() == MatchState.NULL) + sender.sendMessage("There is no match to begin."); + else if (match.getMatchState() == MatchState.IDLE) + sender.sendMessage("There is currently a match ready... Activating..."); + else if (match.getMatchState() == MatchState.WAITING) + sender.sendMessage("There currently a match planned for: TIME:TIME:TIME"); + else if (match.getMatchState() == MatchState.END) + sender.sendMessage("The match has ended! Would you like to restart?"); + else + sender.sendMessage("You cannot start a match now, one is already in progress!"); + + return false; + + } +} diff --git a/src/alisolarflare/modules/events/uhc/listeners/PlayerPowerCyclingListener.java b/src/alisolarflare/modules/events/uhc/listeners/MatchCyclingListener.java similarity index 63% rename from src/alisolarflare/modules/events/uhc/listeners/PlayerPowerCyclingListener.java rename to src/alisolarflare/modules/events/uhc/listeners/MatchCyclingListener.java index eee8820..53d5949 100644 --- a/src/alisolarflare/modules/events/uhc/listeners/PlayerPowerCyclingListener.java +++ b/src/alisolarflare/modules/events/uhc/listeners/MatchCyclingListener.java @@ -9,10 +9,10 @@ import org.bukkit.scheduler.BukkitTask; * ghostie powers if an Ultrahardcore Match is going on, * and it's time for powers to activate */ -public class PlayerPowerCyclingListener implements Listener { +public class MatchCyclingListener implements Listener { public BukkitTask PowerCyclingTask; - public PlayerPowerCyclingListener(JavaPlugin plugin){ - PowerCyclingTask = (new PlayerPowerTask(plugin)).runTaskTimer(plugin, 20, 20); + public MatchCyclingListener(JavaPlugin plugin){ + PowerCyclingTask = (new MatchMainLoop()).runTaskTimer(plugin, 20, 20); } } diff --git a/src/alisolarflare/modules/events/uhc/listeners/MatchMainLoop.java b/src/alisolarflare/modules/events/uhc/listeners/MatchMainLoop.java new file mode 100644 index 0000000..e44d372 --- /dev/null +++ b/src/alisolarflare/modules/events/uhc/listeners/MatchMainLoop.java @@ -0,0 +1,12 @@ +package alisolarflare.modules.events.uhc.listeners; + +import org.bukkit.scheduler.BukkitRunnable; + +public class MatchMainLoop extends BukkitRunnable{ + @Override + public void run() { + + } + + +} diff --git a/src/alisolarflare/modules/events/uhc/listeners/PlayerPowerTask.java b/src/alisolarflare/modules/events/uhc/listeners/PlayerPowerTask.java deleted file mode 100644 index 4c41cf6..0000000 --- a/src/alisolarflare/modules/events/uhc/listeners/PlayerPowerTask.java +++ /dev/null @@ -1,24 +0,0 @@ -package alisolarflare.modules.events.uhc.listeners; - -import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.scheduler.BukkitRunnable; - -/** - * This is the main class that creates and implemnts Ghostie powers - * When run, it will apply the right potion effects to different players - * based on what colours they identify as in that time. - * @author Alisolarflare - * - */ -public class PlayerPowerTask extends BukkitRunnable{ - private JavaPlugin plugin; - public PlayerPowerTask(JavaPlugin plugin){ - this.plugin = plugin; - } - @Override - public void run() { - - } - - -} diff --git a/src/alisolarflare/modules/events/uhc/memory/MatchState.java b/src/alisolarflare/modules/events/uhc/memory/MatchState.java new file mode 100644 index 0000000..8f65034 --- /dev/null +++ b/src/alisolarflare/modules/events/uhc/memory/MatchState.java @@ -0,0 +1,5 @@ +package alisolarflare.modules.events.uhc.memory; + +public enum MatchState { + NULL, IDLE, WAITING, SETUP, INTRO, PEACE, TENSION, POWER, END +} diff --git a/src/alisolarflare/modules/events/uhc/memory/PlayerPowerModule.java b/src/alisolarflare/modules/events/uhc/memory/PlayerPowerModule.java deleted file mode 100644 index 80f9f24..0000000 --- a/src/alisolarflare/modules/events/uhc/memory/PlayerPowerModule.java +++ /dev/null @@ -1,5 +0,0 @@ -package alisolarflare.modules.events.uhc.memory; - -public class PlayerPowerModule { - -} diff --git a/src/alisolarflare/modules/events/uhc/memory/UHCMatch.java b/src/alisolarflare/modules/events/uhc/memory/UHCMatch.java new file mode 100644 index 0000000..f102be5 --- /dev/null +++ b/src/alisolarflare/modules/events/uhc/memory/UHCMatch.java @@ -0,0 +1,34 @@ +package alisolarflare.modules.events.uhc.memory; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.configuration.file.FileConfiguration; + +/** + * Class that contains the data for a single UltraHardcore Match, + * which represents a single game. + * @author Alisolarflare + */ +public class UHCMatch { + public List matchPlayerUsernames = new ArrayList(); + private MatchState matchState = MatchState.IDLE; + private FileConfiguration fileConfiguration; + + /**Class that fucks shit up*/ + public UHCMatch(FileConfiguration fileConfiguration, String stateName) { + this.fileConfiguration = fileConfiguration; + this.matchState = MatchState.valueOf(stateName); + } + + /**Other class that doesn't fuck shit up*/ + public MatchState getMatchState(){ + return matchState; + } + + /**Other class that REALLY fucks shit up*/ + public void setMatchState(MatchState newMS){ + matchState = newMS; + fileConfiguration.set("UHCMatchState", newMS.toString()); + } +}