Skip to content

Commit

Permalink
reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
Exslims committed Aug 23, 2017
1 parent 9eac03b commit acbdff1
Show file tree
Hide file tree
Showing 247 changed files with 3,309 additions and 2,800 deletions.
13 changes: 7 additions & 6 deletions app-core/src/main/java/com/mercury/platform/core/ChatHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.mercury.platform.shared.AsSubscriber;
import com.mercury.platform.shared.config.Configuration;
import com.mercury.platform.shared.config.descriptor.ApplicationDescriptor;
import com.mercury.platform.shared.config.descriptor.TaskBarDescriptor;
import com.mercury.platform.shared.store.MercuryStoreCore;
import com.sun.jna.Native;
Expand All @@ -12,7 +11,6 @@
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.event.KeyEvent;
import java.util.*;

public class ChatHelper implements AsSubscriber {
private Robot robot;
Expand Down Expand Up @@ -53,6 +51,7 @@ private void executeMessage(String message) {
robot.keyRelease(KeyEvent.VK_ENTER);
MercuryStoreCore.blockHotkeySubject.onNext(false);
}

private void openChat(String whisper) {
this.gameToFront();
StringSelection selection = new StringSelection("@" + whisper);
Expand All @@ -79,7 +78,8 @@ private void openChat(String whisper) {
robot.keyRelease(KeyEvent.VK_SPACE);
MercuryStoreCore.blockHotkeySubject.onNext(false);
}
private void gameToFront(){

private void gameToFront() {
User32.INSTANCE.EnumWindows((hWnd, arg1) -> {
char[] className = new char[512];
User32.INSTANCE.GetClassName(hWnd, className, 512);
Expand All @@ -95,16 +95,17 @@ private void gameToFront(){
return true;
}, null);
}

@Override
public void subscribe() {
MercuryStoreCore.chatCommandSubject.subscribe(this::executeMessage);
MercuryStoreCore.openChatSubject.subscribe(this::openChat);
MercuryStoreCore.dndSubject.subscribe(state -> {
TaskBarDescriptor config = Configuration.get().taskBarConfiguration().get();
if(config.isInGameDnd()){
if(state) {
if (config.isInGameDnd()) {
if (state) {
executeMessage("/dnd " + config.getDndResponseText());
}else {
} else {
executeMessage("/dnd");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.mercury.platform.shared.config.MercuryConfigurationSource;
import com.mercury.platform.shared.hotkey.HotKeysInterceptor;
import com.mercury.platform.shared.store.MercuryStoreCore;

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

Expand Down
26 changes: 13 additions & 13 deletions app-core/src/main/java/com/mercury/platform/core/ProdStarter.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import com.mercury.platform.core.update.UpdateClientStarter;
import com.mercury.platform.shared.FrameVisibleState;
import com.mercury.platform.shared.HistoryManager;
import com.mercury.platform.shared.config.descriptor.adr.AdrVisibleState;
import com.mercury.platform.shared.hotkey.HotKeysInterceptor;
import com.mercury.platform.shared.UpdateManager;
import com.mercury.platform.shared.config.MercuryConfigManager;
import com.mercury.platform.shared.config.Configuration;
import com.mercury.platform.shared.config.MercuryConfigManager;
import com.mercury.platform.shared.config.MercuryConfigurationSource;
import com.mercury.platform.shared.config.descriptor.adr.AdrVisibleState;
import com.mercury.platform.shared.hotkey.HotKeysInterceptor;
import com.mercury.platform.shared.store.MercuryStoreCore;
import com.sun.jna.Native;
import com.sun.jna.platform.win32.User32;
Expand All @@ -29,7 +29,7 @@ public class ProdStarter {
private volatile int delay = 100;
private boolean updating = false;

public void startApplication(){
public void startApplication() {
MercuryConfigManager configuration = new MercuryConfigManager(new MercuryConfigurationSource());
configuration.load();
Configuration.set(configuration);
Expand All @@ -48,10 +48,10 @@ public void startApplication(){
timer.schedule(new TimerTask() {
@Override
public void run() {
if(shutdown){
if (shutdown) {
timer.cancel();
updateClientStarter.shutdown();
if(updating){
if (updating) {
updateManager.doUpdate();
}
System.exit(0);
Expand All @@ -63,19 +63,19 @@ public void run() {
User32.INSTANCE.GetClassName(hwnd, className, 512);
User32.INSTANCE.GetWindowText(hwnd, title, 512);

if(Native.toString(title).equals("MercuryTrade ADR")){
if (Native.toString(title).equals("MercuryTrade ADR")) {
MercuryStoreCore.adrVisibleSubject.onNext(AdrVisibleState.SHOW);
}else {
} else {
MercuryStoreCore.adrVisibleSubject.onNext(AdrVisibleState.HIDE);
}

if(!Native.toString(className).equals("POEWindowClass")){
if(APP_STATUS == FrameVisibleState.SHOW) {
if (!Native.toString(className).equals("POEWindowClass")) {
if (APP_STATUS == FrameVisibleState.SHOW) {
APP_STATUS = FrameVisibleState.HIDE;
MercuryStoreCore.frameVisibleSubject.onNext(FrameVisibleState.HIDE);
}
}else{
if(APP_STATUS == FrameVisibleState.HIDE) {
} else {
if (APP_STATUS == FrameVisibleState.HIDE) {
try {
Thread.sleep(delay);
delay = 100;
Expand All @@ -87,7 +87,7 @@ public void run() {
}
}
}
},0,150);
}, 0, 150);
});
MercuryStoreCore.showingDelaySubject.subscribe(state -> this.delay = 300);
MercuryStoreCore.shutdownAppSubject.subscribe(state -> this.shutdown = true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
public class SoundNotifier {
private final Logger logger = LogManager.getLogger(SoundNotifier.class);
private boolean dnd = false;

public SoundNotifier() {
MercuryStoreCore.soundSubject
.compose(DataTransformers.transformSoundData())
Expand All @@ -23,20 +24,20 @@ public SoundNotifier() {
.subscribe(value -> this.dnd = value);
}

private void play(String wavPath, float db){
if(!dnd && db > -40) {
private void play(String wavPath, float db) {
if (!dnd && db > -40) {
ClassLoader classLoader = getClass().getClassLoader();
try (AudioInputStream stream = AudioSystem.getAudioInputStream(classLoader.getResource(wavPath))) {
Clip clip = AudioSystem.getClip();
clip.open(stream);
if(db != 0.0) {
if (db != 0.0) {
FloatControl gainControl =
(FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
gainControl.setValue(db);
}
clip.start();
} catch (Exception e) {
logger.error("Cannot start playing wav file: ",e);
logger.error("Cannot start playing wav file: ", e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@


public enum SoundType {
MESSAGE,UPDATE,CHAT_SCANNER,CLICKS
MESSAGE, UPDATE, CHAT_SCANNER, CLICKS
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ public String asPretty() {
}
};

public abstract String asPretty();
public static WhisperNotifierStatus valueOfPretty(String s){
public static WhisperNotifierStatus valueOfPretty(String s) {
for (WhisperNotifierStatus status : WhisperNotifierStatus.values()) {
if(status.asPretty().equals(s)){
if (status.asPretty().equals(s)) {
return status;
}
}
return null;
}

public abstract String asPretty();
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/**
* Created by Frost on 14.01.2017.
*/
public class UpdateClientStarter implements Runnable{
public class UpdateClientStarter implements Runnable {
private static final Logger LOGGER = LogManager.getLogger(UpdateClientStarter.class.getSimpleName());
private static final String JARS_FILE_PATH = System.getenv("USERPROFILE") + "\\AppData\\Local\\MercuryTrade\\temp";

Expand All @@ -25,7 +25,7 @@ public class UpdateClientStarter implements Runnable{
public void run() {
updaterClient = new UpdaterClient(MercuryConstants.SERVER_HOST, MercuryConstants.APP_VERSION, MercuryConstants.PORT);
updaterClient.registerListener(handler -> {
Files.write(Paths.get(JARS_FILE_PATH + "\\MercuryTrade.jar") , handler.getBytes() , StandardOpenOption.CREATE);
Files.write(Paths.get(JARS_FILE_PATH + "\\MercuryTrade.jar"), handler.getBytes(), StandardOpenOption.CREATE);
setMercuryVersion(getIncrementedVersion(MercuryConstants.APP_VERSION));
MercuryStoreCore.updateReadySubject.onNext(true);
});
Expand All @@ -35,18 +35,21 @@ public void run() {
LOGGER.error(e);
}
}

public synchronized void setMercuryVersion(String mercuryVersion) {
String version = mercuryVersion.replace(".", "0");
ApplicationHolder applicationHolder = ApplicationHolder.getInstance();
applicationHolder.setVersion(Integer.valueOf(version));
}
private String getIncrementedVersion(String version){

private String getIncrementedVersion(String version) {
String replace = version.replace(".", "0");
Integer intVersion = Integer.valueOf(replace);
intVersion++;
return String.valueOf(intVersion).replace("0",".");
return String.valueOf(intVersion).replace("0", ".");
}
public void shutdown(){

public void shutdown() {
updaterClient.shutdown();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,19 @@
/**
* Created by Frost on 25.01.2017.
*/
public class UpdaterClientEventBus extends EventBus{
public class UpdaterClientEventBus extends EventBus {

private static final UpdaterClientEventBus instance = new UpdaterClientEventBus();

public static UpdaterClientEventBus getInstance() {
return instance;
}

private EventBus eventBus;

private UpdaterClientEventBus() {
this.eventBus = new EventBus();
}

public static UpdaterClientEventBus getInstance() {
return instance;
}

@Override
public void register(Object object) {
eventBus.register(object);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class UpdateReceivedEvent {
private byte[] bytes;


public UpdateReceivedEvent(byte [] bytes) {
public UpdateReceivedEvent(byte[] bytes) {
this.bytes = bytes;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
* Created by Frost on 25.01.2017.
*/
public interface UpdateEventHandler {
@Subscribe void onUpdateReceived(UpdateReceivedEvent jarFile) throws IOException;
@Subscribe
void onUpdateReceived(UpdateReceivedEvent jarFile) throws IOException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class UpdaterClient {
private EventLoopGroup group;
private Channel channel;
private boolean connectionEstablished;

public UpdaterClient(String host, String mercuryVersion, int port) {
this.host = host;
this.port = port;
Expand All @@ -33,22 +34,22 @@ public UpdaterClient(String host, String mercuryVersion, int port) {
connectionEstablished = false;

MercuryStoreCore.requestPatchSubject.subscribe(state -> {
if(!connectionEstablished){
if (!connectionEstablished) {
ApplicationHolder.getInstance().setManualRequest(false);
MercuryStoreCore.stringAlertSubject.onNext("Server is currently down, please try again later.");
}else {
} else {
MercuryStoreCore.checkOutPatchSubject.onNext(true);
}
});
}

public void start(){
public void start() {
ClientChannelInitializer clientChannelInitializer = new ClientChannelInitializer();
group = new NioEventLoopGroup();
bootstrap = new Bootstrap();
bootstrap.group(group).channel(NioSocketChannel.class)
.remoteAddress(new InetSocketAddress(host, port))
.option(ChannelOption.SO_KEEPALIVE,true)
.option(ChannelOption.SO_KEEPALIVE, true)
.handler(clientChannelInitializer)
;
try {
Expand All @@ -58,7 +59,8 @@ public void start(){
}
doConnect();
}
private void doConnect(){

private void doConnect() {
try {
ChannelFuture channelFuture = bootstrap.connect();
channelFuture.addListener(new ChannelFutureListener() {
Expand All @@ -69,7 +71,7 @@ public void operationComplete(ChannelFuture future) throws Exception {
future.channel().close();
future.channel().eventLoop().schedule(() -> {
bootstrap.connect().addListener(this);
},new Random().nextInt(5),TimeUnit.MINUTES);
}, new Random().nextInt(5), TimeUnit.MINUTES);
} else {
channel = future.channel();
connectionEstablished = true;
Expand All @@ -86,22 +88,27 @@ private void addCLoseDetectListener(Channel _channel) {
});
}
});
}catch (Exception e){
} catch (Exception e) {
doConnect();
}
}

public void shutdown() {
try {
if (group != null)
group.shutdownGracefully().sync();
}catch (InterruptedException e){}
} catch (InterruptedException e) {
}
}

public int getMercuryVersion() {
return ApplicationHolder.getInstance().getVersion();
}

public void registerListener(UpdateEventHandler handler) {
UpdaterClientEventBus.getInstance().register(handler);
}

public void removeListener(UpdateEventHandler handler) {
UpdaterClientEventBus.getInstance().unregister(handler);
}
Expand Down
Loading

0 comments on commit acbdff1

Please sign in to comment.