Made all channels configurable

Removed Vault repo, was unused and errors now
Removed all channel fields from main class
This commit is contained in:
Norbi Peti 2019-02-13 15:21:57 +01:00
parent 9ba57fd989
commit 13b168d238
7 changed files with 415 additions and 409 deletions

View file

@ -124,10 +124,10 @@
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<repository>
<!-- <repository>
<id>vault-repo</id>
<url>http://nexus.hc.to/content/repositories/pub_releases</url>
</repository>
</repository> -->
<repository>
<id>Essentials</id>
<url>http://repo.ess3.net/content/repositories/essrel/</url>

View file

@ -5,6 +5,7 @@ import buttondevteam.discordplugin.commands.Command2DC;
import buttondevteam.discordplugin.commands.DiscordCommandBase;
import buttondevteam.discordplugin.commands.VersionCommand;
import buttondevteam.discordplugin.exceptions.ExceptionListenerModule;
import buttondevteam.discordplugin.fun.FunModule;
import buttondevteam.discordplugin.listeners.CommonListeners;
import buttondevteam.discordplugin.listeners.MCListener;
import buttondevteam.discordplugin.mcchat.MCChatPrivate;
@ -89,18 +90,6 @@ public class DiscordPlugin extends ButtonPlugin implements IListener<ReadyEvent>
}
}
public static IChannel botchannel; //Can be removed
public static IChannel annchannel;
public static IChannel genchannel;
public static IChannel chatchannel;
public static IChannel botroomchannel;
public static IChannel modlogchannel;
/**
* Don't send messages, just receive, the same channel is used when testing
*/
public static IChannel officechannel;
public static IChannel updatechannel;
public static IChannel devofficechannel;
public static IGuild mainServer;
public static IGuild devServer;
@ -119,31 +108,10 @@ public class DiscordPlugin extends ButtonPlugin implements IListener<ReadyEvent>
if (mainServer == null || devServer == null)
return; // Retry
if (!TBMCCoreAPI.IsTestServer()) { //Don't change conditions here, see mainServer=devServer=null in onDisable()
botchannel = mainServer.getChannelByID(209720707188260864L); // bot
annchannel = mainServer.getChannelByID(126795071927353344L); // announcements
genchannel = mainServer.getChannelByID(125813020357165056L); // general
chatchannel = mainServer.getChannelByID(249663564057411596L); // minecraft_chat
botroomchannel = devServer.getChannelByID(239519012529111040L); // bot-room
officechannel = devServer.getChannelByID(219626707458457603L); // developers-office
updatechannel = devServer.getChannelByID(233724163519414272L); // server-updates
devofficechannel = officechannel; // developers-office
modlogchannel = mainServer.getChannelByID(283840717275791360L); // modlog
dc.changePresence(StatusType.ONLINE, ActivityType.PLAYING, "Chromacraft");
} else {
botchannel = devServer.getChannelByID(239519012529111040L); // bot-room
annchannel = botchannel; // bot-room
genchannel = botchannel; // bot-room
botroomchannel = botchannel;// bot-room
chatchannel = botchannel;// bot-room
officechannel = devServer.getChannelByID(219626707458457603L); // developers-office
updatechannel = botchannel;
devofficechannel = botchannel;// bot-room
modlogchannel = botchannel; // bot-room
dc.changePresence(StatusType.ONLINE, ActivityType.PLAYING, "testing");
}
if (botchannel == null || annchannel == null || genchannel == null || botroomchannel == null
|| chatchannel == null || officechannel == null || updatechannel == null)
return; // Retry
SafeMode = false;
if (task != null)
task.cancel();
@ -153,6 +121,7 @@ public class DiscordPlugin extends ButtonPlugin implements IListener<ReadyEvent>
Component.registerComponent(this, new ExceptionListenerModule());
Component.registerComponent(this, new GameRoleModule()); //Needs the mainServer to be set
Component.registerComponent(this, new AnnouncerModule());
Component.registerComponent(this, new FunModule());
new ChromaBot(this).updatePlayerList(); //Initialize ChromaBot - The MCCHatModule is tested to be enabled
DiscordCommandBase.registerCommands();

View file

