-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from Shynixn/development
Merge changes to master.
- Loading branch information
Showing
7 changed files
with
161 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
.../src/main/java/com/github/shynixn/mccoroutine/sample/listener/EntityInteractListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.github.shynixn.mccoroutine.sample.listener; | ||
|
||
import com.github.shynixn.mccoroutine.sample.entity.UserData; | ||
import com.github.shynixn.mccoroutine.sample.impl.UserDataCache; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.player.PlayerInteractAtEntityEvent; | ||
|
||
import java.util.concurrent.CompletionStage; | ||
|
||
/** | ||
* This is a Java example how to interact with suspend functions from Java. | ||
*/ | ||
public class EntityInteractListener implements Listener { | ||
private final UserDataCache userDataCache; | ||
|
||
public EntityInteractListener(UserDataCache userDataCache) { | ||
this.userDataCache = userDataCache; | ||
} | ||
|
||
@EventHandler | ||
public void onPlayerInteractEvent(PlayerInteractAtEntityEvent event) { | ||
System.out.println("[EntityInteractListener] Is starting on Primary Thread: " + Bukkit.isPrimaryThread()); | ||
|
||
CompletionStage<UserData> future = this.userDataCache.getUserDataFromPlayer(event.getPlayer()); | ||
future.thenAccept(useData -> { | ||
System.out.println("[EntityInteractListener] Is ending on Primary Thread: " + Bukkit.isPrimaryThread()); | ||
}).exceptionally(throwable -> { | ||
throwable.printStackTrace(); | ||
return null; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters