21 Commits
Author SHA1 Message Date
Matthew Cech 8cfb3b951c = dew placeholder wip 2019-10-17 21:43:19 -07:00
Matthew Cech 01f39aba68 - removed unused unused 2019-09-26 20:07:52 -07:00
Matthew Cech e642551019 + Added stubs and some error checking to prevent lockout. 2019-09-14 01:31:16 -07:00
Matthew Cech 861aa95d96 = Adjusting last message response to be a bit less horrible. Still needs overhaul. 2019-09-14 01:11:24 -07:00
Matthew Cech 9b5ae3371d + Highly experimental last message info now saved 2019-09-14 00:56:45 -07:00
Matthew Cech 9d0bbf0ed1 + Added exception logging and fixed dice rolling 2019-09-13 22:32:37 -07:00
Matthew Cech b96d96c849 + Added super basic initial implementaiton of realm visualization and input 2019-09-13 00:28:26 -07:00
Matthew Cech e81e0972a3 + Added visualize basics 2019-09-12 23:51:20 -07:00
Matthew Cech b3187bb89d = Updated color to allow for parsing even with text after it 2019-09-12 23:18:23 -07:00
Matthew Cech d681bb6a4d Merge branch 'develop' into feature/dew 2019-09-12 22:50:23 -07:00
Matthew Cech 96b4533b39 = read/write first pass - seems to work! :D 2019-09-12 02:35:59 -07:00
Matthew Cech 498c3b84bc + Added lua reading and writing basics 2019-09-12 00:17:07 -07:00
Matthew Cech 4b8b125d05 + Added lua writing functionality 2019-09-11 23:10:36 -07:00
Matthew Cech cf7bd68658 + Added adapter concept 2019-09-11 19:53:20 -07:00
Matthew Cech 1e73f6adae + Weh csv 2019-09-11 14:43:09 -07:00
Matthew Cech 9d892e7fc2 + Added "weh" command 2019-09-11 14:42:01 -07:00
Matthew Cech 2fd273c298 + Added core base for dew 2019-09-11 14:28:18 -07:00
Matthew Cech 7581dab87d + Added dew command and generated CSV content for it 2019-09-11 14:10:56 -07:00
Matthew Cech 28377cf78e = Move benchmark core to fit existing standard 2019-09-11 14:03:02 -07:00
Matthew Cech d1dfab411e = Updated return, sorted bench 2019-09-11 14:01:32 -07:00
Matthew Cech 770ed84983 + Add dew base 2019-09-11 13:58:46 -07:00
43 changed files with 940 additions and 54 deletions
+7
View File
@@ -16,6 +16,7 @@
"Localized Commands","dbstats","" "Localized Commands","dbstats",""
"Localized Commands","defaultdance","" "Localized Commands","defaultdance",""
"Localized Commands","derp","" "Localized Commands","derp",""
"Localized Commands","dew",""
"Localized Commands","e621","" "Localized Commands","e621",""
"Localized Commands","eightball, 8ball","" "Localized Commands","eightball, 8ball",""
"Localized Commands","fetch","" "Localized Commands","fetch",""
@@ -48,6 +49,7 @@
"Localized Commands","tony, stark, dontfeelgood, dontfeelsogood","tony, stark, dontfeelgood, dontfeelsogood, snap" "Localized Commands","tony, stark, dontfeelgood, dontfeelsogood","tony, stark, dontfeelgood, dontfeelsogood, snap"
"Localized Commands","tweet","" "Localized Commands","tweet",""
"Localized Commands","vote","" "Localized Commands","vote",""
"Localized Commands","weh",""
"Localized Commands","wolfram","" "Localized Commands","wolfram",""
"Localized Commands","work","" "Localized Commands","work",""
"Localized Commands","yeet","" "Localized Commands","yeet",""
@@ -60,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","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","BetBeansLose","Sorry, you didn't win, try again!"
"Localized Strings","BetBeansLowBet","Please bet with at least 20 beans!" "Localized Strings","BetBeansLowBet","Please bet with at least 20 beans!"
"Localized Strings","BetBeansMinThreshold","50"
"Localized Strings","BetBeansNotEnough","You don't have enough beans!" "Localized Strings","BetBeansNotEnough","You don't have enough beans!"
"Localized Strings","BetBeansNotValid","That's not a valid bet!" "Localized Strings","BetBeansNotValid","That's not a valid bet!"
"Localized Strings","BetBeansWin","You won %s beans!" "Localized Strings","BetBeansWin","You won %s beans!"
@@ -107,6 +110,7 @@
"Localized Strings","DBFlushInfo","Takes all objects queued for the database and writes them to the database, then says how many were written." "Localized Strings","DBFlushInfo","Takes all objects queued for the database and writes them to the database, then says how many were written."
"Localized Strings","DBStatsInfo","Shows current statistics for the database" "Localized Strings","DBStatsInfo","Shows current statistics for the database"
"Localized Strings","DefaultDanceInfo","y'all know forknife, get ready to dance, or make a friend dance with @!" "Localized Strings","DefaultDanceInfo","y'all know forknife, get ready to dance, or make a friend dance with @!"
"Localized Strings","DewInfo","A fun little dev experiment!"
"Localized Strings","DoWorkFinished","I finished with my work! :D" "Localized Strings","DoWorkFinished","I finished with my work! :D"
"Localized Strings","DoWorkInfo","Occupies a core for a few seconds" "Localized Strings","DoWorkInfo","Occupies a core for a few seconds"
"Localized Strings","EightBallError","Hmm? You'll need to ask a question!" "Localized Strings","EightBallError","Hmm? You'll need to ask a question!"
@@ -240,6 +244,7 @@
"Localized Strings","TradeBeansSuccess","%s gave %s %s beans!" "Localized Strings","TradeBeansSuccess","%s gave %s %s beans!"
"Localized Strings","TweetError","Tweet command failed!" "Localized Strings","TweetError","Tweet command failed!"
"Localized Strings","TweetInfo","Kitty will tweet to her personal twitter account" "Localized Strings","TweetInfo","Kitty will tweet to her personal twitter account"
"Localized Strings","WehInfo","Weh"
"Localized Strings","WolframError","Something went wrong!" "Localized Strings","WolframError","Something went wrong!"
"Localized Strings","WolframInfo","Will query wolframalpha with your question and give a full image output of the answer" "Localized Strings","WolframInfo","Will query wolframalpha with your question and give a full image output of the answer"
"Localized Strings","WolframNoArgs","You need to provide some arguments!" "Localized Strings","WolframNoArgs","You need to provide some arguments!"
@@ -267,6 +272,7 @@
"Command Enabler","dbstats","1" "Command Enabler","dbstats","1"
"Command Enabler","defaultdance","1" "Command Enabler","defaultdance","1"
"Command Enabler","derp","1" "Command Enabler","derp","1"
"Command Enabler","dew","1"
"Command Enabler","e621","1" "Command Enabler","e621","1"
"Command Enabler","eightball, 8ball","1" "Command Enabler","eightball, 8ball","1"
"Command Enabler","fetch","1" "Command Enabler","fetch","1"
@@ -310,6 +316,7 @@
"Command Enabler","tony, stark, dontfeelgood, dontfeelsogood","1" "Command Enabler","tony, stark, dontfeelgood, dontfeelsogood","1"
"Command Enabler","tweet","1" "Command Enabler","tweet","1"
"Command Enabler","vote","1" "Command Enabler","vote","1"
"Command Enabler","weh","1"
"Command Enabler","wolfram","1" "Command Enabler","wolfram","1"
"Command Enabler","work","1" "Command Enabler","work","1"
"Command Enabler","yeet","1" "Command Enabler","yeet","1"
1 Type Key Value
16 Localized Commands dbstats
17 Localized Commands defaultdance
18 Localized Commands derp
19 Localized Commands dew
20 Localized Commands e621
21 Localized Commands eightball, 8ball
22 Localized Commands fetch
49 Localized Commands tony, stark, dontfeelgood, dontfeelsogood tony, stark, dontfeelgood, dontfeelsogood, snap
50 Localized Commands tweet
51 Localized Commands vote
52 Localized Commands weh
53 Localized Commands wolfram
54 Localized Commands work
55 Localized Commands yeet
62 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
63 Localized Strings BetBeansLose Sorry, you didn't win, try again!
64 Localized Strings BetBeansLowBet Please bet with at least 20 beans!
65 Localized Strings BetBeansMinThreshold 50
66 Localized Strings BetBeansNotEnough You don't have enough beans!
67 Localized Strings BetBeansNotValid That's not a valid bet!
68 Localized Strings BetBeansWin You won %s beans!
110 Localized Strings DBFlushInfo Takes all objects queued for the database and writes them to the database, then says how many were written.
111 Localized Strings DBStatsInfo Shows current statistics for the database
112 Localized Strings DefaultDanceInfo y'all know forknife, get ready to dance, or make a friend dance with @!
113 Localized Strings DewInfo A fun little dev experiment!
114 Localized Strings DoWorkFinished I finished with my work! :D
115 Localized Strings DoWorkInfo Occupies a core for a few seconds
116 Localized Strings EightBallError Hmm? You'll need to ask a question!
244 Localized Strings TradeBeansSuccess %s gave %s %s beans!
245 Localized Strings TweetError Tweet command failed!
246 Localized Strings TweetInfo Kitty will tweet to her personal twitter account
247 Localized Strings WehInfo Weh
248 Localized Strings WolframError Something went wrong!
249 Localized Strings WolframInfo Will query wolframalpha with your question and give a full image output of the answer
250 Localized Strings WolframNoArgs You need to provide some arguments!
272 Command Enabler dbstats 1
273 Command Enabler defaultdance 1
274 Command Enabler derp 1
275 Command Enabler dew 1
276 Command Enabler e621 1
277 Command Enabler eightball, 8ball 1
278 Command Enabler fetch 1
316 Command Enabler tony, stark, dontfeelgood, dontfeelsogood 1
317 Command Enabler tweet 1
318 Command Enabler vote 1
319 Command Enabler weh 1
320 Command Enabler wolfram 1
321 Command Enabler work 1
322 Command Enabler yeet 1
@@ -2,11 +2,11 @@ package commands.benchmark;
import java.util.List; import java.util.List;
import core.benchmark.BenchmarkCommand; import commands.benchmark.core.BenchmarkCommand;
import core.benchmark.BenchmarkEntry; import commands.benchmark.core.BenchmarkEntry;
import core.benchmark.BenchmarkFormattable; import commands.benchmark.core.BenchmarkFormattable;
import core.benchmark.BenchmarkInput; import commands.benchmark.core.BenchmarkInput;
import core.benchmark.BenchmarkManager; import commands.benchmark.core.BenchmarkManager;
public class BenchmarkCommandCompare extends BenchmarkCommand public class BenchmarkCommandCompare extends BenchmarkCommand
{ {
@@ -2,7 +2,11 @@ package commands.benchmark;
import java.util.List; import java.util.List;
import core.benchmark.*; import commands.benchmark.core.BenchmarkCommand;
import commands.benchmark.core.BenchmarkEntry;
import commands.benchmark.core.BenchmarkFormattable;
import commands.benchmark.core.BenchmarkInput;
import commands.benchmark.core.BenchmarkManager;
public class BenchmarkCommandFind extends BenchmarkCommand public class BenchmarkCommandFind extends BenchmarkCommand
{ {
@@ -2,11 +2,11 @@ package commands.benchmark;
import java.util.List; import java.util.List;
import core.benchmark.BenchmarkCommand; import commands.benchmark.core.BenchmarkCommand;
import core.benchmark.BenchmarkEntry; import commands.benchmark.core.BenchmarkEntry;
import core.benchmark.BenchmarkFormattable; import commands.benchmark.core.BenchmarkFormattable;
import core.benchmark.BenchmarkInput; import commands.benchmark.core.BenchmarkInput;
import core.benchmark.BenchmarkManager; import commands.benchmark.core.BenchmarkManager;
import dataStructures.KittyEmbed; import dataStructures.KittyEmbed;
import java.awt.Color; import java.awt.Color;
@@ -1,9 +1,9 @@
package commands.general; package commands.benchmark;
import commands.benchmark.core.BenchmarkFormattable;
import commands.benchmark.core.BenchmarkFramework;
import core.Command; import core.Command;
import core.LocStrings; import core.LocStrings;
import core.benchmark.BenchmarkFormattable;
import core.benchmark.BenchmarkFramework;
import dataStructures.KittyChannel; import dataStructures.KittyChannel;
import dataStructures.KittyGuild; import dataStructures.KittyGuild;
import dataStructures.KittyRating; import dataStructures.KittyRating;
@@ -1,4 +1,4 @@
package core.benchmark; package commands.benchmark.core;
public abstract class BenchmarkCommand public abstract class BenchmarkCommand
{ {
@@ -1,4 +1,4 @@
package core.benchmark; package commands.benchmark.core;
public class BenchmarkEntry public class BenchmarkEntry
{ {
@@ -1,4 +1,4 @@
package core.benchmark; package commands.benchmark.core;
import dataStructures.KittyEmbed; import dataStructures.KittyEmbed;
import dataStructures.Response; import dataStructures.Response;
@@ -1,4 +1,4 @@
package core.benchmark; package commands.benchmark.core;
import java.util.HashMap; import java.util.HashMap;
import commands.benchmark.*; import commands.benchmark.*;
@@ -1,4 +1,4 @@
package core.benchmark; package commands.benchmark.core;
import utils.StringUtils; import utils.StringUtils;
@@ -1,4 +1,4 @@
package core.benchmark; package commands.benchmark.core;
import utils.GlobalLog; import utils.GlobalLog;
@@ -1,4 +1,4 @@
package core.benchmark; package commands.benchmark.core;
import java.time.Instant; import java.time.Instant;
import java.util.ArrayList; import java.util.ArrayList;
@@ -1,4 +1,4 @@
package core.benchmark; package commands.benchmark.core;
public enum BenchmarkType public enum BenchmarkType
{ {
+43
View File
@@ -0,0 +1,43 @@
package commands.dew;
import commands.dew.core.impl.DewCore;
import core.Command;
import core.LocStrings;
import core.SubCommandFramework;
import dataStructures.KittyChannel;
import dataStructures.KittyGuild;
import dataStructures.KittyRating;
import dataStructures.KittyRole;
import dataStructures.KittyUser;
import dataStructures.Response;
import dataStructures.UserInput;
public class CommandDew extends Command
{
public static DewCore core;
SubCommandFramework framework = new SubCommandFramework();
@Override
public String getHelpText() { return LocStrings.stub("DewInfo"); }
@Override
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
{
framework.run(guild, channel, user, input).Call(res);
}
public CommandDew(KittyRole level, KittyRating rating)
{
super(level, rating);
core = new DewCore(framework);
framework.addCommand("luatest", new CommandDewLuaTest(KittyRole.Dev, KittyRating.Safe));
framework.addCommand("realm", new CommandDewRealm(KittyRole.Dev, KittyRating.Safe));
framework.addCommand("w", new CommandDewInput("w", KittyRole.Dev, KittyRating.Safe));
framework.addCommand("a", new CommandDewInput("a", KittyRole.Dev, KittyRating.Safe));
framework.addCommand("s", new CommandDewInput("s", KittyRole.Dev, KittyRating.Safe));
framework.addCommand("d", new CommandDewInput("d", KittyRole.Dev, KittyRating.Safe));
framework.addCommand("capture", new CommandDewCapture(KittyRole.Dev, KittyRating.Safe));
}
}
+28
View File
@@ -0,0 +1,28 @@
package commands.dew;
import commands.dew.adapter.KittyAdapterDewPlayer;
import commands.dew.core.impl.DewCore;
import core.SubCommand;
import core.SubCommandFormattable;
import dataStructures.KittyChannel;
import dataStructures.KittyGuild;
import dataStructures.KittyRating;
import dataStructures.KittyRole;
import dataStructures.KittyUser;
import dataStructures.UserInput;
public class CommandDewCapture extends SubCommand
{
public CommandDewCapture(KittyRole roleLevel, KittyRating contentRating)
{
super(roleLevel, contentRating);
}
@Override
public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input)
{
KittyAdapterDewPlayer player = DewCore.getOrCreate(user);
DewCore.playersCaptured.add(player);
return null;//new SubCommandFormattable("captured input for " + user.name);
}
}
+41
View File
@@ -0,0 +1,41 @@
package commands.dew;
import commands.dew.adapter.KittyAdapterDewPlayer;
import commands.dew.core.impl.DewCore;
import core.SubCommand;
import core.SubCommandFormattable;
import dataStructures.KittyChannel;
import dataStructures.KittyGuild;
import dataStructures.KittyRating;
import dataStructures.KittyRole;
import dataStructures.KittyUser;
import dataStructures.UserInput;
public class CommandDewInput extends SubCommand
{
String letter = "";
public CommandDewInput(String letter, KittyRole roleLevel, KittyRating contentRating)
{
super(roleLevel, contentRating);
this.letter = letter.toLowerCase();
}
@Override
public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input)
{
KittyAdapterDewPlayer player = DewCore.getOrCreate(user);
int x = player.getRealmX();
int y = player.getRealmY();
switch(letter)
{
case "w": player.setRealmPos(x, y - 1); break;
case "a": player.setRealmPos(x - 1, y); break;
case "s": player.setRealmPos(x, y + 1); break;
case "d": player.setRealmPos(x + 1, y); break;
}
return new SubCommandFormattable(DewCore.drawWorld(player));
}
}
+67
View File
@@ -0,0 +1,67 @@
package commands.dew;
import java.util.UUID;
import commands.dew.core.data.*;
import commands.dew.core.impl.DewLuaCore;
import core.SubCommand;
import core.SubCommandFormattable;
import dataStructures.KittyChannel;
import dataStructures.KittyGuild;
import dataStructures.KittyRating;
import dataStructures.KittyRole;
import dataStructures.KittyUser;
import dataStructures.UserInput;
public class CommandDewLuaTest extends SubCommand
{
public CommandDewLuaTest(KittyRole roleLevel, KittyRating contentRating)
{
super(roleLevel, contentRating);
}
private String asCodeBlock(String string)
{
return "```lua\n" + string + "```";
}
private String asCodeLine(String string)
{
return "`" + string + "`";
}
@Override
public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input)
{
String out = "";
try
{
out += "**Testing writing...\n**";
DewRealm m = new DewRealm();
m.id = UUID.randomUUID().toString();
String out1 = DewLuaCore.toLua(m);
out += asCodeBlock(out1);
String out2 = DewLuaCore.toLua(new DewMovementInfo());
out += asCodeBlock(out2);
out += "**Testing Reading...**\n";
DewRealm map = new DewRealm();
DewLuaCore.fromLua(map, out1);
out += "ID from 1st write: " + asCodeLine(map.id) + "\n";
DewMovementInfo move = new DewMovementInfo();
DewLuaCore.fromLua(move, out2);
out += "Qualified type test: " + asCodeLine(move.toString()) + "\n";
}
catch (Exception e)
{
e.printStackTrace(System.err);
}
return new SubCommandFormattable(out);
}
}
+31
View File
@@ -0,0 +1,31 @@
package commands.dew;
import commands.dew.adapter.KittyAdapterDewPlayer;
import commands.dew.core.impl.DewCore;
import core.SubCommand;
import core.SubCommandFormattable;
import dataStructures.KittyChannel;
import dataStructures.KittyGuild;
import dataStructures.KittyRating;
import dataStructures.KittyRole;
import dataStructures.KittyUser;
import dataStructures.UserInput;
public class CommandDewRealm extends SubCommand
{
public CommandDewRealm(KittyRole roleLevel, KittyRating contentRating)
{
super(roleLevel, contentRating);
}
@Override
public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input)
{
KittyAdapterDewPlayer player = DewCore.getOrCreate(user);
String out = DewCore.drawWorld(player);
return new SubCommandFormattable(out);
}
}
@@ -0,0 +1,71 @@
package commands.dew.adapter;
import commands.dew.core.api.IDewPlayer;
import commands.dew.core.data.DewRealm;
import dataStructures.KittyUser;
public class KittyAdapterDewPlayer implements IDewPlayer
{
private KittyUser user;
private String realmID;
private int x;
private int y;
public KittyAdapterDewPlayer(DewRealm realm, KittyUser user, int x, int y)
{
this.user = user;
this.realmID = realm.id;
this.x = x;
this.y = y;
}
public String getVisual()
{
return user.name.length() >= 1 ? user.name.substring(0, 1) : "@";
}
public boolean isUser(KittyUser user)
{
return user.uniqueID == user.uniqueID;
}
public void setRealmPos(int x, int y)
{
this.x = x;
this.y = y;
}
////////////////////////////
// Interface requirements //
////////////////////////////
@Override
public String getName()
{
return user.name;
}
@Override
public String getUniqueID()
{
return user.uniqueID;
}
@Override
public String getCurrentRealmID()
{
return realmID;
}
@Override
public int getRealmX()
{
return x;
}
@Override
public int getRealmY()
{
return y;
}
}
+5
View File
@@ -0,0 +1,5 @@
package commands.dew.core.api;
public interface IDewCore {
}
@@ -0,0 +1,6 @@
package commands.dew.core.api;
public interface IDewEntity
{
public String getUniqueID();
}
@@ -0,0 +1,6 @@
package commands.dew.core.api;
public interface IDewLuaCore
{
}
@@ -0,0 +1,6 @@
package commands.dew.core.api;
public interface IDewLuaSerializable<T>
{
// Type info for derived class encoded in T
}
@@ -0,0 +1,19 @@
package commands.dew.core.api;
// Commands are standalone pieces of data that contain only structures.
// Each command is simplistic and represents an action in the game world.
// Format:
/*
return
{
name="SomeCommand",
data={
-- some object here --
}
}
*/
public interface IDewMessage<T>
{
public String getMessageName();
public T getData();
}
@@ -0,0 +1,9 @@
package commands.dew.core.api;
public interface IDewPlayer extends IDewEntity
{
public String getName();
public String getCurrentRealmID();
public int getRealmX();
public int getRealmY();
}
@@ -0,0 +1,18 @@
package commands.dew.core.data;
public enum DewMapTile
{
// Assign multiples of 2 for flag purposes
Default(0), Grass(1), Tree(2);
private final int value;
private DewMapTile(int value)
{
this.value = value;
}
public int getValue()
{
return value;
}
}
@@ -0,0 +1,11 @@
package commands.dew.core.data;
import commands.dew.core.api.IDewLuaSerializable;
// Treat all data objects as structs for the purposes of this.
public class DewMovementInfo implements IDewLuaSerializable<DewMovementInfo>
{
public String entityID;
public int x;
public int y;
}
+9
View File
@@ -0,0 +1,9 @@
package commands.dew.core.data;
import commands.dew.core.api.IDewLuaSerializable;
public final class DewRealm implements IDewLuaSerializable<DewRealm>
{
public String id = "0";
public int[][] map = new int[12][24]; // [Rows][Columns]
}
+174
View File
@@ -0,0 +1,174 @@
package commands.dew.core.impl;
import java.util.ArrayList;
import java.util.List;
import commands.dew.adapter.KittyAdapterDewPlayer;
import commands.dew.core.data.DewMapTile;
import commands.dew.core.data.DewRealm;
import core.SubCommandFormattable;
import core.SubCommandFramework;
import dataStructures.KittyChannel;
import dataStructures.KittyGuild;
import dataStructures.KittyUser;
import dataStructures.Response;
import dataStructures.UserInput;
import utils.GlobalLog;
import utils.LogFilter;
public class DewCore
{
// TODO: Make realm and players both per-realm
public static String responseHeader = "[Dewdrop Forest]";
public static DewRealm realm;
public static List<KittyAdapterDewPlayer> players;
public static List<KittyAdapterDewPlayer> playersCaptured;
private static SubCommandFramework framework;
public DewCore(SubCommandFramework framework)
{
DewCore.framework = framework;
DewCore.realm = new DewRealm();
DewCore.players = new ArrayList<KittyAdapterDewPlayer>();
DewCore.playersCaptured = new ArrayList<KittyAdapterDewPlayer>();
for(int y = 0; y < realm.map.length; ++y)
{
for(int x = 0; x < realm.map[y].length; ++x)
{
realm.map[y][x] = DewMapTile.Grass.getValue();
}
}
}
// Returns false if not captured, true if captured.
public static boolean ProcessIfCaptured(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput baseInput, Response res)
{
// Search for a captured player.
KittyAdapterDewPlayer player = null;
for(KittyAdapterDewPlayer p : playersCaptured)
{
if(p.getUniqueID() == user.uniqueID)
{
player = p;
break;
}
}
// If we didn't find that the person is captured, return false since we don't need to do anything.
if(player == null)
return false;
// See if we run anything - also, check to see if we need to exit.
boolean didRun = false;
try
{
UserInput toEdit = new UserInput(baseInput);
String key = toEdit.message.toLowerCase().trim();
toEdit.key = key;
toEdit.args = key;
switch(key)
{
case "cap":
case "capture":
case "uncapture":
case "stop":
case "quit":
case "exit":
playersCaptured.remove(player);
return false;
}
SubCommandFormattable f = framework.run(guild, channel, user, toEdit);
if(f != null)
{
Response.GetLastMessage((String last) -> {
if(last.contains(responseHeader))
Response.EditLastMessage(f.resString);
});
didRun = true;
}
}
catch(Exception e)
{
GlobalLog.error(LogFilter.Command, e);
}
if(didRun)
{
baseInput.deleteOriginInput();
}
return didRun;
}
public static KittyAdapterDewPlayer getOrCreate(KittyUser user)
{
for(KittyAdapterDewPlayer player : players)
{
if(player.getUniqueID() == user.uniqueID)
{
return player;
}
}
KittyAdapterDewPlayer player = new KittyAdapterDewPlayer(realm, user, 10, 10);
players.add(player);
return player;
}
public static String drawWorld(KittyAdapterDewPlayer player)
{
// Build empty world buffer
String[][] worldBuffer = new String[realm.map.length][realm.map[0].length];
// Build world
for(int y = 0; y < realm.map.length; ++y)
{
for(int x = 0; x < realm.map[y].length; ++x)
{
switch(DewMapTile.values()[realm.map[y][x]])
{
case Grass:
worldBuffer[y][x] = ",";
break;
default:
worldBuffer[y][x] = " ";
break;
}
}
}
// Build players
for(KittyAdapterDewPlayer p : players)
{
worldBuffer[p.getRealmY()][p.getRealmX()] = p.getVisual();
}
// Draw world
String out = "";
out += responseHeader + "\n";
out += "**Realm ID - ** `" + realm.id + "`\n";
for(int y = 0; y < worldBuffer.length; ++y)
{
out += "`";
for(int x = 0; x < worldBuffer[y].length; ++x)
{
out += worldBuffer[y][x];
}
out += "`";
out += "\n";
}
out += "**Stats**\n";
out += "`Player Name` - `" + player.getName() + "`\n";
out += "`Player Icon` - `" + player.getVisual() + "`\n";
return out;
}
}
+153
View File
@@ -0,0 +1,153 @@
package commands.dew.core.impl;
import java.lang.reflect.Field;
import org.luaj.vm2.Globals;
import org.luaj.vm2.LuaValue;
import org.luaj.vm2.Varargs;
import org.luaj.vm2.lib.jse.JsePlatform;
import commands.dew.core.api.IDewLuaCore;
import commands.dew.core.api.IDewLuaSerializable;
public class DewLuaCore implements IDewLuaCore
{
private static Globals globalLuaCore = null;
public static String toLua(IDewLuaSerializable<?> item)
{
return toLua(item, 0);
}
private static String tab(int num)
{
String line = "";
for(int i = 0; i < num; ++i)
line += "\t";
return line;
}
public static String toLua(IDewLuaSerializable<?> item, int tabs)
{
String out = tab(tabs) + "return {\n";
// Set up type information
out += tab(tabs + 1) + "type=\"" + item.getClass().getTypeName() + "\",\n";
// Set up data information
out += tab(tabs + 1) + "data={\n";
// Write data
Field[] fields = item.getClass().getDeclaredFields();
for(int i = 0; i < fields.length; ++i)
{
Field current = fields[i];
try
{
String line = "";
String fieldType = current.getType().toString().toLowerCase();
line += tab(tabs + 2);
line += current.getName() + "=";
switch(fieldType)
{
case "int":
line += "" + current.get(item);
break;
case "class java.lang.string":
String content = (String)current.get(item);
if(content == null || content.length() == 0)
line += "\"\"";
else
line += "\"" + content + "\"";
break;
// wrong name
case "dewmaptile ":
line += "\"" + current.get(item).toString() + "\"";
break;
default:
line += "nil";
System.err.print("Type could not be foramtted as lua: " + fieldType + "\n");
break;
}
// If we're not the last line, add a comma.
if(i != fields.length - 1)
line += ",";
out += line + "\n";
}
catch (Exception e)
{
e.printStackTrace(System.err);
}
}
out += tab(tabs + 1) + "}\n";
out += tab(tabs)+ "}\n";
return out;
}
@SuppressWarnings({ "unchecked" })
public static <T> void fromLua(T obj, String lua)
{
if(globalLuaCore == null)
{
globalLuaCore = JsePlatform.standardGlobals();
}
LuaValue luaResult = globalLuaCore.load(lua).call();
String type = luaResult.get("type").toString();
try
{
LuaValue data = luaResult.get("data");
Class<T> concreteClass = (Class<T>) Class.forName(type);
for(Field field : concreteClass.getDeclaredFields())
{
String name = field.getName();
LuaValue value = data.get(name);
if(!value.isnil())
{
String fieldType = field.getType().toString().toLowerCase();
switch(fieldType)
{
case "int":
field.set(obj, value.toint());
break;
case "class java.lang.string":
field.set(obj, value.toString());
break;
// Not the right name
case "dewmaptile":
default:
System.err.print("Could not set field of type: " + fieldType + "\n");
break;
}
}
else
{
System.err.println("Field was not in lua: " + name);
}
}
}
catch (Exception e)
{
e.printStackTrace(System.err);
}
}
}
@@ -0,0 +1,8 @@
package commands.dew.core.messages;
import commands.dew.core.api.IDewLuaSerializable;
public class DewMessageMovement implements IDewLuaSerializable<DewMessageMovement>
{
}
+21 -1
View File
@@ -31,8 +31,28 @@ public class CommandColor extends Command
@Override @Override
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res) public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
{ {
if(input.args == null || input.args.length() == 0)
{
res.send(LocStrings.stub("ColorNotSearchable"));
return;
}
String toFind = null;
String[] split = input.args.split(" ");
if(split.length >= 1)
toFind = split[0];
// First, try and parse out the color to make sure we can even get it. // First, try and parse out the color to make sure we can even get it.
ColorData colorData = theColorAPI.lookupHex(input.args.trim()); ColorData colorData = null;
if(toFind == null)
{
colorData = theColorAPI.lookupHex(input.args.trim());
}
else
{
colorData = theColorAPI.lookupHex(toFind.trim());
}
// Verify the color was even found // Verify the color was even found
if(colorData == null) if(colorData == null)
+13 -10
View File
@@ -7,6 +7,8 @@ import java.util.Stack;
import core.Command; import core.Command;
import core.LocStrings; import core.LocStrings;
import dataStructures.*; import dataStructures.*;
import utils.GlobalLog;
import utils.LogFilter;
public class CommandRoll extends Command public class CommandRoll extends Command
{ {
@@ -32,6 +34,7 @@ public class CommandRoll extends Command
} }
catch(Exception e) catch(Exception e)
{ {
GlobalLog.error(LogFilter.Command, e);
res.send(LocStrings.stub("RollError")); res.send(LocStrings.stub("RollError"));
} }
} }
@@ -170,18 +173,18 @@ public class CommandRoll extends Command
private int[] roll(int first, int second) private int[] roll(int first, int second)
{ {
int roll = 0; int numberOfDice = first;
int dice = first; int diceSideCount = second;
int sides = second; int [] rolls = new int[numberOfDice];
int [] rolls = new int [sides];
if(dice < 1) GlobalLog.log("number: " + numberOfDice + " diceSides: " + diceSideCount);
if(numberOfDice < 1)
return new int[0]; return new int[0];
for(int i = 0; dice > i; i ++)
{ for(int i = 0; i < numberOfDice; i++)
roll = (int)(Math.random() * sides) + 1; rolls[i] = (int)(Math.random() * diceSideCount + 1);
rolls[i] = roll;
}
return rolls; return rolls;
} }
+29
View File
@@ -0,0 +1,29 @@
package commands.general;
import core.Command;
import core.LocStrings;
import dataStructures.KittyChannel;
import dataStructures.KittyGuild;
import dataStructures.KittyRating;
import dataStructures.KittyRole;
import dataStructures.KittyUser;
import dataStructures.Response;
import dataStructures.UserInput;
public class CommandWeh extends Command {
public String getHelpText() { return LocStrings.stub("WehInfo"); }
public CommandWeh(KittyRole roleLevel, KittyRating contentRating) {
super(roleLevel, contentRating);
// TODO Auto-generated constructor stub
}
@Override
// The format for reutrning an emoji is: <:name:ID#>
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
{
res.send("<:weh:548301646929723393>");
}
}
@@ -1,7 +1,5 @@
package commands.music; package commands.music;
import com.google.api.services.youtube.YouTube;
import core.SubCommand; import core.SubCommand;
import core.SubCommandFormattable; import core.SubCommandFormattable;
import dataStructures.KittyChannel; import dataStructures.KittyChannel;
@@ -13,13 +11,11 @@ import dataStructures.UserInput;
public class SubCommandAddTrack extends SubCommand public class SubCommandAddTrack extends SubCommand
{ {
public SubCommandAddTrack(KittyRole level, KittyRating rating) { super(level, rating); } public SubCommandAddTrack(KittyRole level, KittyRating rating) { super(level, rating); }
@Override @Override
public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input) public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input)
{ {
return null; return null;
} }
} }
+4
View File
@@ -4,7 +4,9 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map.Entry; import java.util.Map.Entry;
import commands.benchmark.CommandBenchmark;
import commands.characters.CommandCharacterMain; import commands.characters.CommandCharacterMain;
import commands.dew.CommandDew;
import commands.general.*; import commands.general.*;
import commands.guildrole.CommandGuildRoleMain; import commands.guildrole.CommandGuildRoleMain;
import commands.mod.CommandModMain; import commands.mod.CommandModMain;
@@ -62,6 +64,7 @@ public class CommandManager
this.register(LocCommands.stub("tweet"), new CommandTweet(KittyRole.Dev, KittyRating.Safe)); this.register(LocCommands.stub("tweet"), new CommandTweet(KittyRole.Dev, KittyRating.Safe));
this.register(LocCommands.stub("dbflush"), new CommandDBFlush(KittyRole.Dev, KittyRating.Safe)); this.register(LocCommands.stub("dbflush"), new CommandDBFlush(KittyRole.Dev, KittyRating.Safe));
this.register(LocCommands.stub("dbstats"), new CommandDBStats(KittyRole.Dev, KittyRating.Safe)); this.register(LocCommands.stub("dbstats"), new CommandDBStats(KittyRole.Dev, KittyRating.Safe));
this.register(LocCommands.stub("dew"), new CommandDew(KittyRole.Dev, KittyRating.Safe));
// Admin // Admin
this.register(LocCommands.stub("rating"), new CommandRating(KittyRole.Admin, KittyRating.Safe)); this.register(LocCommands.stub("rating"), new CommandRating(KittyRole.Admin, KittyRating.Safe));
@@ -107,6 +110,7 @@ public class CommandManager
this.register(LocCommands.stub("poll"), new CommandPollMain(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("music"), new CommandMusicMain(KittyRole.General, KittyRating.Safe));
this.register(LocCommands.stub("defaultdance"), new CommandDefaultDance(KittyRole.General, KittyRating.Safe)); this.register(LocCommands.stub("defaultdance"), new CommandDefaultDance(KittyRole.General, KittyRating.Safe));
this.register(LocCommands.stub("weh"), new CommandWeh(KittyRole.General, KittyRating.Safe));
} }
// Allows the command manager to keep track of a command. Takes a pair (the un-localized and localzied commands) // Allows the command manager to keep track of a command. Takes a pair (the un-localized and localzied commands)
+6 -1
View File
@@ -7,6 +7,7 @@ import dataStructures.KittyGuild;
import dataStructures.KittyUser; import dataStructures.KittyUser;
import dataStructures.UserInput; import dataStructures.UserInput;
import utils.GlobalLog; import utils.GlobalLog;
import utils.LogFilter;
public class SubCommandFramework public class SubCommandFramework
{ {
@@ -41,10 +42,14 @@ public class SubCommandFramework
} }
catch(Exception e) catch(Exception e)
{ {
GlobalLog.error(LogFilter.Command, e);
String help = Stats.instance.getHelpText(input.key); String help = Stats.instance.getHelpText(input.key);
if(help != null) if(help != null)
return new SubCommandFormattable(help); return new SubCommandFormattable(help);
return new SubCommandFormattable("Something has gone very wrong.");
return new SubCommandFormattable("Whoops! Internal subcommand error!");
} }
} }
} }
@@ -0,0 +1,6 @@
package dataStructures;
public class KittyTrackedResponse
{
// TODO: Fill this out!
}
+78 -10
View File
@@ -2,11 +2,14 @@ package dataStructures;
import java.io.File; import java.io.File;
import java.io.InputStream; import java.io.InputStream;
import java.util.function.Consumer;
import net.dv8tion.jda.core.JDA; import net.dv8tion.jda.core.JDA;
import net.dv8tion.jda.core.MessageBuilder; import net.dv8tion.jda.core.MessageBuilder;
import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.entities.TextChannel; import net.dv8tion.jda.core.entities.TextChannel;
import net.dv8tion.jda.core.events.message.guild.*; import net.dv8tion.jda.core.events.message.guild.*;
import net.dv8tion.jda.core.requests.restaction.MessageAction;
import net.dv8tion.jda.core.EmbedBuilder; import net.dv8tion.jda.core.EmbedBuilder;
import utils.GlobalLog; import utils.GlobalLog;
import utils.LogFilter; import utils.LogFilter;
@@ -16,6 +19,9 @@ import utils.LogFilter;
// commands aren't exposed to the GuildMessageReceivedEvent then we should be fine. // commands aren't exposed to the GuildMessageReceivedEvent then we should be fine.
public class Response public class Response
{ {
// Last message
private static Message lastSentMessage = new MessageBuilder().append(" ").build();
// Variables // Variables
private GuildMessageReceivedEvent event; private GuildMessageReceivedEvent event;
private final int discordMessageMax = 2000; private final int discordMessageMax = 2000;
@@ -75,7 +81,7 @@ public class Response
File thumbImage = new File(thumbName); File thumbImage = new File(thumbName);
if(thumbImage.exists()) if(thumbImage.exists())
{ {
event.getChannel().sendFile(thumbImage, thumbName, message.build()).queue(); respond(event.getChannel().sendFile(thumbImage, thumbName, message.build()));
} }
} }
else else
@@ -83,7 +89,7 @@ public class Response
if(embedInfo.thumbnailURL != null) if(embedInfo.thumbnailURL != null)
embed.setThumbnail(embedInfo.thumbnailURL); embed.setThumbnail(embedInfo.thumbnailURL);
event.getChannel().sendMessage(embed.build()).queue(); respond(event.getChannel().sendMessage(embed.build()));
} }
} }
@@ -93,11 +99,11 @@ public class Response
GlobalLog.log(LogFilter.Response, "Sending response: " + toRespondWith); GlobalLog.log(LogFilter.Response, "Sending response: " + toRespondWith);
if(toRespondWith.length() > discordMessageMax) if(toRespondWith.length() > discordMessageMax)
{ {
event.getChannel().sendMessage(toRespondWith.substring(0, kittyMessageMax) + "\n\nI think that's enough!").queue(); respond(event.getChannel().sendMessage(toRespondWith.substring(0, kittyMessageMax) + "\n\nI think that's enough!"));
} }
else else
{ {
event.getChannel().sendMessage(toRespondWith).queue(); respond(event.getChannel().sendMessage(toRespondWith));
} }
} }
@@ -108,11 +114,11 @@ public class Response
channel = kitty.getTextChannelById(Long.parseLong(channelID)); channel = kitty.getTextChannelById(Long.parseLong(channelID));
if(toRespondWith.length() > discordMessageMax) if(toRespondWith.length() > discordMessageMax)
{ {
channel.sendMessage(toRespondWith.substring(0, kittyMessageMax) + "\n\nI think that's enough!").queue(); respond(channel.sendMessage(toRespondWith.substring(0, kittyMessageMax) + "\n\nI think that's enough!"));
} }
else else
{ {
channel.sendMessage(toRespondWith).queue(); respond(channel.sendMessage(toRespondWith));
} }
} }
@@ -122,11 +128,11 @@ public class Response
GlobalLog.log(LogFilter.Response, "Sending immediate response: " + toRespondWith); GlobalLog.log(LogFilter.Response, "Sending immediate response: " + toRespondWith);
if(toRespondWith.length() > discordMessageMax) if(toRespondWith.length() > discordMessageMax)
{ {
event.getChannel().sendMessage(toRespondWith.substring(0, kittyMessageMax) + "\n\nI think that's enough!"); respondImmediate(event.getChannel().sendMessage(toRespondWith.substring(0, kittyMessageMax) + "\n\nI think that's enough!"));
} }
else else
{ {
event.getChannel().sendMessage(toRespondWith).complete(); respondImmediate(event.getChannel().sendMessage(toRespondWith));
} }
} }
@@ -134,13 +140,75 @@ public class Response
public void sendFile(File toRespondWith, String extension) public void sendFile(File toRespondWith, String extension)
{ {
GlobalLog.log(LogFilter.Response, "Sending file response"); GlobalLog.log(LogFilter.Response, "Sending file response");
event.getChannel().sendFile(toRespondWith, "return." + extension).queue(); respond(event.getChannel().sendFile(toRespondWith, "return." + extension));
} }
// Queues an input stream response to the channel that issued the command. // Queues an input stream response to the channel that issued the command.
public void sendFile(InputStream in, String extension) public void sendFile(InputStream in, String extension)
{ {
GlobalLog.log(LogFilter.Response, "Sending input stream response"); GlobalLog.log(LogFilter.Response, "Sending input stream response");
event.getChannel().sendFile(in, "return." + extension).queue(); respond(event.getChannel().sendFile(in, "return." + extension));
}
////////////////////////
// Message Management //
////////////////////////
// Blast that message out and don't do anything else on this thread until sent.
// BLOCKING
protected void respondImmediate(MessageAction toSend)
{
synchronized(lastSentMessage)
{
lastSentMessage = toSend.complete();
}
}
// thread-safe assignment. Assignment may technically be out of order, so keep that in mind.
// ASYNC
protected void respond(MessageAction toSend)
{
toSend.submit().whenComplete((msg, err) -> {
synchronized(lastSentMessage)
{
lastSentMessage = msg;
}
});
}
// BLOCKING
public static String GetLastMessage()
{
synchronized(lastSentMessage)
{
if(lastSentMessage == null)
return null;
return lastSentMessage.getContentRaw();
}
}
// ASYNC
public static void GetLastMessage(Consumer<String> consumer)
{
synchronized(lastSentMessage)
{
if(lastSentMessage == null)
return;
consumer.accept(lastSentMessage.getContentRaw());
}
}
// BLOCKING
public static void EditLastMessage(String newContent)
{
synchronized(lastSentMessage)
{
if(lastSentMessage != null)
{
lastSentMessage.editMessage(newContent).queue();
}
}
} }
} }
+21
View File
@@ -4,6 +4,7 @@ import java.util.List;
import core.ObjectBuilderFactory; import core.ObjectBuilderFactory;
import net.dv8tion.jda.core.entities.Member; import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent; import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
public class UserInput public class UserInput
@@ -14,6 +15,7 @@ public class UserInput
public KittyUser [] mentions; public KittyUser [] mentions;
private boolean isValid; private boolean isValid;
public String message; public String message;
private Message internalJDAMessage;
// NOTE(wisp): Designed to parse a string as it's constructed. // NOTE(wisp): Designed to parse a string as it's constructed.
// If a user enters the command "!ping some stuff here :D" // If a user enters the command "!ping some stuff here :D"
@@ -25,6 +27,7 @@ public class UserInput
// The CommandIndicator and spaces between the key and args are dropped. // The CommandIndicator and spaces between the key and args are dropped.
public UserInput(GuildMessageReceivedEvent event, KittyGuild guildContext) public UserInput(GuildMessageReceivedEvent event, KittyGuild guildContext)
{ {
this.internalJDAMessage = event.getMessage();
String toParse = event.getMessage().getContentRaw(); String toParse = event.getMessage().getContentRaw();
message = toParse; message = toParse;
@@ -61,6 +64,18 @@ public class UserInput
} }
} }
// Copy Constructor
public UserInput(UserInput other)
{
this.key = other.key;
this.args = other.args;
this.mentions = other.mentions;
this.isValid = other.isValid;
this.message = other.message;
this.internalJDAMessage = other.internalJDAMessage;
}
// Used for injecting direct commands from plugins // Used for injecting direct commands from plugins
public UserInput(String input, KittyGuild contextGuild) public UserInput(String input, KittyGuild contextGuild)
{ {
@@ -75,6 +90,12 @@ public class UserInput
return isValid; return isValid;
} }
// This deletes the input that was originally sent
public void deleteOriginInput()
{
internalJDAMessage.delete().queue();
}
// Finds first whitespace in the string // Finds first whitespace in the string
private int findFirstWhitespace(String str) private int findFirstWhitespace(String str)
{ {
+7
View File
@@ -4,6 +4,7 @@ import java.util.List;
import javax.security.auth.login.LoginException; import javax.security.auth.login.LoginException;
import commands.dew.core.impl.DewCore;
import core.CharacterManager; import core.CharacterManager;
import core.CommandEnabler; import core.CommandEnabler;
import core.CommandManager; import core.CommandManager;
@@ -89,6 +90,10 @@ public class Main extends ListenerAdapter
if(!Superintendent.perCommandUpkeepPre(pluginManager)) if(!Superintendent.perCommandUpkeepPre(pluginManager))
return; return;
// TODO: Condense outer if somehow...
if(!DewCore.ProcessIfCaptured(guild, channel, user, input, response))
{
// Attempt to spin up a command. If the command doesn't exist. // Attempt to spin up a command. If the command doesn't exist.
// Run plugins right before invoking the commands but after all other setup. // Run plugins right before invoking the commands but after all other setup.
if(commandManager.invokeOnNewThread(guild, channel, user, input, response) == false) if(commandManager.invokeOnNewThread(guild, channel, user, input, response) == false)
@@ -111,6 +116,8 @@ public class Main extends ListenerAdapter
} }
} }
}
// Run any upkeep in post we need to // Run any upkeep in post we need to
if(!Superintendent.perCommandUpkeepPost(kittyCore, databaseManager)) if(!Superintendent.perCommandUpkeepPost(kittyCore, databaseManager))
return; return;
+1
View File
@@ -2,6 +2,7 @@ package main;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import commands.dew.core.impl.DewCore;
import core.Config; import core.Config;
import core.DatabaseManager; import core.DatabaseManager;
import core.RPManager; import core.RPManager;
+16 -6
View File
@@ -1,6 +1,7 @@
package utils; package utils;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.text.DateFormat; import java.text.DateFormat;
@@ -28,18 +29,27 @@ public class GlobalLog
GlobalLog.log(LogFilter.Util, "Finished initializing logging system"); GlobalLog.log(LogFilter.Util, "Finished initializing logging system");
} }
private static void write(String status, LogFilter filter, String body) private static void write(String status, LogFilter filter, String body, PrintStream stream)
{ {
String logLine = "[" + status + "] " + "[" + filter.name() + "] " + body; String logLine = "[" + status + "] " + "[" + filter.name() + "] " + body;
outputLog.write(logLine + "\n"); outputLog.write(logLine + "\n");
outputLog.flush(); outputLog.flush();
System.out.println(logLine); stream.println(logLine);
} }
public static void log(LogFilter filter, String msg) { write(log, filter, msg); } public static void log(LogFilter filter, String msg) { write(log, filter, msg, System.out); }
public static void warn(LogFilter filter, String msg) { write(warn, filter, msg); } public static void warn(LogFilter filter, String msg) { write(warn, filter, msg, System.out); }
public static void error(LogFilter filter, String msg) { write(error, filter, msg); System.err.println(msg); System.err.flush(); } public static void error(LogFilter filter, String msg) { write(error, filter, msg, System.err); System.err.println(msg); System.err.flush(); }
public static void fatal(LogFilter filter, String msg) throws Exception { write(fatal, filter, msg); throw new Exception(msg); } public static void error(LogFilter filter, Exception e)
{
write(error, filter, e.toString(), System.err);
e.printStackTrace(outputLog);
e.printStackTrace(System.err);
outputLog.flush();
System.err.flush();
}
public static void fatal(LogFilter filter, String msg) throws Exception { write(fatal, filter, msg, System.out); throw new Exception(msg); }
public static void log(String msg) { log(LogFilter.Debug, msg); } public static void log(String msg) { log(LogFilter.Debug, msg); }
public static void warn(String msg) { warn(LogFilter.Debug, msg); } public static void warn(String msg) { warn(LogFilter.Debug, msg); }