Skip to content

Commit

Permalink
2.29
Browse files Browse the repository at this point in the history
Added:

Global Moderator support (closes #58)
Message clearing/cleanup is now on MessageQueue

Fixed:

Subscriber sounds now don't trigger twice
Font issue (closes #68)
Null Pointer with checking Subscribers (closes #69)
  • Loading branch information
Gocnak committed Feb 7, 2015
1 parent f8ddc76 commit 6e3f8fe
Show file tree
Hide file tree
Showing 19 changed files with 141 additions and 155 deletions.
2 changes: 0 additions & 2 deletions src/main/java/Boot.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import gui.GUIMain;
import gui.GUIUpdate;
import util.Utils;
import util.settings.Settings;

import javax.swing.*;

import java.awt.*;

public class Boot {
Expand Down
88 changes: 40 additions & 48 deletions src/main/java/gui/ChatPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import gui.listeners.ListenerURL;
import irc.Donor;
import irc.message.Message;
import irc.message.MessageQueue;
import irc.message.MessageWrapper;
import lib.pircbot.org.jibble.pircbot.User;
import lib.scalr.Scalr;
Expand All @@ -16,7 +17,10 @@
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.*;
import javax.swing.text.DefaultCaret;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;
import javax.swing.text.html.HTML;
import java.awt.*;
import java.awt.event.WindowAdapter;
Expand Down Expand Up @@ -166,8 +170,11 @@ public void doScrollToBottom() {
}
}

private boolean messageOut = false;

@Override
public void insertUpdate(DocumentEvent e) {
maybeScrollToBottom();
if (GUIMain.currentSettings.cleanupChat) {
try {
if (e.getDocument().getText(e.getOffset(), e.getLength()).contains("\n")) {
Expand All @@ -176,42 +183,30 @@ public void insertUpdate(DocumentEvent e) {
} catch (Exception ignored) {
}
if (cleanupCounter > GUIMain.currentSettings.chatMax) {
/* cleanup every n messages */
if (cleanupChat()) {
resetCleanupCounter();
/* cleanup every n messages */
if (!messageOut) {
MessageQueue.addMessage(new Message().setType(Message.MessageType.CLEAR_TEXT).setExtra(this));
messageOut = true;
}
}
}
}

@Override
public void removeUpdate(DocumentEvent e) {
maybeScrollToBottom();
}

@Override
public void changedUpdate(DocumentEvent e) {
maybeScrollToBottom();
}

// ScrollingDocumentListener takes care of re-scrolling when appropriate
class ScrollingDocumentListener implements DocumentListener {
public void changedUpdate(DocumentEvent e) {
maybeScrollToBottom();
}

public void insertUpdate(DocumentEvent e) {
maybeScrollToBottom();
}

public void removeUpdate(DocumentEvent e) {
maybeScrollToBottom();
}

private void maybeScrollToBottom() {
JScrollBar scrollBar = scrollPane.getVerticalScrollBar();
boolean scrollBarAtBottom = isScrollBarFullyExtended(scrollBar);
if (scrollBarAtBottom) {
scrollToBottom();
}
private void maybeScrollToBottom() {
JScrollBar scrollBar = scrollPane.getVerticalScrollBar();
boolean scrollBarAtBottom = isScrollBarFullyExtended(scrollBar);
if (scrollBarAtBottom) {
scrollToBottom();
}
}

Expand Down Expand Up @@ -296,7 +291,6 @@ public ChatPane(String channel, JScrollPane scrollPane, JTextPane pane, int inde
this.index = index;
this.scrollPane = scrollPane;
textPane.getDocument().addDocumentListener(this);
textPane.getDocument().addDocumentListener(new ScrollingDocumentListener());
}

public ChatPane() {
Expand Down Expand Up @@ -338,10 +332,13 @@ public void onMessage(MessageWrapper m, boolean showChannel) {
insertIcon(m, 1, null);
}
if (u.isOp(channel)) {
if (!channel.substring(1).equals(sender) && !u.isStaff() && !u.isAdmin()) {//not the broadcaster again
if (!channel.substring(1).equals(sender) && !u.isStaff() && !u.isAdmin() && !u.isGlobalMod()) {//not the broadcaster again
insertIcon(m, 0, null);
}
}
if (u.isGlobalMod()) {
insertIcon(m, 11, null);
}
if (u.isDonor()) {
insertIcon(m, u.getDonationStatus(), null);
}
Expand Down Expand Up @@ -561,6 +558,10 @@ public void insertIcon(MessageWrapper m, int type, String channel) {
icon = sizeIcon(ChatPane.class.getResource("/image/diamond.png"));
kind = "Donator";
break;
case 11:
icon = sizeIcon(ChatPane.class.getResource("/image/globalmod.png"));
kind = "Global Mod";
break;
default:
icon = sizeIcon(GUIMain.currentSettings.modIcon);
kind = "Mod";
Expand All @@ -581,41 +582,32 @@ public String getText() {

// Source: http://stackoverflow.com/a/4628879
// by http://stackoverflow.com/users/131872/camickr & Community
public boolean cleanupChat() {
if (textPane == null || textPane.getParent() == null) return false;
public void cleanupChat() {
if (textPane == null || textPane.getParent() == null) return;
if (!(textPane.getParent() instanceof JViewport)) {
return false;
return;
}
JViewport viewport = ((JViewport) textPane.getParent());
Point startPoint = viewport.getViewPosition();
// we are not deleting right before the visible area, but one screen behind
// for convenience, otherwise flickering.
if (startPoint == null) return false;
if (startPoint == null) return;
final int start = textPane.viewToModel(startPoint);
if (start > 0) // not equal zero, because then we don't have to delete anything
{
final StyledDocument doc = textPane.getStyledDocument();
try {
if (GUIMain.currentSettings.cleanupChat) {
if (GUIMain.currentSettings.logChat && chan != null) {
String[] toRemove = doc.getText(0, start).split("\\n");
Utils.logChat(toRemove, chan, 1);
}
EventQueue.invokeLater(() -> {
try {
doc.remove(0, start);
} catch (Exception ignored) {
}
});
return true;
if (GUIMain.currentSettings.logChat && chan != null) {
String[] toRemove = doc.getText(0, start).split("\\n");
Utils.logChat(toRemove, chan, 1);
}
} catch (BadLocationException e) {
// we cannot do anything here
GUIMain.log("CLEANUP CHAT " + e.getMessage());
return false;
doc.remove(0, start);
resetCleanupCounter();
} catch (Exception e) {
GUIMain.log("Failed clearing chat: " + e.getMessage());
}
}
return false;
messageOut = false;
}

/**
Expand Down Expand Up @@ -665,4 +657,4 @@ public void log(MessageWrapper message, boolean isSystem) {
print(message, "\n" + getTime(), GUIMain.norm);
print(message, " " + (isSystem ? "SYS: " : "") + message.getLocal().getContent(), GUIMain.norm);
}
}
}
5 changes: 2 additions & 3 deletions src/main/java/gui/DraggableTabbedPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ enum TabTypeEnum {
TAB_NEITHER
}

class TabType {
private class TabType {

Rectangle rectangle;
TabTypeEnum type;
Expand All @@ -514,5 +514,4 @@ public TabTypeEnum getType() {
return type;
}
}

}
}
15 changes: 10 additions & 5 deletions src/main/java/gui/GUISettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -372,11 +372,16 @@ public void changeFontButtonActionPerformed() {
JFontChooser jfc = new JFontChooser(Constants.fontSizeArray);
jfc.setSelectedFont(GUIMain.currentSettings.font);
if (jfc.showDialog(this) == JFontChooser.OK_OPTION) {
if (jfc.getSelectedFont() != null) GUIMain.currentSettings.font = jfc.getSelectedFont();
StyleConstants.setFontFamily(GUIMain.norm, GUIMain.currentSettings.font.getFamily());
StyleConstants.setFontSize(GUIMain.norm, GUIMain.currentSettings.font.getSize());
currentFontLabel.setText(Utils.fontToString(GUIMain.currentSettings.font));
currentFontLabel.setFont(GUIMain.currentSettings.font);
Font f = jfc.getSelectedFont();
if (f != null) {
GUIMain.currentSettings.font = f;
StyleConstants.setFontFamily(GUIMain.norm, GUIMain.currentSettings.font.getFamily());
StyleConstants.setFontSize(GUIMain.norm, GUIMain.currentSettings.font.getSize());
StyleConstants.setBold(GUIMain.norm, GUIMain.currentSettings.font.isBold());
StyleConstants.setItalic(GUIMain.norm, GUIMain.currentSettings.font.isItalic());
currentFontLabel.setText(Utils.fontToString(GUIMain.currentSettings.font));
currentFontLabel.setFont(GUIMain.currentSettings.font);
}
}
}

Expand Down
7 changes: 2 additions & 5 deletions src/main/java/gui/listeners/ListenerName.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
*/
public class ListenerName extends MouseAdapter implements ActionListener {

public ListenerName() {
}

@Override
public void mouseReleased(MouseEvent e) {
JTextPane textPane = (JTextPane) e.getSource();
Expand All @@ -50,8 +47,8 @@ public void mouseReleased(MouseEvent e) {
User main = GUIMain.currentSettings.channelManager.getUser(GUIMain.currentSettings.accountManager.getUserAccount().getName(), false);//get yourself
if (main != null) {
int count = 0; //don't worry about it
//can't ban broadcaster or admin/staff
if (u != null && (u.isAdmin() || u.isStaff() || name.equalsIgnoreCase(channel.replace("#", ""))))
//can't ban broadcaster or admin/staff/global mod
if (u != null && (u.isAdmin() || u.isGlobalMod() || u.isStaff() || name.equalsIgnoreCase(channel.replace("#", ""))))
count++;

//can't ban other mods if you aren't the broadcaster
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/gui/listeners/PaneMenuListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void actionPerformed(ActionEvent e) {
if (pane instanceof CombinedChatPane) pane = ((CombinedChatPane) pane).getActiveChatPane();
pane.resetCleanupCounter();
final ChatPane pane1 = pane;
EventQueue.invokeLater(() -> {
EventQueue.invokeLater(() -> {//this should be fine, no need for message queue since clearing would be situational anyways
if (GUIMain.currentSettings.logChat) {
String[] toPrint = pane1.getText().split("\\n");
Utils.logChat(toPrint, pane1.getChannel(), 1);
Expand All @@ -103,4 +103,4 @@ public void actionPerformed(ActionEvent e) {
}
}
}
}
}
Binary file added src/main/java/image/globalmod.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 1 addition & 17 deletions src/main/java/irc/IRCBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import lib.pircbot.org.jibble.pircbot.User;
import sound.Sound;
import sound.SoundEngine;
import util.Constants;
import util.Response;
import util.StringArray;
import util.Utils;
Expand Down Expand Up @@ -109,22 +108,7 @@ public void onMessage(String channel, String sender, String message) {
String key = r.getKeyword();
if (message.contains(key)) {
int permBase = r.getPermission();
int permission = Constants.PERMISSION_ALL;
if (u.isSubscriber(channel)) {
permission = Constants.PERMISSION_SUB;
}
if (u.isDonor()) {
if (u.getDonated() >= 2.50) {
permission = Constants.PERMISSION_DONOR;
}
}
if ((u.isOp(channel) || u.isAdmin() || u.isStaff())) {
permission = Constants.PERMISSION_MOD;
}
if (GUIMain.currentSettings.accountManager.getUserAccount() != null &&
GUIMain.currentSettings.accountManager.getUserAccount().getName().equalsIgnoreCase(sender)) {
permission = Constants.PERMISSION_DEV;
}
int permission = Utils.getUserPermission(u, channel);
if (permission >= permBase) {
r.addUser(u.getNick());
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/irc/message/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public enum MessageType {
HOSTING_NOTIFY,
HOSTED_NOTIFY,
DONATION_NOTIFY,
JTV_NOTIFY
JTV_NOTIFY,
CLEAR_TEXT
}

}
7 changes: 3 additions & 4 deletions src/main/java/irc/message/MessageQueue.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package irc.message;

import gui.ChatPane;
import gui.CombinedChatPane;
import gui.GUIMain;
import lib.pircbot.org.jibble.pircbot.Queue;
Expand Down Expand Up @@ -63,10 +64,6 @@ public static void addMessage(Message mess) {
} else if (mess.getType() == Message.MessageType.SUB_NOTIFY) {
String channel = mess.getChannel().substring(1);
GUIMain.chatPanes.get(channel).onSub(wrap);
if (channel.equalsIgnoreCase(GUIMain.currentSettings.accountManager.getUserAccount().getName())) {
if (GUIMain.currentSettings.subSound != null)
SoundEngine.getEngine().playSpecialSound(true);
}
} else if (mess.getType() == Message.MessageType.BAN_NOTIFY ||
mess.getType() == Message.MessageType.HOSTED_NOTIFY ||
mess.getType() == Message.MessageType.HOSTING_NOTIFY ||
Expand All @@ -77,6 +74,8 @@ public static void addMessage(Message mess) {
if (GUIMain.currentSettings.donationSound != null) {
SoundEngine.getEngine().playSpecialSound(false);
}
} else if (mess.getType() == Message.MessageType.CLEAR_TEXT) {
wrap.addPrint(((ChatPane) mess.getExtra())::cleanupChat);
}
addToQueue(wrap);
} catch (Exception e) {
Expand Down
30 changes: 16 additions & 14 deletions src/main/java/irc/message/MessageWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,22 @@ public void addPrint(Runnable r) {
}

public void print() {
Runnable handler = () -> {
try {
prints.forEach(java.lang.Runnable::run);
} catch (Exception e) {
GUIMain.log(e.getMessage());
}
};
if (EventQueue.isDispatchThread()) {
handler.run();
} else {
try {
EventQueue.invokeLater(handler);
} catch (Exception e) {
GUIMain.log(e.getMessage());
if (!prints.isEmpty()) {
Runnable handler = () -> {
try {
prints.forEach(java.lang.Runnable::run);
} catch (Exception e) {
GUIMain.log(e.getMessage());
}
};
if (EventQueue.isDispatchThread()) {
handler.run();
} else {
try {
EventQueue.invokeLater(handler);
} catch (Exception e) {
GUIMain.log(e.getMessage());
}
}
}
}
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/lib/pircbot/org/jibble/pircbot/PircBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -1000,15 +1000,14 @@ public void handleSpecial(String channel, String line) {
String user = split[1].toLowerCase();
if (split[2].equalsIgnoreCase("admin")) {
getChannelManager().getUser(user, true).setAdmin(true);
}
if (split[2].equalsIgnoreCase("staff")) {
} else if (split[2].equalsIgnoreCase("staff")) {
getChannelManager().getUser(user, true).setStaff(true);
}
if (split[2].equalsIgnoreCase("turbo")) {
} else if (split[2].equalsIgnoreCase("turbo")) {
getChannelManager().getUser(user, true).setTurbo(true);
}
if (split[2].equalsIgnoreCase("subscriber")) {
} else if (split[2].equalsIgnoreCase("subscriber")) {
getChannelManager().getChannel(channel).addSubscriber(user);
} else if (split[2].equalsIgnoreCase("global_mod")) {
getChannelManager().getUser(user, true).setGlobalMod(true);
}
}
}
Expand Down
Loading

0 comments on commit 6e3f8fe

Please sign in to comment.