@ -1,5 +1,6 @@
package buttondevteam.discordplugin.exceptions;
import buttondevteam.core.ComponentManager;
import buttondevteam.discordplugin.DiscordPlugin;
import buttondevteam.lib.TBMCDebugMessageEvent;
import org.bukkit.event.EventHandler;
@ -13,7 +14,7 @@ public class DebugMessageListener implements Listener{
}
private static void SendMessage(String message) {
if (DiscordPlugin.SafeMode)
if (DiscordPlugin.SafeMode || !ComponentManager.isEnabled(ExceptionListenerModule.class))
return;
try {
StringBuilder sb = new StringBuilder();
@ -22,7 +23,7 @@ public class DebugMessageListener implements Listener{
message = message.substring(0, 2000);
sb.append(message).append("\n");
sb.append("```");
DiscordPlugin.sendMessageToChannel(DiscordPlugin.botroomchannel, sb.toString());
DiscordPlugin.sendMessageToChannel(ExceptionListenerModule.getChannel(), sb.toString());
} catch (Exception ex) {
ex.printStackTrace();
}

View file

@ -1,14 +1,17 @@
package buttondevteam.discordplugin.exceptions;
import buttondevteam.core.ComponentManager;
import buttondevteam.discordplugin.DPUtils;
import buttondevteam.discordplugin.DiscordPlugin;
import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.lib.TBMCExceptionEvent;
import buttondevteam.lib.architecture.Component;
import buttondevteam.lib.architecture.ConfigData;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import sx.blah.discord.handle.obj.IChannel;
import sx.blah.discord.handle.obj.IRole;
import java.util.ArrayList;
@ -43,6 +46,7 @@ public class ExceptionListenerModule extends Component implements Listener {
private static IRole coderRole;
private static void SendException(Throwable e, String sourcemessage) {
if (instance == null) return;
try {
if (coderRole == null)
coderRole = DiscordPlugin.devServer.getRolesByName("Coder").get(0);
@ -57,20 +61,32 @@ public class ExceptionListenerModule extends Component implements Listener {
stackTrace = stackTrace.substring(0, 1800);
sb.append(stackTrace).append("\n");
sb.append("```");
DiscordPlugin.sendMessageToChannel(DiscordPlugin.botroomchannel, sb.toString());
DiscordPlugin.sendMessageToChannel(getChannel(), sb.toString()); //Instance isn't null here
} catch (Exception ex) {
ex.printStackTrace();
}
}
private static ExceptionListenerModule instance;
public static IChannel getChannel() {
if (instance != null) return instance.channel().get();
return null;
}
private ConfigData<IChannel> channel() {
return DPUtils.channelData(getConfig(), "channel", 239519012529111040L);
}
@Override
protected void enable() {
instance = this;
Bukkit.getPluginManager().registerEvents(new ExceptionListenerModule(), getPlugin());
TBMCCoreAPI.RegisterEventsForExceptions(new DebugMessageListener(), getPlugin());
}
@Override
protected void disable() {
instance = null;
}
}

View file

@ -1,6 +1,7 @@
package buttondevteam.discordplugin.fun;
import buttondevteam.core.ComponentManager;
import buttondevteam.discordplugin.DPUtils;
import buttondevteam.discordplugin.DiscordPlugin;
import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.lib.architecture.Component;
@ -12,6 +13,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import sx.blah.discord.handle.impl.events.user.PresenceUpdateEvent;
import sx.blah.discord.handle.obj.IChannel;
import sx.blah.discord.handle.obj.IMessage;
import sx.blah.discord.handle.obj.IRole;
import sx.blah.discord.handle.obj.StatusType;
@ -123,6 +125,11 @@ public class FunModule extends Component implements Listener {
}, IRole::getName);
}
private ConfigData<IChannel> fullHouseChannel() {
return DPUtils.channelData(getConfig(), "fullHouseChannel", 219626707458457603L);
}
private static long lasttime = 0;
public static void handleFullHouse(PresenceUpdateEvent event) {
@ -138,7 +145,7 @@ public class FunModule extends Component implements Listener {
.noneMatch(u -> u.getPresence().getStatus().equals(StatusType.OFFLINE))
&& lasttime + 10 < TimeUnit.NANOSECONDS.toHours(System.nanoTime())
&& Calendar.getInstance().get(Calendar.DAY_OF_MONTH) % 5 == 0) {
DiscordPlugin.sendMessageToChannel(DiscordPlugin.devofficechannel, "Full house!",
DiscordPlugin.sendMessageToChannel(mod.fullHouseChannel().get(), "Full house!",
new EmbedBuilder()
.withImage(
"https://cdn.discordapp.com/attachments/249295547263877121/249687682618359808/poker-hand-full-house-aces-kings-playing-cards-15553791.png")

View file

@ -3,8 +3,10 @@ package buttondevteam.discordplugin.mcchat;
import buttondevteam.discordplugin.*;
import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.lib.TBMCSystemChatEvent;
import buttondevteam.lib.architecture.ConfigData;
import buttondevteam.lib.player.*;
import com.earth2me.essentials.CommandSource;
import lombok.RequiredArgsConstructor;
import lombok.val;
import net.ess3.api.events.AfkStatusChangeEvent;
import net.ess3.api.events.MuteStatusChangeEvent;
@ -26,7 +28,10 @@ import sx.blah.discord.handle.obj.IUser;
import sx.blah.discord.util.DiscordException;
import sx.blah.discord.util.MissingPermissionsException;
@RequiredArgsConstructor
class MCListener implements Listener {
private final MinecraftChatModule module;
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerLogin(PlayerLoginEvent e) {
if (e.getResult() != Result.ALLOWED)
@ -48,7 +53,7 @@ class MCListener implements Listener {
MCChatUtils.addSender(MCChatUtils.OnlineSenders, dp.getDiscordID(),
new DiscordPlayerSender(user, user.getOrCreatePMChannel(), p));
MCChatUtils.addSender(MCChatUtils.OnlineSenders, dp.getDiscordID(),
new DiscordPlayerSender(user, DiscordPlugin.chatchannel, p)); //Stored per-channel
new DiscordPlayerSender(user, module.chatChannel().get(), p)); //Stored per-channel
}
final String message = e.GetPlayer().PlayerName().get() + " joined the game";
MCChatUtils.forAllowedCustomAndAllMCChat(MCChatUtils.send(message), e.getPlayer(), ChannelconBroadcast.JOINLEAVE, true);
@ -94,11 +99,15 @@ class MCListener implements Listener {
MCChatUtils.forAllowedCustomAndAllMCChat(MCChatUtils.send(msg), base, ChannelconBroadcast.AFK, false);
}
private ConfigData<IRole> muteRole() {
return DPUtils.roleData(module.getConfig(), "muteRole", "Muted");
}
@EventHandler
public void onPlayerMute(MuteStatusChangeEvent e) {
try {
DPUtils.performNoWait(() -> {
final IRole role = DiscordPlugin.dc.getRoleByID(164090010461667328L); //TODO: Config
final IRole role = muteRole().get();
final CommandSource source = e.getAffected().getSource();
if (!source.isPlayer())
return;
@ -111,7 +120,7 @@ class MCListener implements Listener {
user.addRole(role);
else
user.removeRole(role);
DiscordPlugin.sendMessageToChannel(DiscordPlugin.modlogchannel, (e.getValue() ? "M" : "Unm") + "uted user: " + user.getName());
DiscordPlugin.sendMessageToChannel(module.modlogChannel().get(), (e.getValue() ? "M" : "Unm") + "uted user: " + user.getName());
});
} catch (DiscordException | MissingPermissionsException ex) {
TBMCCoreAPI.SendException("Failed to give/take Muted role to player " + e.getAffected().getName() + "!",

View file

@ -32,12 +32,16 @@ public class MinecraftChatModule extends Component {
return DPUtils.channelData(getConfig(), "chatChannel", 239519012529111040L);
}
public ConfigData<IChannel> modlogChannel() {
return DPUtils.channelData(getConfig(), "modlogChannel", 283840717275791360L);
}
@Override
protected void enable() {
listener = new MCChatListener(this);
DiscordPlugin.dc.getDispatcher().registerListener(listener);
TBMCCoreAPI.RegisterEventsForExceptions(listener, getPlugin());
TBMCCoreAPI.RegisterEventsForExceptions(new MCListener(), getPlugin());//These get undone if restarting/resetting - it will ignore events if disabled
TBMCCoreAPI.RegisterEventsForExceptions(new MCListener(this), getPlugin());//These get undone if restarting/resetting - it will ignore events if disabled
val chcons = getConfig().getConfig().getConfigurationSection("chcons");
if (chcons == null) //Fallback to old place