Skip to content

Commit

Permalink
source clean
Browse files Browse the repository at this point in the history
  • Loading branch information
nicol authored and nicol committed Sep 24, 2023
1 parent ef14827 commit 2b3487d
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import java.util.UUID;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.logging.log4j.Logger;
import org.magic.game.model.Player;
import org.magic.services.logging.MTGLogger;
import org.magic.services.tools.CryptoUtils;

public abstract class AbstractMessage extends AbstractAuditableItem {
Expand All @@ -19,7 +21,8 @@ public enum MSG_TYPE { CONNECT, CHANGESTATUS, DISCONNECT, TALK, SYSTEM, SEARCH,
private MSG_TYPE typeMessage;
private String message;
private Color color;

protected transient Logger logger = MTGLogger.getLogger(this.getClass());


protected AbstractMessage() {
setId(CryptoUtils.generateMD5(UUID.randomUUID().toString()+new Date()+typeMessage));
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/magic/api/beans/enums/EnumExtra.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public enum EnumExtra {
VIP ("vip"),
WELCOME("default"),
JUMP ("jumpstart"),
INTRO("default"),
INTRO("intro"),
PLANESWALKER("default"),
STARTER("starter"),
BRAWL("default");
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/magic/api/beans/enums/EnumItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public enum EnumItems
CHALLENGERDECK ("Challenger deck"),
FATPACK ("Fat Pack"),
DECK ("Deck"),
COMMANDER_DECK ("Commander Deck"),
CASE ("Case of Sealed product"),
DRAFT_PACK ("3 boosters pack"),
WELCOME ("Welcome pack");
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/org/magic/api/beans/messages/TalkMessage.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package org.magic.api.beans.messages;

import java.awt.Color;
import java.util.regex.Pattern;

import org.magic.api.beans.abstracts.AbstractMessage;

public class TalkMessage extends AbstractMessage{

private static final long serialVersionUID = 1L;

private static final String REGEX = "\\{(.*?)\\}";



public String toChatString() {
return getAuthor().getName() + " : " + getMessage();
Expand All @@ -19,6 +19,16 @@ public TalkMessage(String message, Color color) {
setTypeMessage(MSG_TYPE.TALK);
setMessage(message);
setColor(color);

var m = Pattern.compile(REGEX).matcher(message);
if(m.find())
{
logger.info("founnd card");
}

}




}
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,13 @@ public void disableConsummer() {

@Override
protected String read() throws IOException {
ClientMessage msg;
ClientMessage msg=null;
try {
msg = consumer.receive();
logger.debug("consume {}",msg);

if(!consumer.isClosed()) {
msg = consumer.receive();
logger.debug("consume {}",msg);
}
} catch (ActiveMQException e) {
throw new IOException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,8 @@ private MagicEdition generateEdition(String id) {
sp.setTypeProduct(parseType(el.getAsJsonObject().get("category").getAsString()));
sp.setNum(itemId++);
sp.setLang("en");

if(el.getAsJsonObject().get("subtype")!=null) {
var extra=el.getAsJsonObject().get("subtype").getAsString();

if(extra.equals("starter"))
Expand All @@ -713,8 +715,7 @@ private MagicEdition generateEdition(String id) {
sp.setExtra(parseExtra(extra));
}



}
if(sp.getName().contains(" Gift "))
sp.setExtra(EnumExtra.GIFT);

Expand Down Expand Up @@ -763,7 +764,7 @@ private EnumItems parseType(String category) {
case "bundle" : return EnumItems.BUNDLE;
case "prerelease_pack" : return EnumItems.PRERELEASEPACK;
case "deck" : return EnumItems.DECK;
case "commander_deck" : return EnumItems.DECK;
case "commander_deck" : return EnumItems.COMMANDER_DECK;
case "draft_set": return EnumItems.DRAFT_PACK;
default : return null;
}
Expand Down
14 changes: 8 additions & 6 deletions src/main/java/org/magic/gui/components/NetworkChatPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -88,7 +89,7 @@ public NetworkChatPanel() {
editorPane = new JTextArea();
var panel1 = new JPanel();
btnColorChoose = new JButton(MTGConstants.ICON_GAME_COLOR);
cboStates = UITools.createCombobox(EnumPlayerStatus.values());
cboStates = UITools.createCombobox(Arrays.asList(EnumPlayerStatus.values()).stream().filter(s->s!=EnumPlayerStatus.CONNECTED).filter(s->s!=EnumPlayerStatus.DISCONNECTED).toList());
var panelChatBox = new JPanel();
txtServer.setText(MTGControler.getInstance().get("network-config/network-last-server", ActiveMQServer.DEFAULT_SERVER));
txtServer.setColumns(10);
Expand All @@ -102,8 +103,7 @@ public NetworkChatPanel() {
listPlayers.setCellRenderer(new PlayerRenderer());
listMsg.setCellRenderer(new MessageRenderer());

btnSearch = new JButton("Search");

btnSearch = UITools.createBindableJButton("", MTGConstants.ICON_SEARCH_24,KeyEvent.VK_S,"searchquery");
try {
editorPane.setForeground(new Color(Integer.parseInt(MTGControler.getInstance().get("/game/player-profil/foreground"))));
} catch (Exception e) {
Expand All @@ -127,8 +127,8 @@ public NetworkChatPanel() {
panelChatBox.add(editorPane, BorderLayout.CENTER);
panelChatBox.add(panel1, BorderLayout.NORTH);

panel1.add(btnColorChoose);
panel1.add(cboStates);
panel1.add(btnColorChoose);
panel1.add(btnSearch);


Expand Down Expand Up @@ -294,6 +294,7 @@ protected void done() {
}
catch(Exception e)
{
e.printStackTrace();
logger.error(e);
}

Expand All @@ -320,7 +321,7 @@ protected void process(List<AbstractMessage> chunks) {

for(var s : chunks)
{

switch(s.getTypeMessage())
{
case CHANGESTATUS:
Expand Down Expand Up @@ -367,9 +368,10 @@ protected void process(List<AbstractMessage> chunks) {

default:break;
}

}

listPlayers.updateUI();


listMsg.ensureIndexIsVisible( listMsg.getModel().getSize() - 1 );

Expand Down
17 changes: 16 additions & 1 deletion src/main/java/org/magic/gui/renderer/MessageRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,23 @@ public class MessageRenderer implements ListCellRenderer<AbstractMessage> {
@Override
public Component getListCellRendererComponent(JList<? extends AbstractMessage> list, AbstractMessage value, int index,boolean isSelected, boolean cellHasFocus) {
var panel = new JPanel();
var pane = new JsonMessagePanel(value);
panel.setLayout(new BorderLayout());
panel.add(new JPanel(),BorderLayout.NORTH);
panel.add(new JsonMessagePanel(value),BorderLayout.CENTER);
panel.add(pane,BorderLayout.CENTER);
pane.setOpaque(true);

if(isSelected)
{
pane.setBackground(list.getSelectionBackground());
pane.setForeground(list.getSelectionForeground());
}
else
{
pane.setBackground(list.getBackground());
pane.setForeground(list.getForeground());
}


return panel;
}}

0 comments on commit 2b3487d

Please sign in to comment.