Skip to content

Commit

Permalink
Further cleanup - Now complies with code style rules.
Browse files Browse the repository at this point in the history
  • Loading branch information
thsassmann committed Mar 8, 2024
1 parent b47f997 commit 90fb738
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
package net.md_5.bungee.api.event;

import java.util.Map;
import net.md_5.bungee.api.config.ListenerInfo;
import net.md_5.bungee.api.plugin.Event;

import java.util.Map;

public class ProxyInitializeEvent extends Event
{

private final Map<ListenerInfo, Boolean> listenerState;

public ProxyInitializeEvent( Map<ListenerInfo, Boolean> listenerState ) {
public ProxyInitializeEvent(Map<ListenerInfo, Boolean> listenerState)
{
this.listenerState = listenerState;
}

public Map<ListenerInfo, Boolean> getListenerState() {
public Map<ListenerInfo, Boolean> getListenerState()
{
return listenerState;
}
}
33 changes: 17 additions & 16 deletions api/src/main/java/net/md_5/bungee/util/InitEventLogic.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package net.md_5.bungee.util;

import net.md_5.bungee.api.config.ListenerInfo;
import net.md_5.bungee.api.event.ProxyInitializeEvent;
import java.util.Map;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.locks.ReentrantLock;
import net.md_5.bungee.api.config.ListenerInfo;
import net.md_5.bungee.api.event.ProxyInitializeEvent;


/**
* This class contains the necessary code to fire the ProxyInitializeEvent, as soon as all listeners
Expand All @@ -27,9 +28,9 @@ public class InitEventLogic
* @param listenerInfo ListenerInfo to assign a state to.
* @param success True: Port has opened. False: Port failed to open.
*/
public static void setListenerAsInitialized( ListenerInfo listenerInfo, boolean success )
public static void setListenerAsInitialized(ListenerInfo listenerInfo, boolean success)
{
if( listenerInfo == null )
if ( listenerInfo == null )
{
throw new NullPointerException( "ListenerInfo may not be null!" );
}
Expand All @@ -49,16 +50,16 @@ public static void setListenerAsInitialized( ListenerInfo listenerInfo, boolean
* @throws IllegalArgumentException Thrown if passed number is negative.
* @throws IllegalStateException Thrown if function is called more than once.
*/
public static void setNumberOfListenersToWaitFor( int number )
public static void setNumberOfListenersToWaitFor(int number)
{
if(number <= 0)
if ( number <= 0 )
{
throw new IllegalArgumentException("The amount of listeners that have to be waited needs to be larger than zero.");
throw new IllegalArgumentException( "The amount of listeners that have to be waited needs to be larger than zero." );
}

if(InitEventLogic.amountOfListenersToWaitFor > 0)
if ( InitEventLogic.amountOfListenersToWaitFor > 0 )
{
throw new IllegalStateException("The amount of listeners cannot be set twice!");
throw new IllegalStateException( "The amount of listeners cannot be set twice!" );
}

InitEventLogic.amountOfListenersToWaitFor = number;
Expand All @@ -68,7 +69,7 @@ public static void setNumberOfListenersToWaitFor( int number )
* Checks if the amount of entries in the internal Map is equals to the previously set amount.
* <br><br>
* Requires a previous call to {@link InitEventLogic#setNumberOfListenersToWaitFor(int)}.<br>
* <bImportant:</b>Will return false if the above-mentioned function was not called before,
* <b>Important:</b>Will return false if the above-mentioned function was not called before,
* even if entries were set via {@link InitEventLogic#setListenerAsInitialized(ListenerInfo, boolean)}
* @return Have all Listeners a defined state?
*/
Expand All @@ -77,7 +78,7 @@ public static boolean areAllListenersInitialized()

// Check if all listeners declared have initialized:

if( InitEventLogic.amountOfListenersToWaitFor == -1 )
if ( InitEventLogic.amountOfListenersToWaitFor == -1 )
{
return false;
}
Expand All @@ -92,19 +93,19 @@ public static boolean areAllListenersInitialized()
* @return null if this function has already been called or the listeners are not ready yet.
* Otherwise, returns valid event object.
*/
public static ProxyInitializeEvent generateEvent( )
public static ProxyInitializeEvent generateEvent()
{
if( InitEventLogic.amountOfListenersToWaitFor == -1 )
if ( InitEventLogic.amountOfListenersToWaitFor == -1 )
{
return null;
}

if( !InitEventLogic.areAllListenersInitialized( ) )
if ( !InitEventLogic.areAllListenersInitialized( ) )
{
return null;
}

if( InitEventLogic.initializeEvent != null )
if ( InitEventLogic.initializeEvent != null )
{
return null;
}
Expand Down
3 changes: 1 addition & 2 deletions proxy/src/main/java/net/md_5/bungee/BungeeCord.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
import net.md_5.bungee.api.config.ListenerInfo;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.event.ProxyInitializeEvent;
import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.api.plugin.PluginManager;
import net.md_5.bungee.chat.ComponentSerializer;
Expand Down Expand Up @@ -358,7 +357,7 @@ public void operationComplete(ChannelFuture future) throws Exception
getLogger().log( Level.WARNING, "Could not bind to host " + info.getSocketAddress(), future.cause() );
}
InitEventLogic.setListenerAsInitialized( info, future.isSuccess() );
if( InitEventLogic.areAllListenersInitialized() )
if ( InitEventLogic.areAllListenersInitialized() )
{
getPluginManager().callEvent( InitEventLogic.generateEvent() );
}
Expand Down

0 comments on commit 90fb738

Please sign in to comment.