-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from Ashleyz4/master
Version 1.5
- Loading branch information
Showing
5 changed files
with
231 additions
and
89 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
src/com/johnymuffin/discordGameBridge/Cmd_DiscordBridge.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.johnymuffin.discordGameBridge; | ||
|
||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandExecutor; | ||
import org.bukkit.command.CommandSender; | ||
|
||
public class Cmd_DiscordBridge implements CommandExecutor { | ||
@Override | ||
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) { | ||
if(strings.length > 0) { | ||
if(strings[0].equalsIgnoreCase("reload")) { | ||
DiscordBot.getInstance().configReader.reload(); | ||
} | ||
} else { | ||
commandSender.sendMessage("/DiscordBridge reload"); | ||
} | ||
return false; | ||
} | ||
} |
158 changes: 88 additions & 70 deletions
158
src/com/johnymuffin/discordGameBridge/ConfigReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,103 +1,121 @@ | ||
package com.johnymuffin.discordGameBridge; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.io.FileInputStream; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.util.Properties; | ||
|
||
class ConfigReader { | ||
// New Config | ||
|
||
//discord.Discord().DiscordSendToChannel(gameBridge, | ||
//"**" + ((PlayerJoinEvent) event).getPlayer().getName() + "** Has Joined The Game [" | ||
//+ Bukkit.getServer().getOnlinePlayers().length + "/" | ||
//+ Bukkit.getServer().getMaxPlayers() + "]"); | ||
|
||
private String discordStartMessage = "**Server Has Started**"; | ||
private String discordChatMessage = "&f[&6Discord&f]&7 %messageAuthor%: %message%"; | ||
private String gameChatMessage = "**%messageAuthor%**: %message%"; | ||
private String joinMessage = "**%username%** Has Joined THe Game [%onlineCount%/%maxCount%]"; | ||
private String quitMessage = "**%username%** Has Quit THe Game [%onlineCount%/%maxCount%]"; | ||
|
||
private String joinMessage = "**%username%** Has Joined The Game [%onlineCount%/%maxCount%]"; | ||
private String quitMessage = "**%username%** Has Quit The Game [%onlineCount%/%maxCount%]"; | ||
private String timestampMessage = "**[%world%( - )%h%:%m%:%s%:%S% %ampm% %z%]** "; | ||
private String serverName = ""; | ||
private String channelID = ""; | ||
private Boolean PrensencePlayercount = true; | ||
private Boolean OnlineCommand = true; | ||
|
||
private boolean presencePlayercount = true; | ||
private boolean onlineCommand = true; | ||
private boolean announceStartStop = true; | ||
private boolean showTimestamp = true; | ||
private boolean useInGameTime = true; | ||
private boolean seperateChat = true; | ||
|
||
ConfigReader() { | ||
this.reload(); | ||
} | ||
|
||
ConfigReader(DiscordBot instance) { | ||
private int reloadTimes = 0; | ||
void reload() { | ||
Properties prop = new Properties(); | ||
|
||
DiscordBot instance = DiscordBot.getInstance(); | ||
if(reloadTimes > 3) { | ||
reloadTimes = 0; | ||
instance.logger.severe("[DiscordBot]: Failed to create/read properties file after 3 times at " + instance.config.getAbsolutePath()); | ||
return; | ||
} | ||
|
||
try { | ||
prop.load(new FileInputStream(instance.config)); | ||
} catch (IOException var4) { | ||
instance.logger.warning("[RetroBot] No properties found! Making new file..."); | ||
var4.printStackTrace(); | ||
instance.logger.warning("[DiscordBot]: No properties file found! Attempting to create..."); | ||
if(!instance.config.exists()) { | ||
try { | ||
boolean b = instance.config.createNewFile(); | ||
if(!b) { | ||
instance.logger.warning("[DiscordBot]: Failed to create file at " + instance.config.getAbsolutePath()); | ||
} else { | ||
reloadTimes++; | ||
instance.logger.fine("[DiscordBot]: Successfully created new config, trying again..."); | ||
reload(); | ||
} | ||
return; | ||
} catch(IOException e) { | ||
e.printStackTrace(); | ||
return; | ||
} | ||
} else { | ||
if(!instance.config.canRead()) { | ||
instance.logger.severe("[DiscordBot]: Can't read from config file at " + instance.config.getAbsolutePath()); | ||
return; | ||
} | ||
} | ||
} | ||
// New Config | ||
serverName = prop.getProperty("serverName", serverName); | ||
channelID = prop.getProperty("channelID", channelID); | ||
PrensencePlayercount = Boolean.parseBoolean(prop.getProperty("PrensencePlayercount", "" + PrensencePlayercount)); | ||
OnlineCommand = Boolean.parseBoolean(prop.getProperty("OnlineCommand", "" + OnlineCommand)); | ||
announceStartStop = Boolean.parseBoolean(prop.getProperty("announceStartStop", "" + announceStartStop)); | ||
//Join Custom Message | ||
joinMessage = prop.getProperty("joinMessage", joinMessage); | ||
prop.setProperty("joinMessage", joinMessage); | ||
//Quit Custom Message | ||
quitMessage = prop.getProperty("quitMessage", quitMessage); | ||
prop.setProperty("quitMessage", quitMessage); | ||
//Discord Chat Message | ||
discordChatMessage = prop.getProperty("discordChatMessage", discordChatMessage); | ||
prop.setProperty("discordChatMessage", discordChatMessage); | ||
//Game Chat Message | ||
gameChatMessage = prop.getProperty("gameChatMessage", gameChatMessage); | ||
prop.setProperty("gameChatMessage", gameChatMessage); | ||
//Announce Server Start/Stop | ||
|
||
prop.setProperty("OnlineCommand", "" + OnlineCommand); | ||
prop.setProperty("PrensencePlayercount", "" + PrensencePlayercount); | ||
prop.setProperty("channelID", channelID); | ||
prop.setProperty("serverName", serverName); | ||
prop.setProperty("announceStartStop", ""+announceStartStop); | ||
reloadTimes = 0; | ||
|
||
seperateChat = getAndSet_B(prop, "separateChat", seperateChat); | ||
showTimestamp = getAndSet_B(prop, "showTimestamp", showTimestamp); | ||
useInGameTime = getAndSet_B(prop, "useInGameTime", useInGameTime); | ||
presencePlayercount = getAndSet_B(prop, "presencePlayercount", presencePlayercount); | ||
onlineCommand = getAndSet_B(prop, "onlineCommand", onlineCommand); | ||
announceStartStop = getAndSet_B(prop, "announceStartStop", announceStartStop); | ||
|
||
serverName = getAndSet_S(prop, "serverName", serverName); | ||
channelID = getAndSet_S(prop, "channelID", channelID); | ||
joinMessage = getAndSet_S(prop, "joinMessage", joinMessage); | ||
quitMessage = getAndSet_S(prop, "quitMessage", quitMessage); | ||
discordStartMessage = getAndSet_S(prop, "discordStartMessage", discordStartMessage); | ||
discordChatMessage = getAndSet_S(prop, "discordChatMessage", discordChatMessage); | ||
gameChatMessage = getAndSet_S(prop, "gameChatMessage", gameChatMessage); | ||
timestampMessage = getAndSet_S(prop, "timestampMessage", timestampMessage); | ||
|
||
try { | ||
prop.store(new FileOutputStream(instance.config), "Properties for DiscordBot"); | ||
} catch (Exception var3) { | ||
instance.logger.severe("Failed to save properties for RetroBot!"); | ||
var3.printStackTrace(); | ||
} catch (Exception e) { | ||
instance.logger.severe("[DiscordBot]: Failed to save properties!"); | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
String getServerName() { | ||
return this.serverName; | ||
private String getAndSet_S(@Nonnull Properties prop, @Nonnull String get, @Nonnull Object Default) { | ||
String s = prop.getProperty(get, String.valueOf(Default)); | ||
prop.setProperty(get, String.valueOf(s)); | ||
return s; | ||
} | ||
|
||
String getChannel() { | ||
return this.channelID; | ||
private boolean getAndSet_B(@Nonnull Properties prop, @Nonnull String get, @Nonnull Object Default) { | ||
Boolean s = Boolean.parseBoolean(prop.getProperty(get, String.valueOf(Default))); | ||
prop.setProperty(get, String.valueOf(s)); | ||
return s; | ||
} | ||
|
||
String getJoinMessage() { | ||
return this.joinMessage; | ||
} | ||
String getQuitMessage() { | ||
return this.quitMessage; | ||
} | ||
String getDiscordChatMessage() { | ||
return this.discordChatMessage; | ||
} | ||
String getGameChatMessage() { | ||
return this.gameChatMessage; | ||
} | ||
String getServerName() { return this.serverName; } | ||
String getChannel() { return this.channelID; } | ||
String getJoinMessage() { return this.joinMessage; } | ||
String getQuitMessage() { return this.quitMessage; } | ||
String getDiscordStartMessage() { return discordStartMessage; } | ||
String getDiscordChatMessage() { return this.discordChatMessage; } | ||
String getGameChatMessage() { return this.gameChatMessage; } | ||
String getTimestampMessage() { return timestampMessage; } | ||
|
||
Boolean getPrensencePlayercount() { | ||
return this.PrensencePlayercount; | ||
boolean getPresencePlayercount() { return this.presencePlayercount; } | ||
boolean getOnlineCommand() { return this.onlineCommand; } | ||
|
||
} | ||
Boolean getOnlineCommand() { | ||
return this.OnlineCommand; | ||
} | ||
|
||
boolean canAnnounceStartStop() { | ||
return announceStartStop; | ||
} | ||
boolean canUseInGameTime() { return useInGameTime; } | ||
boolean canShowTimestamp() { return showTimestamp; } | ||
boolean canSeparateChat() { return seperateChat; } | ||
boolean canAnnounceStartStop() { return announceStartStop; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.