-
Notifications
You must be signed in to change notification settings - Fork 0
⚡ Offload Gem.setGems to async task #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,7 +41,7 @@ public void run() { | |
| } | ||
| switch (args[0].toLowerCase()) { | ||
| case "set": | ||
| set(); | ||
| set(sender, args); | ||
|
||
| break; | ||
| case "check": | ||
| check(); | ||
|
|
@@ -60,13 +60,20 @@ public void run() { | |
| return true; | ||
| } | ||
|
|
||
| private void set() { | ||
| private void set(CommandSender sender, String[] args) { | ||
| if (args.length != 3) { | ||
| sendParameterError(); | ||
| } else { | ||
| try { | ||
| Gem.getPlugin().getGemExecutor().setGems(args[1], Integer.parseInt(args[2])); | ||
| sender.sendMessage(Message.INFO + args[1] + " 的宝石设置为: " + args[2]); | ||
| final String playerName = args[1]; | ||
| final int gems = Integer.parseInt(args[2]); | ||
| new BukkitRunnable() { | ||
| @Override | ||
| public void run() { | ||
| Gem.getPlugin().getGemExecutor().setGems(playerName, gems); | ||
| sender.sendMessage(Message.INFO + playerName + " 的宝石设置为: " + gems); | ||
| } | ||
|
Comment on lines
+70
to
+75
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This async task now calls Useful? React with 👍 / 👎. |
||
| }.runTaskAsynchronously(Gem.getPlugin()); | ||
| } catch (NumberFormatException e) { | ||
| sender.sendMessage(Message.ERROR + "宝石必须是整数"); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,94 @@ | ||||||
| package com.mcatk.gem.command; | ||||||
|
|
||||||
| import com.mcatk.gem.Gem; | ||||||
| import com.mcatk.gem.GemExecutor; | ||||||
| import org.bukkit.Bukkit; | ||||||
| import org.bukkit.Server; | ||||||
| import org.bukkit.command.Command; | ||||||
| import org.bukkit.command.CommandSender; | ||||||
| import org.bukkit.plugin.Plugin; | ||||||
| import org.bukkit.scheduler.BukkitScheduler; | ||||||
| import org.bukkit.scheduler.BukkitTask; | ||||||
| import org.junit.Before; | ||||||
| import org.junit.Test; | ||||||
| import org.junit.runner.RunWith; | ||||||
| import org.mockito.ArgumentCaptor; | ||||||
| import org.mockito.junit.MockitoJUnitRunner; | ||||||
|
|
||||||
| import java.lang.reflect.Field; | ||||||
| import java.util.logging.Logger; | ||||||
|
|
||||||
| import static org.junit.Assert.assertTrue; | ||||||
| import static org.mockito.Mockito.*; | ||||||
|
|
||||||
| @RunWith(MockitoJUnitRunner.class) | ||||||
| public class CommandGemBenchmarkTest { | ||||||
|
||||||
| public class CommandGemBenchmarkTest { | |
| public class CommandGemAsyncTest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a version mismatch between mockito-core (5.11.0) and mockito-inline (5.2.0). These should typically use the same version to avoid potential compatibility issues. Consider updating mockito-inline to 5.11.0 to match mockito-core, or verify that this specific version combination is intentional and compatible.