1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-12-01 23:13:48 +01:00

exp command cleanup

This commit is contained in:
Zrips 2023-01-06 14:30:50 +02:00
parent 6715fa7bee
commit 2dc25b232d
4 changed files with 156 additions and 143 deletions

View File

@ -197,7 +197,7 @@
<artifactId>CMILib</artifactId> <artifactId>CMILib</artifactId>
<version>latest</version> <version>latest</version>
<scope>system</scope> <scope>system</scope>
<systemPath>${basedir}/libs/CMILib1.2.3.3.jar</systemPath> <systemPath>${basedir}/libs/CMILib1.2.4.1.jar</systemPath>
</dependency> </dependency>
<!-- WildStacker --> <!-- WildStacker -->
<dependency> <dependency>
@ -286,7 +286,7 @@
<artifactId>maven-jar-plugin</artifactId> <artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version> <version>2.3.1</version>
<configuration> <configuration>
<!-- <outputDirectory>D:\MC\Server 1.19\plugins\</outputDirectory> --> <outputDirectory>D:\MC\Server 1.19\plugins\</outputDirectory>
</configuration> </configuration>
</plugin> </plugin>
</plugins> </plugins>

View File

@ -28,6 +28,7 @@ import net.Zrips.CMILib.ActionBar.CMIActionBar;
import net.Zrips.CMILib.Container.CMIArray; import net.Zrips.CMILib.Container.CMIArray;
import net.Zrips.CMILib.Container.PageInfo; import net.Zrips.CMILib.Container.PageInfo;
import net.Zrips.CMILib.Locale.LC; import net.Zrips.CMILib.Locale.LC;
import net.Zrips.CMILib.Logs.CMIDebug;
import net.Zrips.CMILib.Messages.CMIMessages; import net.Zrips.CMILib.Messages.CMIMessages;
import net.Zrips.CMILib.RawMessages.RawMessage; import net.Zrips.CMILib.RawMessages.RawMessage;
@ -51,6 +52,7 @@ public class JobsCommands implements CommandExecutor {
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
CMIDebug.d("jobs commands");
if (sender instanceof Player && !Jobs.getGCManager().canPerformActionInWorld(((Player) sender).getWorld()) if (sender instanceof Player && !Jobs.getGCManager().canPerformActionInWorld(((Player) sender).getWorld())
&& !sender.hasPermission("jobs.disabledworld.commands")) { && !sender.hasPermission("jobs.disabledworld.commands")) {
sender.sendMessage(Jobs.getLanguage().getMessage("general.error.worldisdisabled")); sender.sendMessage(Jobs.getLanguage().getMessage("general.error.worldisdisabled"));

View File

@ -1,5 +1,7 @@
package com.gamingmesh.jobs.commands.list; package com.gamingmesh.jobs.commands.list;
import java.util.Random;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -8,8 +10,7 @@ import com.gamingmesh.jobs.commands.Cmd;
import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.Job;
import com.gamingmesh.jobs.container.JobProgression; import com.gamingmesh.jobs.container.JobProgression;
import com.gamingmesh.jobs.container.JobsPlayer; import com.gamingmesh.jobs.container.JobsPlayer;
import com.gamingmesh.jobs.i18n.Language;
import java.util.Random;
public class exp implements Cmd { public class exp implements Cmd {
@ -17,22 +18,38 @@ public class exp implements Cmd {
Set, Add, Take Set, Add, Take
} }
Random rand = new Random();
@Override @Override
public boolean perform(Jobs plugin, CommandSender sender, String[] args) { public boolean perform(Jobs plugin, CommandSender sender, String[] args) {
if (args.length < 4) { if (args.length < 4) {
Jobs.getCommandManager().sendUsage(sender, "exp"); Jobs.getCommandManager().sendUsage(sender, "exp");
return true; return true;
} }
boolean silent = false;
boolean silentAdmin = false;
for (String one : args) {
if (one.equalsIgnoreCase("-s")) {
silent = true;
continue;
}
if (one.equalsIgnoreCase("-sa")) {
silentAdmin = true;
}
}
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]); JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]);
if (jPlayer == null) { if (jPlayer == null) {
sender.sendMessage(Jobs.getLanguage().getMessage("general.error.noinfoByPlayer", "%playername%", args[0])); Language.sendMessage(sender, "general.error.noinfoByPlayer", "%playername%", args[0]);
return true; return true;
} }
Job job = Jobs.getJob(args[1]); Job job = Jobs.getJob(args[1]);
if (job == null) { if (job == null) {
sender.sendMessage(Jobs.getLanguage().getMessage("general.error.job")); Language.sendMessage(sender, "general.error.job");
return true; return true;
} }
@ -53,7 +70,6 @@ public class exp implements Cmd {
} }
double amount = 0.0; double amount = 0.0;
/* Add random argument, ex: rand_5-10 */ /* Add random argument, ex: rand_5-10 */
if (args[3].startsWith("rand_")) { if (args[3].startsWith("rand_")) {
String data = args[3].split("(?i)rand_")[1]; String data = args[3].split("(?i)rand_")[1];
@ -62,8 +78,8 @@ public class exp implements Cmd {
int amountMin = Integer.parseInt(arr[0]); int amountMin = Integer.parseInt(arr[0]);
int amountMax = Integer.parseInt(arr[1]); int amountMax = Integer.parseInt(arr[1]);
if (amountMin <= amountMax) { if (amountMin < amountMax) {
amount = amountMin + new Random().nextDouble() * (amountMax - amountMin); amount = amountMin + rand.nextInt(amountMax - amountMin);
} else { } else {
amount = amountMax; amount = amountMax;
} }
@ -77,9 +93,13 @@ public class exp implements Cmd {
} }
} }
if (!jPlayer.isInJob(job)) {
Language.sendMessage(sender, "command.exp.error.nojob");
return true;
}
try { try {
// check if player already has the job // check if player already has the job
if (jPlayer.isInJob(job)) {
JobProgression prog = jPlayer.getJobProgression(job); JobProgression prog = jPlayer.getJobProgression(job);
switch (action) { switch (action) {
@ -99,36 +119,22 @@ public class exp implements Cmd {
} }
Player player = jPlayer.getPlayer(); Player player = jPlayer.getPlayer();
boolean isSilent = false; if (player == null) {
boolean isSilentAdmin = false; sender.sendMessage(Jobs.getLanguage().getMessage("general.give.output.notonline"));
if (player != null) { return true;
for (String one : args) {
if (one.equalsIgnoreCase("-s")) {
isSilent = true;
break;
} }
}
if (!isSilent) { if (!silent)
player.sendMessage(Jobs.getLanguage().getMessage("command.exp.output.target", "%jobname%", job.getDisplayName(), "%level%", prog.getLevelFormatted(), "%exp%", prog player.sendMessage(Jobs.getLanguage().getMessage("command.exp.output.target", "%jobname%", job.getDisplayName(), "%level%", prog.getLevelFormatted(), "%exp%", prog
.getExperience())); .getExperience()));
}
for (String one : args) { if (!silentAdmin)
if (one.equalsIgnoreCase("-sa")) {
isSilentAdmin = true;
break;
}
}
if (!isSilentAdmin) {
sender.sendMessage(Jobs.getLanguage().getMessage("general.admin.success")); sender.sendMessage(Jobs.getLanguage().getMessage("general.admin.success"));
}
} else {
sender.sendMessage(Jobs.getLanguage().getMessage("general.give.output.notonline"));
}
} else {
sender.sendMessage(Jobs.getLanguage().getMessage("command.exp.error.nojob"));
}
} catch (Exception e) { } catch (Exception e) {
if (!silentAdmin)
sender.sendMessage(Jobs.getLanguage().getMessage("general.admin.error")); sender.sendMessage(Jobs.getLanguage().getMessage("general.admin.error"));
e.printStackTrace();
} }
return true; return true;
} }

View File

@ -24,6 +24,7 @@ import java.util.List;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.Jobs;
@ -48,6 +49,10 @@ public class Language {
customlocale = enlocale; customlocale = enlocale;
} }
public static void sendMessage(CommandSender sender, String key, Object... variables) {
sender.sendMessage(Jobs.getLanguage().getMessage(key, variables));
}
/** /**
* Get the message with the correct key * Get the message with the correct key
* @param key - the key of the message * @param key - the key of the message