mirror of
https://github.com/Zrips/Jobs.git
synced 2025-02-27 09:43:22 +01:00
exp command cleanup
This commit is contained in:
parent
6715fa7bee
commit
2dc25b232d
4
pom.xml
4
pom.xml
@ -197,7 +197,7 @@
|
||||
<artifactId>CMILib</artifactId>
|
||||
<version>latest</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${basedir}/libs/CMILib1.2.3.3.jar</systemPath>
|
||||
<systemPath>${basedir}/libs/CMILib1.2.4.1.jar</systemPath>
|
||||
</dependency>
|
||||
<!-- WildStacker -->
|
||||
<dependency>
|
||||
@ -286,7 +286,7 @@
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>2.3.1</version>
|
||||
<configuration>
|
||||
<!-- <outputDirectory>D:\MC\Server 1.19\plugins\</outputDirectory> -->
|
||||
<outputDirectory>D:\MC\Server 1.19\plugins\</outputDirectory>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
@ -28,6 +28,7 @@ import net.Zrips.CMILib.ActionBar.CMIActionBar;
|
||||
import net.Zrips.CMILib.Container.CMIArray;
|
||||
import net.Zrips.CMILib.Container.PageInfo;
|
||||
import net.Zrips.CMILib.Locale.LC;
|
||||
import net.Zrips.CMILib.Logs.CMIDebug;
|
||||
import net.Zrips.CMILib.Messages.CMIMessages;
|
||||
import net.Zrips.CMILib.RawMessages.RawMessage;
|
||||
|
||||
@ -51,6 +52,7 @@ public class JobsCommands implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
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())
|
||||
&& !sender.hasPermission("jobs.disabledworld.commands")) {
|
||||
sender.sendMessage(Jobs.getLanguage().getMessage("general.error.worldisdisabled"));
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.gamingmesh.jobs.commands.list;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
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.JobProgression;
|
||||
import com.gamingmesh.jobs.container.JobsPlayer;
|
||||
|
||||
import java.util.Random;
|
||||
import com.gamingmesh.jobs.i18n.Language;
|
||||
|
||||
public class exp implements Cmd {
|
||||
|
||||
@ -17,22 +18,38 @@ public class exp implements Cmd {
|
||||
Set, Add, Take
|
||||
}
|
||||
|
||||
Random rand = new Random();
|
||||
|
||||
@Override
|
||||
public boolean perform(Jobs plugin, CommandSender sender, String[] args) {
|
||||
|
||||
if (args.length < 4) {
|
||||
Jobs.getCommandManager().sendUsage(sender, "exp");
|
||||
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]);
|
||||
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;
|
||||
}
|
||||
|
||||
Job job = Jobs.getJob(args[1]);
|
||||
if (job == null) {
|
||||
sender.sendMessage(Jobs.getLanguage().getMessage("general.error.job"));
|
||||
Language.sendMessage(sender, "general.error.job");
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -53,7 +70,6 @@ public class exp implements Cmd {
|
||||
}
|
||||
|
||||
double amount = 0.0;
|
||||
|
||||
/* Add random argument, ex: rand_5-10 */
|
||||
if (args[3].startsWith("rand_")) {
|
||||
String data = args[3].split("(?i)rand_")[1];
|
||||
@ -62,8 +78,8 @@ public class exp implements Cmd {
|
||||
int amountMin = Integer.parseInt(arr[0]);
|
||||
int amountMax = Integer.parseInt(arr[1]);
|
||||
|
||||
if (amountMin <= amountMax) {
|
||||
amount = amountMin + new Random().nextDouble() * (amountMax - amountMin);
|
||||
if (amountMin < amountMax) {
|
||||
amount = amountMin + rand.nextInt(amountMax - amountMin);
|
||||
} else {
|
||||
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 {
|
||||
// check if player already has the job
|
||||
if (jPlayer.isInJob(job)) {
|
||||
JobProgression prog = jPlayer.getJobProgression(job);
|
||||
|
||||
switch (action) {
|
||||
@ -99,36 +119,22 @@ public class exp implements Cmd {
|
||||
}
|
||||
|
||||
Player player = jPlayer.getPlayer();
|
||||
boolean isSilent = false;
|
||||
boolean isSilentAdmin = false;
|
||||
if (player != null) {
|
||||
for (String one : args) {
|
||||
if (one.equalsIgnoreCase("-s")) {
|
||||
isSilent = true;
|
||||
break;
|
||||
if (player == null) {
|
||||
sender.sendMessage(Jobs.getLanguage().getMessage("general.give.output.notonline"));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (!isSilent) {
|
||||
|
||||
if (!silent)
|
||||
player.sendMessage(Jobs.getLanguage().getMessage("command.exp.output.target", "%jobname%", job.getDisplayName(), "%level%", prog.getLevelFormatted(), "%exp%", prog
|
||||
.getExperience()));
|
||||
}
|
||||
for (String one : args) {
|
||||
if (one.equalsIgnoreCase("-sa")) {
|
||||
isSilentAdmin = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!isSilentAdmin) {
|
||||
|
||||
if (!silentAdmin)
|
||||
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) {
|
||||
if (!silentAdmin)
|
||||
sender.sendMessage(Jobs.getLanguage().getMessage("general.admin.error"));
|
||||
e.printStackTrace();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import com.gamingmesh.jobs.Jobs;
|
||||
@ -48,6 +49,10 @@ public class Language {
|
||||
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
|
||||
* @param key - the key of the message
|
||||
|
Loading…
Reference in New Issue
Block a user