From ef3c29a99d317694d22e216e63f0fb4a68c11266 Mon Sep 17 00:00:00 2001 From: Matthew Cech Date: Sun, 8 Sep 2019 19:45:43 -0700 Subject: [PATCH 01/11] - Removed unfinished RPG command --- src/commands/general/CommandRPG.java | 53 ----------- src/commands/rpg/RPGCommandBattleFight.java | 37 -------- src/commands/rpg/RPGCommandBattleRun.java | 36 -------- src/commands/rpg/RPGCommandExplore.java | 97 --------------------- src/commands/rpg/RPGCommandInfo.java | 91 ------------------- src/commands/rpg/RPGCommandStats.java | 61 ------------- src/core/CommandManager.java | 43 +-------- src/core/rpg/RPGArmor.java | 14 --- src/core/rpg/RPGBattleContext.java | 11 --- src/core/rpg/RPGCommand.java | 9 -- src/core/rpg/RPGEnemy.java | 9 -- src/core/rpg/RPGExpTable.java | 65 -------------- src/core/rpg/RPGFramework.java | 82 ----------------- src/core/rpg/RPGInput.java | 32 ------- src/core/rpg/RPGItem.java | 25 ------ src/core/rpg/RPGLog.java | 12 --- src/core/rpg/RPGMain.java | 39 --------- src/core/rpg/RPGPlayer.java | 58 ------------ src/core/rpg/RPGState.java | 19 ---- src/core/rpg/RPGUnit.java | 34 -------- src/core/rpg/RPGWeapon.java | 17 ---- 21 files changed, 1 insertion(+), 843 deletions(-) delete mode 100644 src/commands/general/CommandRPG.java delete mode 100644 src/commands/rpg/RPGCommandBattleFight.java delete mode 100644 src/commands/rpg/RPGCommandBattleRun.java delete mode 100644 src/commands/rpg/RPGCommandExplore.java delete mode 100644 src/commands/rpg/RPGCommandInfo.java delete mode 100644 src/commands/rpg/RPGCommandStats.java delete mode 100644 src/core/rpg/RPGArmor.java delete mode 100644 src/core/rpg/RPGBattleContext.java delete mode 100644 src/core/rpg/RPGCommand.java delete mode 100644 src/core/rpg/RPGEnemy.java delete mode 100644 src/core/rpg/RPGExpTable.java delete mode 100644 src/core/rpg/RPGFramework.java delete mode 100644 src/core/rpg/RPGInput.java delete mode 100644 src/core/rpg/RPGItem.java delete mode 100644 src/core/rpg/RPGLog.java delete mode 100644 src/core/rpg/RPGMain.java delete mode 100644 src/core/rpg/RPGPlayer.java delete mode 100644 src/core/rpg/RPGState.java delete mode 100644 src/core/rpg/RPGUnit.java delete mode 100644 src/core/rpg/RPGWeapon.java diff --git a/src/commands/general/CommandRPG.java b/src/commands/general/CommandRPG.java deleted file mode 100644 index 8f62d7d..0000000 --- a/src/commands/general/CommandRPG.java +++ /dev/null @@ -1,53 +0,0 @@ -package commands.general; - -import core.Command; -import core.LocStrings; -import core.rpg.RPGFramework; -import dataStructures.KittyChannel; -import dataStructures.KittyGuild; -import dataStructures.KittyRating; -import dataStructures.KittyRole; -import dataStructures.KittyUser; -import dataStructures.Response; -import dataStructures.UserInput; - - -public class CommandRPG extends Command -{ - private RPGFramework framework; - - public CommandRPG(KittyRole role, KittyRating rating) - { - super(role, rating); - framework = new RPGFramework(); - } - - @Override - public String getHelpText() { return LocStrings.stub("RPGInfo"); }; - - - @Override - public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res) - { - if(input.args == null || input.args.length() == 0) - { - String output = getHelpText(); - res.send(output); - return; - } - - String result = null; - synchronized(framework) - { - result = framework.run(user.uniqueID, input.args.trim()); - } - - if(result == null) - { - res.send(LocStrings.stub("RPGInvalid")); - return; - } - - res.send(result); - } -} diff --git a/src/commands/rpg/RPGCommandBattleFight.java b/src/commands/rpg/RPGCommandBattleFight.java deleted file mode 100644 index 7c1fe64..0000000 --- a/src/commands/rpg/RPGCommandBattleFight.java +++ /dev/null @@ -1,37 +0,0 @@ -package commands.rpg; - -import core.rpg.RPGCommand; -import core.rpg.RPGInput; -import core.rpg.RPGState; - -public class RPGCommandBattleFight extends RPGCommand -{ - @Override - public String onRun(RPGState state, RPGInput input) - { - if(state.battleContext == null) - return "```There's nothing to fight!```"; - - String out = null; - String reward = null; - - out = "No one ever trained you to fight, so you do a silly dance and it weirds your opponent out and they leave. (i need to implement this still)"; - reward = "+150xp"; - - state.battleContext = null; - state.player.applyEXP(150); - - if(out != null && reward != null) - { - out += "\n"; - out += "\n"; - out += "[" + reward + "]"; - } - - if(out != null) - out = "```\n" + out + "```"; - - return out; - } - -} diff --git a/src/commands/rpg/RPGCommandBattleRun.java b/src/commands/rpg/RPGCommandBattleRun.java deleted file mode 100644 index b655cab..0000000 --- a/src/commands/rpg/RPGCommandBattleRun.java +++ /dev/null @@ -1,36 +0,0 @@ -package commands.rpg; - -import core.rpg.RPGCommand; -import core.rpg.RPGInput; -import core.rpg.RPGState; - -public class RPGCommandBattleRun extends RPGCommand -{ - @Override - public String onRun(RPGState state, RPGInput input) - { - if(state.battleContext == null) - return "```There's nothing to run from!```"; - - long lostGold = (long)(state.player.getGold() * .1); - String out = null; - - state.player.spendGold(lostGold); - state.battleContext = null; - - out = "You duck behind a tree and manage to escape from encounter just barely!"; - if(lostGold > 0) - { - out += " As you make your final move to escape, you accidentally drop some of your gold behind. You don't dare try to go back and pick it up."; - out += "\n"; - out += "\n"; - out += "[-" + lostGold + "gp]"; - } - - if(out != null) - out = "```\n" + out + "```"; - - return out; - } - -} diff --git a/src/commands/rpg/RPGCommandExplore.java b/src/commands/rpg/RPGCommandExplore.java deleted file mode 100644 index 3e5544c..0000000 --- a/src/commands/rpg/RPGCommandExplore.java +++ /dev/null @@ -1,97 +0,0 @@ -package commands.rpg; - -import java.util.Random; - -import core.rpg.RPGBattleContext; -import core.rpg.RPGCommand; -import core.rpg.RPGInput; -import core.rpg.RPGState; - -public class RPGCommandExplore extends RPGCommand -{ - private class Chance - { - double rand; - float lastSection; - - public Chance(float percentChanceTotal) - { - rand = new Random().nextDouble() * percentChanceTotal; - lastSection = 0; - } - - public boolean Next(float amount) - { - lastSection += amount; - return rand < lastSection; - } - } - - @Override - public String onRun(RPGState state, RPGInput input) - { - Chance chance = new Chance(100); - - String out = null; - String reward = null; - - if(state.battleContext != null) - return "```You can't explore right now, you're in a fight! Try either 'fight' or 'run'!```"; - - if(chance.Next(20)) - { - out = "A creature jumps out of a bush at you!"; - reward = "Prepare to fight!"; - state.battleContext = new RPGBattleContext(state); - } - else if(chance.Next(20)) - { - final int gp = 1; - - out = "As you take a stroll, you spy a small shiny glint from a bush and decide to investigate! Looks like it's your lucky day!"; - reward = "+" + gp + "gp"; - state.player.giveGold(gp); - } - else if(chance.Next(20)) - { - final int healing = 1; - final int xp = 25; - - out = "You head out on a lovely stroll down a familiar path - the sun is out and the birds are chirping! Nothing much comes of it, but you feel refreshed."; - reward = "+" + xp + "xp, +" + healing + "hp"; - state.player.applyHealing(healing); - state.player.applyEXP(xp); - } - else if(chance.Next(20)) - { - final int xp = 75; - final int damage = 1; - - out = "Today's the day you head out on a new path. You find a lot of little nicknacks and trinkets on the trail, but leave them be. The trail gets really steep, the rocks jagged, but you keep going. Eventually, you make it out to the other side into a small but pleasant town, and collapse on a bench to catch your breath."; - reward = "+" + xp + "xp, -" + damage + "hp"; - state.player.applyEXP(xp); - state.player.applyDamage(damage); - } - else - { - final int hp = 2; - - out = "You step outside but it starts to rain. You decide not to do much today, and hang about the inn and the tavern."; - reward = "+" + hp + "hp"; - state.player.applyHealing(hp); - } - - if(out != null && reward != null) - { - out += "\n"; - out += "\n"; - out += "[" + reward + "]"; - } - - if(out != null) - out = "```\n" + out + "```"; - - return out; - } - -} diff --git a/src/commands/rpg/RPGCommandInfo.java b/src/commands/rpg/RPGCommandInfo.java deleted file mode 100644 index 3741809..0000000 --- a/src/commands/rpg/RPGCommandInfo.java +++ /dev/null @@ -1,91 +0,0 @@ -package commands.rpg; - -import core.rpg.RPGArmor; -import core.rpg.RPGCommand; -import core.rpg.RPGInput; -import core.rpg.RPGState; -import core.rpg.RPGWeapon; - -public class RPGCommandInfo extends RPGCommand -{ - @Override - public String onRun(RPGState state, RPGInput input) - { - String out = null; - switch(input.value.trim().toLowerCase()) - { - case "weapon": - case "weapo": - case "weap": - case "wea": - case "we": - case "w": - case "wepon": - case "wepo": - case "wep": - case "hand": - case "att": - case "attack": - out = weaponStats(state.player.getWeapon()); - break; - - case "armour": - case "armou": - case "armor": - case "armr": - case "armo": - case "arm": - case "ar": - case "a": - case "def": - case "defense": - case "body": - case "dress": - case "wear": - case "outfit": - out = armorStats(state.player.getArmor()); - break; - } - - if(out != null) - out = "```\n" + out + "```"; - - return out; - } - - private String weaponStats(RPGWeapon weapon) - { - if(weapon == null) - return null; - - String out = ""; - out += "[" + weapon.getName() + "]"; - out += "\n"; - out += " att: " + weapon.getAttack(); - out += "\n"; - out += "value: " + weapon.getValue() + "gp"; - out += "\n"; - out += "\n"; - out += weapon.getDescription(); - - return out; - } - - private String armorStats(RPGArmor armor) - { - if(armor == null) - return null; - - String out = ""; - out += "[" + armor.getName() + "]"; - out += "\n"; - out += " def: " + armor.getDefense(); - out += "\n"; - out += "value: " + armor.getValue() + "gp"; - out += "\n"; - out += "\n"; - out += armor.getDescription(); - - return out; - } -} diff --git a/src/commands/rpg/RPGCommandStats.java b/src/commands/rpg/RPGCommandStats.java deleted file mode 100644 index 1e2cb9b..0000000 --- a/src/commands/rpg/RPGCommandStats.java +++ /dev/null @@ -1,61 +0,0 @@ -package commands.rpg; - -import core.rpg.RPGArmor; -import core.rpg.RPGCommand; -import core.rpg.RPGExpTable; -import core.rpg.RPGInput; -import core.rpg.RPGPlayer; -import core.rpg.RPGState; -import core.rpg.RPGWeapon; - -public class RPGCommandStats extends RPGCommand -{ - @Override - public String onRun(RPGState state, RPGInput input) - { - RPGPlayer player = state.player; - long exp = player.getEXP(); - long level = RPGExpTable.levelFromEXP(player.getEXP()); - long ceil = RPGExpTable.expCeil(level); - - String indent = ""; - String linebreak = "\n"; - - String out = ""; - out += indent + "[" + player.getName() + ", lv. " + level + "]"; - out += indent + linebreak; - out += indent + "_______________"; - out += indent + linebreak; - - out += indent + " EXP: " + exp; - out += indent + " (until next: " + (ceil - exp) + ")"; - out += indent + linebreak; - - out += indent + " Gold: " + player.getGold(); - out += indent + linebreak; - - out += indent + "Health: " + player.getHealthCurrent() + "/" + player.getHealthMax(); - out += indent + linebreak; - - RPGWeapon weapon = player.getWeapon(); - out += indent + "_____"; - out += indent + linebreak; - out += indent + "Weapon: " + weapon.getName(); - out += indent + linebreak; - out += indent + " att: " + weapon.getAttack(); - out += indent + linebreak; - - RPGArmor armor = player.getArmor(); - out += indent + "_____"; - out += indent + linebreak; - out += indent + "Armor: " + armor.getName(); - out += indent + linebreak; - out += indent + " def: " + armor.getDefense() ; - out += indent + linebreak; - - out += indent + linebreak; - out += "Use 'info armor' / 'info weapon' for details!"; - - return "```\n" + out + "```"; - } -} diff --git a/src/core/CommandManager.java b/src/core/CommandManager.java index c1441c4..5c7e599 100644 --- a/src/core/CommandManager.java +++ b/src/core/CommandManager.java @@ -5,47 +5,7 @@ import java.util.HashMap; import java.util.Map.Entry; import commands.characters.CommandCharacterMain; -import commands.general.CommandBeansShow; -import commands.general.CommandBenchmark; -import commands.general.CommandBetBeans; -import commands.general.CommandBetHistory; -import commands.general.CommandBlurry; -import commands.general.CommandBoop; -import commands.general.CommandCatch; -import commands.general.CommandChangeIndicator; -import commands.general.CommandChoose; -import commands.general.CommandColiru; -import commands.general.CommandColor; -import commands.general.CommandCrouton; -import commands.general.CommandDBFlush; -import commands.general.CommandDBStats; -import commands.general.CommandDoWork; -import commands.general.CommandEightBall; -import commands.general.CommandFetch; -import commands.general.CommandGiveBeans; -import commands.general.CommandHelp; -import commands.general.CommandHelpBuilder; -import commands.general.CommandInfo; -import commands.general.CommandInvite; -import commands.general.CommandJDoodle; -import commands.general.CommandLeaderboard; -import commands.general.CommandMap; -import commands.general.CommandPerish; -import commands.general.CommandPing; -import commands.general.CommandRPEnd; -import commands.general.CommandRPG; -import commands.general.CommandRPStart; -import commands.general.CommandRating; -import commands.general.CommandRemind; -import commands.general.CommandRole; -import commands.general.CommandRoll; -import commands.general.CommandShutdown; -import commands.general.CommandStark; -import commands.general.CommandStats; -import commands.general.CommandTeey; -import commands.general.CommandTweet; -import commands.general.CommandWolfram; -import commands.general.CommandYeet; +import commands.general.*; import commands.guildrole.CommandGuildRoleMain; import commands.mod.CommandModMain; import commands.music.CommandMusicMain; @@ -116,7 +76,6 @@ public class CommandManager // Mod this.register(LocCommands.stub("givebeans"), new CommandGiveBeans(KittyRole.Mod, KittyRating.Safe)); - this.register(LocCommands.stub("rpg"), new CommandRPG(KittyRole.Mod, KittyRating.Safe)); this.register(LocCommands.stub("mod"), new CommandModMain(KittyRole.Mod, KittyRating.Safe)); // General diff --git a/src/core/rpg/RPGArmor.java b/src/core/rpg/RPGArmor.java deleted file mode 100644 index 9d3788f..0000000 --- a/src/core/rpg/RPGArmor.java +++ /dev/null @@ -1,14 +0,0 @@ -package core.rpg; - -public class RPGArmor extends RPGItem -{ - int defense; - - public RPGArmor() - { - super("Tattered Clothes", "The remains of your first sewing project. You did a pretty good job!", 5); - defense = 1; - } - - public long getDefense() { return defense; } -} diff --git a/src/core/rpg/RPGBattleContext.java b/src/core/rpg/RPGBattleContext.java deleted file mode 100644 index 72c82ca..0000000 --- a/src/core/rpg/RPGBattleContext.java +++ /dev/null @@ -1,11 +0,0 @@ -package core.rpg; - -public class RPGBattleContext -{ - public RPGState stateRef; - - public RPGBattleContext(RPGState state) - { - this.stateRef = state; - } -} diff --git a/src/core/rpg/RPGCommand.java b/src/core/rpg/RPGCommand.java deleted file mode 100644 index 0a7170e..0000000 --- a/src/core/rpg/RPGCommand.java +++ /dev/null @@ -1,9 +0,0 @@ -package core.rpg; - -public abstract class RPGCommand -{ - public RPGCommand() { } - - // OVERRIDE ME - public abstract String onRun(RPGState state, RPGInput input); -} diff --git a/src/core/rpg/RPGEnemy.java b/src/core/rpg/RPGEnemy.java deleted file mode 100644 index 41a9a52..0000000 --- a/src/core/rpg/RPGEnemy.java +++ /dev/null @@ -1,9 +0,0 @@ -package core.rpg; - -public class RPGEnemy extends RPGUnit -{ - RPGWeapon attack; - RPGArmor armor; - - long expValue; -} diff --git a/src/core/rpg/RPGExpTable.java b/src/core/rpg/RPGExpTable.java deleted file mode 100644 index 310d41e..0000000 --- a/src/core/rpg/RPGExpTable.java +++ /dev/null @@ -1,65 +0,0 @@ -package core.rpg; - -public final class RPGExpTable -{ - public static long expFloor(long level) - { - if(level > Levels.length - 1) - level = Levels.length - 1; - - else if (level <= 0) - level = 1; - - return Levels[(int) level]; - } - - public static long expCeil(long level) - { - if(level > Levels.length - 1) - level = Levels.length - 1; - - else if (level <= 0) - level = 1; - - return Levels[(int) (level + 1)]; - } - public static long levelFromEXP(long exp) - { - if(exp < 0) - exp = 0; - - for(int i = 0; i < Levels.length; ++i) - { - if(Levels[i] > exp) - return i - 1; - } - - return Levels.length - 1; - } - - // Based on D&D Pathfinder levels - public static long Levels[] = - { - 0, // level 0 - 0, // level 1 - 3000, // level 2 - 7500, // level 3 - 14000, // level 4 - 23000, // level 5 - 35000, // level 6 - 53000, // level 7 - 77000, // level 8 - 115000, // level 9 - 160000, // level 10 - 235000, // level 11 - 330000, // level 12 - 475000, // level 13 - 665000, // level 14 - 955000, // level 15 - 1350000, // level 16 - 1900000, // level 17 - 2700000, // level 18 - 3850000, // level 19 - 5350000 // level 20 - }; -} diff --git a/src/core/rpg/RPGFramework.java b/src/core/rpg/RPGFramework.java deleted file mode 100644 index 424048f..0000000 --- a/src/core/rpg/RPGFramework.java +++ /dev/null @@ -1,82 +0,0 @@ -package core.rpg; - -import java.util.HashMap; - -import commands.rpg.RPGCommandBattleFight; -import commands.rpg.RPGCommandBattleRun; -import commands.rpg.RPGCommandExplore; -import commands.rpg.RPGCommandInfo; -import commands.rpg.RPGCommandStats; -import core.rpg.RPGInput; - -// Holds the framework for the text RPG, for any number of users -public class RPGFramework -{ - // User ID to user state. Users are conceptually just an ID. - public HashMap gameStates; - public HashMap gameCommands; - - // Ctor - public RPGFramework() - { - this.gameStates = new HashMap(); - this.gameCommands = new HashMap(); - - registerCommand("stats", new RPGCommandStats()); - registerCommand("about", new RPGCommandInfo()); - registerCommand("info", new RPGCommandInfo()); - registerCommand("explore", new RPGCommandExplore()); - registerCommand("run", new RPGCommandBattleRun()); - registerCommand("fight", new RPGCommandBattleFight()); - } - - // Primary external - public String run(String userID, String inputRaw) - { - RPGState state = lookupState(userID); - RPGInput input = new RPGInput(inputRaw); - return executeCommand(input.key, state, input); - } - - // Get state for executing a command - public RPGState lookupState(String userID) - { - RPGState state; - synchronized(gameStates) - { - // Note: Hardcoded right now. Later: Extract. - state = gameStates.get(userID); - - if(state == null) - { - state = new RPGState(userID); - gameStates.put(userID, state); - } - } - - return state; - } - - // Registers a command - private void registerCommand(String commandName, RPGCommand command) - { - commandName = commandName.toLowerCase(); - if(gameCommands.put(commandName, command) != null) - RPGLog.log("Managed to register the same RPG command twice! Not ideal!"); - - RPGLog.log("Registered " + commandName); - } - - private String executeCommand(String name, RPGState state, RPGInput input) - { - synchronized(gameCommands) - { - RPGCommand command = gameCommands.get(name.toLowerCase()); - - if(command != null && state != null) - return command.onRun(state, input); - } - - return null; - } -} diff --git a/src/core/rpg/RPGInput.java b/src/core/rpg/RPGInput.java deleted file mode 100644 index d93a318..0000000 --- a/src/core/rpg/RPGInput.java +++ /dev/null @@ -1,32 +0,0 @@ -package core.rpg; - -import utils.StringUtils; - -public class RPGInput -{ - public String raw; - public String key; - public String value; - - public RPGInput(String raw) - { - this.raw = raw; - this.key = ""; - this.value = ""; - - if(raw == null || raw.length() == 0) - return; - - raw = raw.trim(); - int whitespacePos = StringUtils.findFirstWhitespace(raw); - - if(whitespacePos == -1) - { - key = raw; - return; - } - - key = raw.substring(0, whitespacePos).trim(); - value = raw.substring(whitespacePos).trim(); - } -} diff --git a/src/core/rpg/RPGItem.java b/src/core/rpg/RPGItem.java deleted file mode 100644 index 3c71b03..0000000 --- a/src/core/rpg/RPGItem.java +++ /dev/null @@ -1,25 +0,0 @@ -package core.rpg; - -public abstract class RPGItem -{ - protected String name; - protected String description; - protected int value; - - // Defaults - public RPGItem() { this("unknown"); } - public RPGItem(String name) { this(name, "nothig is known about this item"); } - public RPGItem(String name, String description) { this(name, description, 1); } - - // Ctor - public RPGItem(String name, String description, int value) - { - this.name = name; - this.description = description; - this.value = value; - } - - public String getName() { return name; } - public String getDescription() { return description; } - public long getValue() { return value; } -} diff --git a/src/core/rpg/RPGLog.java b/src/core/rpg/RPGLog.java deleted file mode 100644 index cbf6774..0000000 --- a/src/core/rpg/RPGLog.java +++ /dev/null @@ -1,12 +0,0 @@ -package core.rpg; - -import utils.GlobalLog; -import utils.LogFilter; - -public class RPGLog -{ - public static void log(String toWrite) - { - GlobalLog.log(LogFilter.Command, "[RPG] " + toWrite); - } -} diff --git a/src/core/rpg/RPGMain.java b/src/core/rpg/RPGMain.java deleted file mode 100644 index d7d5598..0000000 --- a/src/core/rpg/RPGMain.java +++ /dev/null @@ -1,39 +0,0 @@ -package core.rpg; - -import java.util.Scanner; - -// This is for testing only, and generally doesn't run unless it's specified. -public class RPGMain -{ - private static RPGFramework framework; - private static Scanner scanner; - - public static void RPGmain(String[] args) - { - init(); - while(run()) { }; - shutdown(); - } - - // Initializes stuff (small factory, ish) - private static void init() - { - framework = new RPGFramework(); - scanner = new Scanner(System.in); - } - - // Main loop - private static boolean run() - { - // move outside - String out = framework.run("Test", scanner.nextLine()); - RPGLog.log(out); - return true; - } - - // Cleanup - private static void shutdown() - { - scanner.close(); - } -} \ No newline at end of file diff --git a/src/core/rpg/RPGPlayer.java b/src/core/rpg/RPGPlayer.java deleted file mode 100644 index f29ce7a..0000000 --- a/src/core/rpg/RPGPlayer.java +++ /dev/null @@ -1,58 +0,0 @@ -package core.rpg; - -public class RPGPlayer extends RPGUnit -{ - private String name; - private long gold; - private long exp; - - RPGWeapon weapon; - RPGArmor armor; - - public RPGPlayer() - { - super(); - - name = "Wanderer"; - healthCurrent = 5; - healthMax = 5; - gold = 0; - weapon = new RPGWeapon(); - armor = new RPGArmor(); - } - - // Getters - public long getEXP() { return exp; } - public long getGold() { return gold; } - public String getName() { return name; } - public RPGArmor getArmor() { return armor; }; - public RPGWeapon getWeapon() { return weapon; }; - - // Setters - public void setName(String name) { this.name = name; } - - // Interactions - public void applyEXP(int expToGive) - { - if(expToGive < 0) - expToGive = 0; - - exp += expToGive; - } - - public void giveGold(long amount) - { - if(amount < 0) - amount = 0; - - gold += amount; - } - - public void spendGold(long amount) - { - if(amount < 0) - amount = 0; - - gold -= amount; - } -} diff --git a/src/core/rpg/RPGState.java b/src/core/rpg/RPGState.java deleted file mode 100644 index f6fb1a7..0000000 --- a/src/core/rpg/RPGState.java +++ /dev/null @@ -1,19 +0,0 @@ -package core.rpg; - -// Holds specific state information for a given user and their world -public class RPGState -{ - // General - public String userID; - - // Stats and gameplay - public RPGPlayer player; - public RPGBattleContext battleContext; - - public RPGState(String userID) - { - this.userID = userID; - this.player = new RPGPlayer(); - this.battleContext = null; - } -} \ No newline at end of file diff --git a/src/core/rpg/RPGUnit.java b/src/core/rpg/RPGUnit.java deleted file mode 100644 index b0c23b1..0000000 --- a/src/core/rpg/RPGUnit.java +++ /dev/null @@ -1,34 +0,0 @@ -package core.rpg; - -public abstract class RPGUnit -{ - protected int healthMax; - protected int healthCurrent; - - public int getHealthMax() { return healthMax; } - public int getHealthCurrent() { return healthCurrent; } - public boolean isAlive() { return healthCurrent > 0; } - - // Generic implementation. Consider implementing armor in - // derived classes, for example. - public void applyDamage(int value) - { - if(value < 0) - value = 0; - - healthCurrent -= value; - } - - // Generic implementation. Consider applying boosts in - // derived classes, for example. - public void applyHealing(int value) - { - if(value < 0) - value = 0; - - healthCurrent += value; - - if(healthCurrent > healthMax) - healthCurrent = healthMax; - } -} diff --git a/src/core/rpg/RPGWeapon.java b/src/core/rpg/RPGWeapon.java deleted file mode 100644 index b53a25e..0000000 --- a/src/core/rpg/RPGWeapon.java +++ /dev/null @@ -1,17 +0,0 @@ -package core.rpg; - -public class RPGWeapon extends RPGItem -{ - private long attack; - private double accuracy; - - RPGWeapon() - { - super("Singed Stick", "A really cool stick that you found! You poked at your campfire last night with it a bit, so the end is a bit toasty.", 2); - attack = 1; - accuracy = 0.8; - } - - public long getAttack() { return attack; } - public double getAccuracy() { return accuracy; } -} From 44efcef7ae4206f954d3c99f6ca1ef7c2e9daf44 Mon Sep 17 00:00:00 2001 From: Matthew Cech Date: Thu, 12 Sep 2019 22:24:28 -0700 Subject: [PATCH 02/11] = Covered leaderboard to prevent bad parses and condensed command manager --- src/commands/general/CommandLeaderboard.java | 26 ++++++++++++++------ src/core/CommandManager.java | 10 ++------ 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/commands/general/CommandLeaderboard.java b/src/commands/general/CommandLeaderboard.java index b461077..ddc8cf0 100644 --- a/src/commands/general/CommandLeaderboard.java +++ b/src/commands/general/CommandLeaderboard.java @@ -49,15 +49,25 @@ public class CommandLeaderboard extends Command if(userID.length() < 1) continue; - // Look up in the database the user beans - String dbUserData = DatabaseManager.instance.globalGetRemoteValue(guildID + userID); + String dbUserData = null; + Long parsedBeans = null; - // Leverage the fact that the user is automatically read and parsed when constructed. - Long parsedBeans = KittyUser.parseBeans(KittyUser.prepareFromString(dbUserData)); - - // If we were only using cached users, we would use this. However, we're not. - // KittyUser cachedUser = ObjectBuilderFactory.getCachedUser(guildID, userID); - users.add(new Pair(parsedBeans, userID)); + try + { + // Look up in the database the user beans + dbUserData = DatabaseManager.instance.globalGetRemoteValue(guildID + userID); + + // Leverage the fact that the user is automatically read and parsed when constructed. + parsedBeans = KittyUser.parseBeans(KittyUser.prepareFromString(dbUserData)); + + // If we were only using cached users, we would use this. However, we're not. + // KittyUser cachedUser = ObjectBuilderFactory.getCachedUser(guildID, userID); + users.add(new Pair(parsedBeans, userID)); + } + catch (Exception e) + { + GlobalLog.error(LogFilter.Command, "Issue parsing for leaderboard,\ndbUserData:" + dbUserData + "\nparsedBeans:" + parsedBeans); + } } } diff --git a/src/core/CommandManager.java b/src/core/CommandManager.java index 5c7e599..ec831ee 100644 --- a/src/core/CommandManager.java +++ b/src/core/CommandManager.java @@ -11,14 +11,7 @@ import commands.mod.CommandModMain; import commands.music.CommandMusicMain; import commands.poll.CommandPollMain; import commands.raffle.CommandRaffleMain; -import dataStructures.KittyChannel; -import dataStructures.KittyGuild; -import dataStructures.KittyRating; -import dataStructures.KittyRole; -import dataStructures.KittyUser; -import dataStructures.Pair; -import dataStructures.Response; -import dataStructures.UserInput; +import dataStructures.*; import utils.GlobalLog; import utils.LogFilter; @@ -113,6 +106,7 @@ public class CommandManager this.register(LocCommands.stub("raffle"), new CommandRaffleMain(KittyRole.General, KittyRating.Safe)); this.register(LocCommands.stub("poll"), new CommandPollMain(KittyRole.General, KittyRating.Safe)); this.register(LocCommands.stub("music"), new CommandMusicMain(KittyRole.General, KittyRating.Safe)); + this.register(LocCommands.stub("defaultdance"), new CommandDefaultDance(KittyRole.General, KittyRating.Safe)); } // Allows the command manager to keep track of a command. Takes a pair (the un-localized and localzied commands) From b960fd0101a7199f0c48f13dc1ab50a86f1c05ae Mon Sep 17 00:00:00 2001 From: Matthew Cech Date: Thu, 12 Sep 2019 22:48:24 -0700 Subject: [PATCH 03/11] + Added ability to change bet threshold from config file --- src/commands/general/CommandBetBeans.java | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/commands/general/CommandBetBeans.java b/src/commands/general/CommandBetBeans.java index 25e0eb9..bcb14b0 100644 --- a/src/commands/general/CommandBetBeans.java +++ b/src/commands/general/CommandBetBeans.java @@ -5,6 +5,8 @@ import java.util.Random; import core.Command; import core.LocStrings; import dataStructures.*; +import utils.GlobalLog; +import utils.LogFilter; public class CommandBetBeans extends Command { @@ -17,12 +19,30 @@ public class CommandBetBeans extends Command public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res) { String call = ""; + + int min = 50; int bet = 0; int win = 0; + + try + { + String valAsString = LocStrings.stub("BetBeansMinThreshold"); + int parsed = Integer.parseInt(valAsString); + + if(parsed < 0) + parsed = 0; + + min = parsed; + } + catch (Exception e) + { + GlobalLog.log(LogFilter.Command, "Betting took place, but a value was not specified in the config file so 50 was used as the minimum bet threshold. Consider specifying BetBeansMinThreshold."); + } + try { bet = Integer.parseInt(input.args); - if(bet < 50) + if(bet < min) { res.send(LocStrings.stub("BetBeansLowBet")); return; From 7f2251732ea8e476ad26107e4f5510e044a8116c Mon Sep 17 00:00:00 2001 From: Matthew Cech Date: Sat, 2 Nov 2019 19:13:26 -0800 Subject: [PATCH 04/11] = Configs updating --- src/core/Config.java | 1 + src/core/ConfigGlobals.java | 68 ++++++++++++++++++++++++ src/core/ConfigItem.java | 6 +-- src/core/LocCommands.java | 4 +- src/dataStructures/KittyStartupMode.java | 18 +++++++ 5 files changed, 92 insertions(+), 5 deletions(-) create mode 100644 src/core/ConfigGlobals.java create mode 100644 src/dataStructures/KittyStartupMode.java diff --git a/src/core/Config.java b/src/core/Config.java index c76c9c2..96b29bc 100644 --- a/src/core/Config.java +++ b/src/core/Config.java @@ -28,6 +28,7 @@ public class Config sections = new Vector(); // Add all sections + sections.add(new ConfigGlobals()); sections.add(new LocCommands()); sections.add(new LocStrings()); sections.add(new CommandEnabler()); diff --git a/src/core/ConfigGlobals.java b/src/core/ConfigGlobals.java new file mode 100644 index 0000000..f7b7ce7 --- /dev/null +++ b/src/core/ConfigGlobals.java @@ -0,0 +1,68 @@ +package core; + +import java.util.ArrayList; +import java.util.List; + +import dataStructures.KittyStartupMode; +import utils.GlobalLog; + +// Want to add a single item to the config file? This is where that lives. +public class ConfigGlobals implements IConfigSection +{ + // Defined const variables + public static final String header = "Globals"; + public static ConfigGlobals instance; + + + // A pile of variables being manually tracked/serialized to the config file + private static final String startupStyleKey = "mode"; + private KittyStartupMode startupStyleValue = KittyStartupMode.Development; + + // Constructor + public ConfigGlobals() + { + if(instance == null) + instance = this; + else + GlobalLog.error("Attempted to initialize a second config globals! Probably don't do this!"); + } + + @Override + public String getSectionTitle() + { + return header; + } + + public static KittyStartupMode getStartupMode() + { + return instance.startupStyleValue; + } + + @Override + public void consume(List pairs) + { + for(int i = 0; i < pairs.size(); ++i) + { + String key = pairs.get(i).key; + String value = pairs.get(i).value; + + // Parse startup style + if(key.equalsIgnoreCase(startupStyleKey)) + { + startupStyleValue = KittyStartupMode.Development; + + if(value.equalsIgnoreCase(KittyStartupMode.Release.getValue())) + startupStyleValue = KittyStartupMode.Release; + } + } + } + + @Override + public List produce() + { + List items = new ArrayList(); + items.add(new ConfigItem(getSectionTitle(), startupStyleKey, startupStyleValue.getValue())); + + return items; + } +} diff --git a/src/core/ConfigItem.java b/src/core/ConfigItem.java index 7f556d2..75e8bad 100644 --- a/src/core/ConfigItem.java +++ b/src/core/ConfigItem.java @@ -6,9 +6,9 @@ import utils.StringUtils; // perform any parsing past naming columns, and just holds the raw data. public class ConfigItem { - public String type; - public String key; - public String value; + public String type; // The section this specific key/value pair belongs to. This almost certainly will appear in multiple places. + public String key; // A unique key for a given lookup value for the specified section. Keys, within sections, are unique. + public String value; // The value assocaited with the key. public static final int items = 3; public static final String[] header = {"Type","Key","Value"}; diff --git a/src/core/LocCommands.java b/src/core/LocCommands.java index 30d071e..2d446e7 100644 --- a/src/core/LocCommands.java +++ b/src/core/LocCommands.java @@ -11,7 +11,7 @@ import dataStructures.Pair; public class LocCommands extends BaseLocFile implements IConfigSection { // Defined const variables - public static final String HeaderName = "Localized Commands"; + public static final String header = "Localized Commands"; public static final String function = "LocCommands.stub"; // Instance @@ -20,7 +20,7 @@ public class LocCommands extends BaseLocFile implements IConfigSection // Constructor public LocCommands() { - super(HeaderName, function); + super(header, function); GlobalLog.log(LogFilter.Core, "Initializing " + this.getClass().getSimpleName()); diff --git a/src/dataStructures/KittyStartupMode.java b/src/dataStructures/KittyStartupMode.java new file mode 100644 index 0000000..3d9e67d --- /dev/null +++ b/src/dataStructures/KittyStartupMode.java @@ -0,0 +1,18 @@ +package dataStructures; + +public enum KittyStartupMode +{ + Development("dev"), Release("release"); + + private final String value; + private KittyStartupMode(String value) + { + this.value = value; + } + + public String getValue() + { + return value; + } +} + From 74a57508247f992fc487d3d895c5d66c570af77e Mon Sep 17 00:00:00 2001 From: Matthew Cech Date: Sat, 2 Nov 2019 19:29:02 -0800 Subject: [PATCH 05/11] = Updated config --- assets/config.csv | 2 ++ src/core/ConfigGlobals.java | 8 ++++---- src/core/ObjectBuilderFactory.java | 11 +++++++++-- src/dataStructures/KittyStartupMode.java | 8 ++++---- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/assets/config.csv b/assets/config.csv index 686c012..b515996 100644 --- a/assets/config.csv +++ b/assets/config.csv @@ -1,4 +1,5 @@ "Type","Key","Value" +"Globals","mode","dev" "Localized Commands","beans","" "Localized Commands","benchmark, bench","" "Localized Commands","bet","" @@ -61,6 +62,7 @@ "Localized Strings","BetBeansInfo","Allows you to bet your beans, set your amount after the command! Warning! House always wins!nSets of 3 will get 2x, 4 will get 10x, and 5 will get 1000x" "Localized Strings","BetBeansLose","Sorry, you didn't win, try again!" "Localized Strings","BetBeansLowBet","Please bet with at least 20 beans!" +"Localized Strings","BetBeansMinThreshold","" "Localized Strings","BetBeansNotEnough","You don't have enough beans!" "Localized Strings","BetBeansNotValid","That's not a valid bet!" "Localized Strings","BetBeansWin","You won %s beans!" diff --git a/src/core/ConfigGlobals.java b/src/core/ConfigGlobals.java index f7b7ce7..1828d70 100644 --- a/src/core/ConfigGlobals.java +++ b/src/core/ConfigGlobals.java @@ -16,7 +16,7 @@ public class ConfigGlobals implements IConfigSection // A pile of variables being manually tracked/serialized to the config file private static final String startupStyleKey = "mode"; - private KittyStartupMode startupStyleValue = KittyStartupMode.Development; + private KittyStartupMode startupStyleValue = KittyStartupMode.Dev; // Constructor public ConfigGlobals() @@ -49,9 +49,9 @@ public class ConfigGlobals implements IConfigSection // Parse startup style if(key.equalsIgnoreCase(startupStyleKey)) { - startupStyleValue = KittyStartupMode.Development; + startupStyleValue = KittyStartupMode.Dev; - if(value.equalsIgnoreCase(KittyStartupMode.Release.getValue())) + if(value.equalsIgnoreCase(KittyStartupMode.Release.name())) startupStyleValue = KittyStartupMode.Release; } } @@ -61,7 +61,7 @@ public class ConfigGlobals implements IConfigSection public List produce() { List items = new ArrayList(); - items.add(new ConfigItem(getSectionTitle(), startupStyleKey, startupStyleValue.getValue())); + items.add(new ConfigItem(getSectionTitle(), startupStyleKey, startupStyleValue.name().toLowerCase())); return items; } diff --git a/src/core/ObjectBuilderFactory.java b/src/core/ObjectBuilderFactory.java index fd5d592..a17d2ed 100644 --- a/src/core/ObjectBuilderFactory.java +++ b/src/core/ObjectBuilderFactory.java @@ -20,6 +20,7 @@ import dataStructures.KittyCore; import dataStructures.KittyGuild; import dataStructures.KittyRating; import dataStructures.KittyRole; +import dataStructures.KittyStartupMode; import dataStructures.KittyUser; import main.Main; import net.dv8tion.jda.core.AccountType; @@ -382,9 +383,15 @@ public class ObjectBuilderFactory { lazyInit(); + // Determine token based on config. Default to test token. + String tokenToUse = Ref.TestToken; + if(ConfigGlobals.getStartupMode() == KittyStartupMode.Release) + tokenToUse = Ref.Token; + + // Construct bot based on token kitty = new JDABuilder(AccountType.BOT) - .setToken(Ref.TestToken).buildBlocking(); - kitty.getPresence().setGame(Game.playing("with digital yarn")); + .setToken(tokenToUse).buildBlocking(); + kitty.getPresence().setGame(Game.playing("with a laser pointer")); kitty.addEventListener(new Main()); return new KittyCore(kitty); diff --git a/src/dataStructures/KittyStartupMode.java b/src/dataStructures/KittyStartupMode.java index 3d9e67d..3f9f8a7 100644 --- a/src/dataStructures/KittyStartupMode.java +++ b/src/dataStructures/KittyStartupMode.java @@ -2,15 +2,15 @@ package dataStructures; public enum KittyStartupMode { - Development("dev"), Release("release"); + Dev(1), Release(2); - private final String value; - private KittyStartupMode(String value) + private final int value; + private KittyStartupMode(int value) { this.value = value; } - public String getValue() + public int getValue() { return value; } From d6fd5ae436a07c29b302315557b8d8c7ff188a1e Mon Sep 17 00:00:00 2001 From: Matthew Cech Date: Sat, 2 Nov 2019 19:31:02 -0800 Subject: [PATCH 06/11] = clarified mode with note in key --- assets/config.csv | 2 +- src/core/ConfigGlobals.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/assets/config.csv b/assets/config.csv index b515996..437a63e 100644 --- a/assets/config.csv +++ b/assets/config.csv @@ -1,5 +1,5 @@ "Type","Key","Value" -"Globals","mode","dev" +"Globals","mode (dev or release)","dev" "Localized Commands","beans","" "Localized Commands","benchmark, bench","" "Localized Commands","bet","" diff --git a/src/core/ConfigGlobals.java b/src/core/ConfigGlobals.java index 1828d70..d6b5db9 100644 --- a/src/core/ConfigGlobals.java +++ b/src/core/ConfigGlobals.java @@ -15,7 +15,7 @@ public class ConfigGlobals implements IConfigSection // A pile of variables being manually tracked/serialized to the config file - private static final String startupStyleKey = "mode"; + private static final String startupStyleKey = "mode (dev or release)"; private KittyStartupMode startupStyleValue = KittyStartupMode.Dev; // Constructor From 595b1e3958d836e8dd78bd3116cf1971ecb78ee1 Mon Sep 17 00:00:00 2001 From: Matthew Cech Date: Sat, 2 Nov 2019 19:31:02 -0800 Subject: [PATCH 07/11] = clarified mode with note in key --- assets/config.csv | 2 +- src/core/ConfigGlobals.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/assets/config.csv b/assets/config.csv index b515996..437a63e 100644 --- a/assets/config.csv +++ b/assets/config.csv @@ -1,5 +1,5 @@ "Type","Key","Value" -"Globals","mode","dev" +"Globals","mode (dev or release)","dev" "Localized Commands","beans","" "Localized Commands","benchmark, bench","" "Localized Commands","bet","" diff --git a/src/core/ConfigGlobals.java b/src/core/ConfigGlobals.java index 1828d70..d6b5db9 100644 --- a/src/core/ConfigGlobals.java +++ b/src/core/ConfigGlobals.java @@ -15,7 +15,7 @@ public class ConfigGlobals implements IConfigSection // A pile of variables being manually tracked/serialized to the config file - private static final String startupStyleKey = "mode"; + private static final String startupStyleKey = "mode (dev or release)"; private KittyStartupMode startupStyleValue = KittyStartupMode.Dev; // Constructor From 46cf6f8c97fc8b7376eaa0615e98eb342b49cdb5 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 18 Dec 2019 03:07:52 -0500 Subject: [PATCH 08/11] Bug Fixes with Music playing --- src/commands/music/CommandMusicMain.java | 1 - src/commands/music/SubCommandPlaylist.java | 2 +- src/commands/music/SubCommandStop.java | 3 +-- src/utils/audio/AudioUtils.java | 22 ++++++++++++++++------ 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/commands/music/CommandMusicMain.java b/src/commands/music/CommandMusicMain.java index 6581271..7e71fc6 100644 --- a/src/commands/music/CommandMusicMain.java +++ b/src/commands/music/CommandMusicMain.java @@ -27,7 +27,6 @@ public class CommandMusicMain extends Command public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res) { SubCommandFormattable scf = framework.run(guild, channel, user, input); - System.out.println("SCF: " + scf.resString); scf.Call(res); } } \ No newline at end of file diff --git a/src/commands/music/SubCommandPlaylist.java b/src/commands/music/SubCommandPlaylist.java index ec81859..b6c2a3f 100644 --- a/src/commands/music/SubCommandPlaylist.java +++ b/src/commands/music/SubCommandPlaylist.java @@ -35,4 +35,4 @@ public class SubCommandPlaylist extends SubCommand return new SubCommandFormattable(stringPlaylist); } -} +} \ No newline at end of file diff --git a/src/commands/music/SubCommandStop.java b/src/commands/music/SubCommandStop.java index 2aacffd..1422792 100644 --- a/src/commands/music/SubCommandStop.java +++ b/src/commands/music/SubCommandStop.java @@ -17,8 +17,7 @@ public class SubCommandStop extends SubCommand @Override public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input) { - return new SubCommandFormattable(guild.audio.stopPlayer(guild.audio.player)); } -} +} \ No newline at end of file diff --git a/src/utils/audio/AudioUtils.java b/src/utils/audio/AudioUtils.java index fa99919..3dbaaf3 100644 --- a/src/utils/audio/AudioUtils.java +++ b/src/utils/audio/AudioUtils.java @@ -104,9 +104,9 @@ public class AudioUtils { playlist.add(track); } - if(!isPlaying) + + if(player.getPlayingTrack() == null) { - isPlaying = true; startPlay(player); } } @@ -118,21 +118,31 @@ public class AudioUtils guild.getAudioManager().setSendingHandler(new AudioPlayerSendHandler(player)); playerManager.loadItemOrdered(player, videoURL, new SmallAudio(player)); + return null; } private void startPlay(AudioPlayer player) { + isPlaying = false; do { if(player.getPlayingTrack() == null) { - player.startTrack(playlist.get(0), false); - if(!playlist.isEmpty()) - playlist.remove(0); + if(playlist.isEmpty()) + { + isPlaying = false; + } + else + { + player.startTrack(playlist.get(0), false); + + if(!playlist.isEmpty()) + playlist.remove(0); + } } } - while(!playlist.isEmpty()); + while(isPlaying); isPlaying = false; } From 3a037931241287ff293f98054d9cbae2009de9e0 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 15 Jan 2020 01:51:23 -0500 Subject: [PATCH 09/11] Youtube Progress --- src/utils/audio/AudioUtils.java | 6 +++- src/utils/audio/TrackScheduler.java | 56 +++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 src/utils/audio/TrackScheduler.java diff --git a/src/utils/audio/AudioUtils.java b/src/utils/audio/AudioUtils.java index 3dbaaf3..a98cc25 100644 --- a/src/utils/audio/AudioUtils.java +++ b/src/utils/audio/AudioUtils.java @@ -124,18 +124,21 @@ public class AudioUtils private void startPlay(AudioPlayer player) { - isPlaying = false; + do { if(player.getPlayingTrack() == null) { + System.out.println("HERE"); if(playlist.isEmpty()) { isPlaying = false; } else { + System.out.println("NEXT SONG"); player.startTrack(playlist.get(0), false); + isPlaying = true; if(!playlist.isEmpty()) playlist.remove(0); @@ -152,6 +155,7 @@ public class AudioUtils try { playlist.remove(0); + player.getPlayingTrack(); } catch(Exception e) { diff --git a/src/utils/audio/TrackScheduler.java b/src/utils/audio/TrackScheduler.java new file mode 100644 index 0000000..e5a1f3b --- /dev/null +++ b/src/utils/audio/TrackScheduler.java @@ -0,0 +1,56 @@ +package utils.audio; +import com.sedmelluq.discord.lavaplayer.player.AudioPlayer; +import com.sedmelluq.discord.lavaplayer.player.event.AudioEventAdapter; +import com.sedmelluq.discord.lavaplayer.track.AudioTrack; +import com.sedmelluq.discord.lavaplayer.track.AudioTrackEndReason; + +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.LinkedBlockingQueue; + +/** + * This class schedules tracks for the audio player. It contains the queue of tracks. + */ +public class TrackScheduler extends AudioEventAdapter { + private final AudioPlayer player; + private final BlockingQueue queue; + + /** + * @param player The audio player this scheduler uses + */ + public TrackScheduler(AudioPlayer player) { + this.player = player; + this.queue = new LinkedBlockingQueue<>(); + } + + /** + * Add the next track to queue or play right away if nothing is in the queue. + * + * @param track The track to play or add to queue. + */ + public void queue(AudioTrack track) + { + // Calling startTrack with the noInterrupt set to true will start the track only if nothing is currently playing. If + // something is playing, it returns false and does nothing. In that case the player was already playing so this + // track goes to the queue instead. + if (!player.startTrack(track, true)) { + queue.offer(track); + } + } + + /** + * Start the next track, stopping the current one if it is playing. + */ + public void nextTrack() { + // Start the next track, regardless of if something is already playing or not. In case queue was empty, we are + // giving null to startTrack, which is a valid argument and will simply stop the player. + player.startTrack(queue.poll(), false); + } + + @Override + public void onTrackEnd(AudioPlayer player, AudioTrack track, AudioTrackEndReason endReason) { + // Only start the next track if the end reason is suitable for it (FINISHED or LOAD_FAILED) + if (endReason.mayStartNext) { + nextTrack(); + } + } +} \ No newline at end of file From 0d4015fff02d4b594610ee49347bbc4f01e86684 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 16 Jan 2020 03:16:27 -0500 Subject: [PATCH 10/11] youtube fix --- src/utils/audio/AudioUtils.java | 43 ++++++++++++--------------------- 1 file changed, 15 insertions(+), 28 deletions(-) diff --git a/src/utils/audio/AudioUtils.java b/src/utils/audio/AudioUtils.java index a98cc25..4ab68e2 100644 --- a/src/utils/audio/AudioUtils.java +++ b/src/utils/audio/AudioUtils.java @@ -20,7 +20,7 @@ public class AudioUtils public AudioManager am; public final AudioPlayer player; public final AudioPlayerManager playerManager; - private boolean isPlaying = false; +// private boolean isPlaying = false; private ArrayList playlist = new ArrayList(); @@ -86,11 +86,11 @@ public class AudioUtils public class SmallAudio implements AudioLoadResultHandler { - private AudioPlayer player; +// private AudioPlayer player; private SmallAudio(AudioPlayer player) { - this.player = player; +// this.player = player; } @Override public void loadFailed(FriendlyException arg0) { } @@ -104,11 +104,6 @@ public class AudioUtils { playlist.add(track); } - - if(player.getPlayingTrack() == null) - { - startPlay(player); - } } } @@ -117,36 +112,28 @@ public class AudioUtils { guild.getAudioManager().setSendingHandler(new AudioPlayerSendHandler(player)); playerManager.loadItemOrdered(player, videoURL, new SmallAudio(player)); - - + try { + Thread.sleep(1000); + } catch (InterruptedException e) {} + if(player.getPlayingTrack() == null) + { + System.out.println("HERE"); + startPlay(player); + } return null; } private void startPlay(AudioPlayer player) { - do { - if(player.getPlayingTrack() == null) + if(!playlist.isEmpty()) { - System.out.println("HERE"); - if(playlist.isEmpty()) - { - isPlaying = false; - } - else - { - System.out.println("NEXT SONG"); - player.startTrack(playlist.get(0), false); - isPlaying = true; - - if(!playlist.isEmpty()) - playlist.remove(0); - } + player.startTrack(playlist.get(0), false); + playlist.remove(0); } } - while(isPlaying); - isPlaying = false; + while(!playlist.isEmpty()); } public String skipVideo(AudioPlayer player) From 86d7e58838b35d00920399e411ac96f8b43a1f36 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 9 Feb 2020 23:06:45 -0500 Subject: [PATCH 11/11] =Youtube Fixes --- src/core/CommandThread.java | 2 +- src/utils/audio/AudioUtils.java | 68 +++++++++++++++++++-------------- 2 files changed, 40 insertions(+), 30 deletions(-) diff --git a/src/core/CommandThread.java b/src/core/CommandThread.java index 2d044e5..070d0eb 100644 --- a/src/core/CommandThread.java +++ b/src/core/CommandThread.java @@ -52,4 +52,4 @@ public class CommandThread extends Thread e.printStackTrace(); } } -} +} \ No newline at end of file diff --git a/src/utils/audio/AudioUtils.java b/src/utils/audio/AudioUtils.java index 4ab68e2..7430926 100644 --- a/src/utils/audio/AudioUtils.java +++ b/src/utils/audio/AudioUtils.java @@ -20,7 +20,6 @@ public class AudioUtils public AudioManager am; public final AudioPlayer player; public final AudioPlayerManager playerManager; -// private boolean isPlaying = false; private ArrayList playlist = new ArrayList(); @@ -85,12 +84,9 @@ public class AudioUtils } public class SmallAudio implements AudioLoadResultHandler - { -// private AudioPlayer player; - + { private SmallAudio(AudioPlayer player) { -// this.player = player; } @Override public void loadFailed(FriendlyException arg0) { } @@ -117,37 +113,15 @@ public class AudioUtils } catch (InterruptedException e) {} if(player.getPlayingTrack() == null) { - System.out.println("HERE"); - startPlay(player); + MusicController control = new MusicController(player, playlist); + control.start(); } return null; } - private void startPlay(AudioPlayer player) - { - do - { - if(!playlist.isEmpty()) - { - player.startTrack(playlist.get(0), false); - playlist.remove(0); - } - } - while(!playlist.isEmpty()); - } - public String skipVideo(AudioPlayer player) { player.stopTrack(); - try - { - playlist.remove(0); - player.getPlayingTrack(); - } - catch(Exception e) - { - return "Stopped"; - } return "Skipped"; } @@ -163,3 +137,39 @@ public class AudioUtils return playlist; } } + +class MusicController extends Thread +{ + AudioPlayer player; + private ArrayList playlist; + + public MusicController(AudioPlayer player, ArrayList playlist) + { + this.player = player; + this.playlist = playlist; + } + + @Override + public void run() + { + AudioTrack nowPlaying = null; + do + { + if(!playlist.isEmpty() || nowPlaying != null) + { + if(player.getPlayingTrack() == null) + { + if(playlist.isEmpty()) + nowPlaying = null; + else + { + nowPlaying = playlist.get(0); + playlist.remove(0); + } + player.startTrack(nowPlaying, false); + } + } + } + while(!playlist.isEmpty() || player.getPlayingTrack() != null); + } +}