mirror of
https://github.com/AppleDash/SaneEconomy.git
synced 2024-06-21 20:14:46 +02:00
Make async transactions not crash the server
This commit is contained in:
parent
db8970ebbd
commit
e2cc0f3f03
|
@ -17,8 +17,7 @@ import java.math.BigDecimal;
|
|||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
/**
|
||||
* Created by AppleDash on 6/13/2016.
|
||||
|
@ -144,17 +143,25 @@ public class EconomyManager {
|
|||
if (Bukkit.getServer().getPluginManager() != null) { // Bukkit.getServer().getPluginManager() == null from our JUnit tests.
|
||||
SaneEconomyTransactionEvent evt = new SaneEconomyTransactionEvent(transaction);
|
||||
|
||||
Future<SaneEconomyTransactionEvent> future = Bukkit.getServer().getScheduler().callSyncMethod(SaneEconomy.getInstance(), () -> {
|
||||
if (Bukkit.isPrimaryThread()) {
|
||||
Bukkit.getServer().getPluginManager().callEvent(evt);
|
||||
return evt;
|
||||
});
|
||||
|
||||
try {
|
||||
if (future.get().isCancelled()) {
|
||||
if (evt.isCancelled()) {
|
||||
return new TransactionResult(transaction, TransactionResult.Status.CANCELLED_BY_PLUGIN);
|
||||
}
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
} else {
|
||||
Future<SaneEconomyTransactionEvent> future = Bukkit.getServer().getScheduler().callSyncMethod(SaneEconomy.getInstance(), () -> {
|
||||
Bukkit.getServer().getPluginManager().callEvent(evt);
|
||||
return evt;
|
||||
});
|
||||
|
||||
try {
|
||||
if (future.get().isCancelled()) {
|
||||
return new TransactionResult(transaction, TransactionResult.Status.CANCELLED_BY_PLUGIN);
|
||||
}
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue
Block a user