-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add in-game money management (closes #15)
- Loading branch information
1 parent
2579ece
commit da1b6ab
Showing
10 changed files
with
148 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
allprojects { | ||
group 'com.azuriom' | ||
version '1.2.0' | ||
version '1.2.1' | ||
} | ||
|
||
subprojects { | ||
|
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
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
24 changes: 24 additions & 0 deletions
24
common/src/main/java/com/azuriom/azlink/common/users/EditMoneyResult.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,24 @@ | ||
package com.azuriom.azlink.common.users; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
|
||
public class EditMoneyResult { | ||
|
||
@SerializedName("old_balance") | ||
private final double oldBalance; | ||
@SerializedName("new_balance") | ||
private final double newBalance; | ||
|
||
public EditMoneyResult(double oldBalance, double newBalance) { | ||
this.oldBalance = oldBalance; | ||
this.newBalance = newBalance; | ||
} | ||
|
||
public double getOldBalance() { | ||
return oldBalance; | ||
} | ||
|
||
public double getNewBalance() { | ||
return newBalance; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
common/src/main/java/com/azuriom/azlink/common/users/UserManager.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,35 @@ | ||
package com.azuriom.azlink.common.users; | ||
|
||
import com.azuriom.azlink.common.AzLinkPlugin; | ||
import com.azuriom.azlink.common.data.UserInfo; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
public class UserManager { | ||
|
||
private final Map<String, UserInfo> usersByName = new ConcurrentHashMap<>(); | ||
private final AzLinkPlugin plugin; | ||
|
||
public UserManager(AzLinkPlugin plugin) { | ||
this.plugin = plugin; | ||
} | ||
|
||
public Optional<UserInfo> getUserByName(String name) { | ||
return Optional.ofNullable(this.usersByName.get(name)); | ||
} | ||
|
||
public void addUser(UserInfo user) { | ||
this.usersByName.put(user.getName(), user); | ||
} | ||
|
||
public CompletableFuture<UserInfo> editMoney(UserInfo user, String action, double amount) { | ||
return this.plugin.getHttpClient().editMoney(user, action, amount) | ||
.thenApply(result -> { | ||
user.setMoney(result.getNewBalance()); | ||
return user; | ||
}); | ||
} | ||
} |
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