Skip to content

Commit

Permalink
started V7 channel updates
Browse files Browse the repository at this point in the history
added the `IChannelCategory` interface
added the `ChannelCategory` class
added the `ChannelTypes` enum
Fixed some of the type hell in the channel implementations
  • Loading branch information
R3alCl0ud committed Sep 13, 2017
1 parent 4db4f18 commit 5844541
Show file tree
Hide file tree
Showing 19 changed files with 321 additions and 154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import io.discloader.discloader.common.Shard;
import io.discloader.discloader.core.entity.emoji.Emoji;
import io.discloader.discloader.core.entity.emoji.EmojiCategory;
import io.discloader.discloader.entity.channel.ChannelTypes;
import io.discloader.discloader.entity.channel.IChannel;
import io.discloader.discloader.entity.channel.IGroupChannel;
import io.discloader.discloader.entity.channel.IGuildChannel;
Expand Down Expand Up @@ -86,8 +87,6 @@ public static Collection<IChannel> getChannels() {
return channels.values();
}



public static Collection<IGroupChannel> getGroupChannels() {
return groupChannels.values();
}
Expand Down Expand Up @@ -231,13 +230,13 @@ public static void putVoiceConnection(VoiceConnection connection) {
public static void removeChannel(IChannel channel) {
if (channel == null) return;
channels.remove(channel.getID());
if (channel.getType() == ChannelType.TEXT) {
if (channel.getType() == ChannelTypes.TEXT) {
textChannels.remove(channel.getID());
} else if (channel.getType() == ChannelType.VOICE) {
} else if (channel.getType() == ChannelTypes.VOICE) {
voiceChannels.remove(channel.getID());
} else if (channel.getType() == ChannelType.DM) {
} else if (channel.getType() == ChannelTypes.GROUP) {
groupChannels.remove(channel.getID());
} else if (channel.getType() == ChannelType.DM) {
} else if (channel.getType() == ChannelTypes.DM) {
privateChannels.remove(channel.getID());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,45 +22,48 @@
import io.discloader.discloader.util.DLUtil;

public class ModRegistry {

/**
* The mod currently being loaded in any given phase of the {@link DiscLoader loader's} startup
* The mod currently being loaded in any given phase of the
* {@link DiscLoader loader's} startup
*
* @author Perry Berman
* @since 0.0.1
*/
public static ModContainer activeMod = null;

public static DiscLoader loader;

/**
* A {@link HashMap} of the mods loaded by the client. Indexed by {@link Mod#modid()}
* A {@link HashMap} of the mods loaded by the client. Indexed by
* {@link Mod#modid()}
*
* @author Zachary Waldron
* @since 0.0.1
*/
public static final HashMap<String, ModContainer> mods = new HashMap<String, ModContainer>();

/**
* Uninitialized mods
*
* @author Perry Berman
*/
private static final HashMap<String, ModContainer> preInitMods = new HashMap<String, ModContainer>();

/**
* Contains a sensible method of figuring out what mods loaded what mod
*
* @author Perry Berman
*/
private static final Map<String, String> loadMod = new HashMap<String, String>();

private static final Logger logger = new DLLogger(ModRegistry.class).getLogger();

public static final CompletableFuture<Void> loaded = new CompletableFuture<>();

public static CompletableFuture<Void> checkCandidates(List<ModCandidate> mcs) {
Thread modLoader = new Thread("ModLoader") {

public void run() {
ProgressLogger.step(1, 2, "Checking candidates for @Mod annotation");
logger.info("Checking candidates for @Mod annotation");
Expand Down Expand Up @@ -104,7 +107,7 @@ public void run() {
mc.discoverHandlers();
n++;
}

activeMod = null;
ProgressLogger.phase(2, 3, "PreINIT");
logger.info("PreINIT");
Expand All @@ -121,7 +124,7 @@ public void run() {
modLoader.start();
return loaded;
}

public static void preInit() {
int i = 1;
for (ModContainer mod : preInitMods.values()) {
Expand All @@ -134,9 +137,8 @@ public static void preInit() {
// activeMod = null;
}
DLPreInitEvent event = new DLPreInitEvent(loader);
for (IEventListener e : loader.handlers) {
e.PreInit(event);
}
logger.info("" + (loader != null));
// loader.emit(event);
ProgressLogger.phase(3, 3, "Init");
logger.info("Now swiching to the Init phase");
ProgressLogger.stage(1, 3, "Waiting to Login");
Expand All @@ -145,7 +147,7 @@ public static void preInit() {
resetStep();
loaded.complete((Void) null);
}

public static CompletableFuture<Void> startMods() {
ProgressLogger.stage(1, 3, "Mod Discovery");
logger.info("Beginning Mod Discovery");
Expand All @@ -155,7 +157,7 @@ public static CompletableFuture<Void> startMods() {
logger.info("Discovering Mod Containers");
return checkCandidates(candidates);
}

public static void loadMod(String modid) {
ModContainer mod = preInitMods.get(modid);
ProgressLogger.progress(1, 3, "Checking if another mod is currently active");
Expand All @@ -166,7 +168,7 @@ public static void loadMod(String modid) {
ProgressLogger.progress(2, 3, "Setting active mod");
logger.info("Setting active mod");
activeMod = mod;

ProgressLogger.progress(3, 3, "Executing PreInit handler in: " + mod.modInfo.modid());
logger.info("Executing PreInit handler in: " + mod.modInfo.modid());
mods.put(mod.modInfo.modid(), mod);
Expand All @@ -179,7 +181,7 @@ public static void loadMod(String modid) {
}
mod.loaded = true;
}

private static void resetStep() {
if (!Main.usegui) return;
LoadingPanel.setProgress(0, 0, "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import io.discloader.discloader.common.DiscLoader;
import io.discloader.discloader.core.entity.channel.Channel;
import io.discloader.discloader.core.entity.channel.ChannelCategory;
import io.discloader.discloader.core.entity.channel.PrivateChannel;
import io.discloader.discloader.core.entity.channel.TextChannel;
import io.discloader.discloader.core.entity.channel.VoiceChannel;
import io.discloader.discloader.core.entity.message.Message;
import io.discloader.discloader.entity.channel.ChannelTypes;
import io.discloader.discloader.entity.channel.IChannel;
import io.discloader.discloader.entity.channel.IChannelCategory;
import io.discloader.discloader.entity.channel.ITextChannel;
import io.discloader.discloader.entity.guild.IGuild;
import io.discloader.discloader.entity.message.IMessage;
Expand All @@ -17,6 +20,10 @@
public class ChannelFactory {

public IChannel buildChannel(ChannelJSON data, IGuild guild) {
return buildChannel(data, guild, true);
}

public IChannel buildChannel(ChannelJSON data, IGuild guild, boolean insert) {
IChannel channel = null;
if (data.type == DLUtil.ChannelTypes.DM) {
channel = new PrivateChannel(DiscLoader.getDiscLoader(), data);
Expand All @@ -26,10 +33,13 @@ public IChannel buildChannel(ChannelJSON data, IGuild guild) {
if (guild != null) {
if (data.type == DLUtil.ChannelTypes.text) {
channel = new TextChannel(guild, data);
guild.getTextChannels().put(channel.getID(), (TextChannel) channel);
if (insert) guild.getTextChannels().put(channel.getID(), (TextChannel) channel);
} else if (data.type == DLUtil.ChannelTypes.voice) {
channel = new VoiceChannel(guild, data);
guild.getVoiceChannels().put(channel.getID(), (VoiceChannel) channel);
if (insert) guild.getVoiceChannels().put(channel.getID(), (VoiceChannel) channel);
} else if (ChannelTypes.fromCode(data.type) == ChannelTypes.CATEGORY) {
channel = new ChannelCategory(guild, data);
if (insert) guild.getChannelCategories().put(channel.getID(), (IChannelCategory) channel);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import java.time.OffsetDateTime;

import io.discloader.discloader.common.DiscLoader;
import io.discloader.discloader.entity.channel.ChannelTypes;
import io.discloader.discloader.entity.channel.IChannel;
import io.discloader.discloader.entity.util.SnowflakeUtil;
import io.discloader.discloader.network.json.ChannelJSON;
import io.discloader.discloader.util.DLUtil.ChannelType;

public class Channel implements IChannel {

Expand All @@ -15,7 +15,7 @@ public class Channel implements IChannel {
*/
private long id;

protected ChannelType type;
protected short type;

/**
* The current instance of DiscLoader
Expand All @@ -27,7 +27,7 @@ public Channel(DiscLoader loader, ChannelJSON data) {

id = SnowflakeUtil.parse(data.id);

type = ChannelType.CHANNEL;
type = data.type;

if (data != null) setup(data);
}
Expand All @@ -43,13 +43,13 @@ public DiscLoader getLoader() {
}

@Override
public ChannelType getType() {
return type;
public ChannelTypes getType() {
return ChannelTypes.fromCode(type);
}

@Override
public boolean isPrivate() {
return type != ChannelType.TEXT && type != ChannelType.VOICE && type != ChannelType.CHANNEL;
return getType() == ChannelTypes.DM || getType() == ChannelTypes.GROUP;
}

public void setup(ChannelJSON data) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.discloader.discloader.core.entity.channel;

import java.util.concurrent.CompletableFuture;

import io.discloader.discloader.entity.channel.IChannelCategory;
import io.discloader.discloader.entity.channel.IGuildChannel;
import io.discloader.discloader.entity.guild.IGuild;
import io.discloader.discloader.network.json.ChannelJSON;

public class ChannelCategory extends GuildChannel implements IChannelCategory {

public ChannelCategory(IGuild guild, ChannelJSON channel) {
super(guild, channel);
}

@Override
public <T extends IGuildChannel> CompletableFuture<T> addChannel(T guildChannel) {
return null;
}

public void setup(ChannelJSON data) {
super.setup(data);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import io.discloader.discloader.network.rest.actions.channel.pin.PinMessage;
import io.discloader.discloader.network.rest.actions.channel.pin.PinnedMessages;
import io.discloader.discloader.network.rest.actions.channel.pin.UnpinMessage;
import io.discloader.discloader.util.DLUtil.ChannelType;

/**
* Represents a GroupDMChannel on discord. GroupChannels are only available for
Expand All @@ -55,7 +54,7 @@ public class GroupChannel extends Channel implements IGroupChannel, IVoiceChanne
public GroupChannel(DiscLoader loader, ChannelJSON data) {
super(loader, data);

type = ChannelType.GROUPDM;
// type = ChannelType.GROUPDM;

messages = new HashMap<>();
typing = new HashMap<>();
Expand Down Expand Up @@ -225,15 +224,18 @@ public CompletableFuture<Map<Long, IUser>> startTyping() {
public CompletableFuture<IMessage> unpinMessage(IMessage message) {
return new UnpinMessage<IGroupChannel>(message).execute();
}

/*
* (non-Javadoc)
* @see io.discloader.discloader.entity.channel.ITextChannel#sendMessage(java.lang.String,
* io.discloader.discloader.core.entity.RichEmbed, io.discloader.discloader.entity.sendable.Attachment)
* @see
* io.discloader.discloader.entity.channel.ITextChannel#sendMessage(java.
* lang.String,
* io.discloader.discloader.core.entity.RichEmbed,
* io.discloader.discloader.entity.sendable.Attachment)
*/
@Override
public CompletableFuture<IMessage> sendMessage(String content, RichEmbed embed, Attachment attachment) {
return null;
}

}
Loading

0 comments on commit 5844541

Please sign in to comment.