Skip to content

Commit

Permalink
Fixed minor issues & added new commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Picono435 committed Aug 22, 2020
1 parent dc44a82 commit dd4406c
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.codehaus.plexus.util.FileUtils;

import com.gmail.picono435.picojobs.PicoJobsPlugin;
import com.gmail.picono435.picojobs.api.JobPlayer;
import com.gmail.picono435.picojobs.api.PicoJobsAPI;
import com.gmail.picono435.picojobs.managers.LanguageManager;
import com.gmail.picono435.picojobs.utils.FileCreator;

public class JobsAdminCommand implements CommandExecutor, TabCompleter {

@SuppressWarnings("deprecation")
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if(!cmd.getName().equals("jobsadmin")) return false;
Expand All @@ -48,6 +50,11 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
String reloadString = LanguageManager.getSubCommandAlias("reload");
String updateString = LanguageManager.getSubCommandAlias("update");
String aboutString = LanguageManager.getSubCommandAlias("about");
String setString = LanguageManager.getSubCommandAlias("set");

String salaryString = LanguageManager.getSubCommandAlias("salary");
String methodString = LanguageManager.getSubCommandAlias("method");

Player pl = null;
if(sender instanceof Player) {
pl = (Player)sender;
Expand Down Expand Up @@ -100,7 +107,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
return true;
}

// UPDATE COMMAND
// ABOUT COMMAND
if(subcmd.equalsIgnoreCase("about") || subcmd.equalsIgnoreCase(aboutString)) {
String message = "&eHere are some information about the plugin\n"
+ "&ePlugin version:&6 v" + PicoJobsPlugin.getInstance().getDescription().getVersion() + "\n"
Expand All @@ -111,6 +118,60 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
p.sendMessage(LanguageManager.formatMessage(message));
return true;
}

// SET COMMAND
if(subcmd.equalsIgnoreCase("set") || subcmd.equalsIgnoreCase(setString)) {
if(args.length < 2) {
p.sendMessage(LanguageManager.getMessage("no-args", pl));
return true;
}
// /jobsadmin set salary Frankandstile 1000
if(args[1].equalsIgnoreCase("salary") || args[1].equalsIgnoreCase(salaryString)) {
if(args.length < 4) {
p.sendMessage(LanguageManager.getMessage("no-args", pl));
return true;
}
JobPlayer jpNew = PicoJobsAPI.getPlayersManager().getJobPlayer(args[2]);
if(jpNew == null) {
p.sendMessage(LanguageManager.getMessage("player-not-found", pl));
return true;
}
int newSalary = 0;
try {
newSalary = Integer.parseInt(args[3]);
} catch(Exception ex) {
p.sendMessage(LanguageManager.getMessage("no-args", pl));
return true;
}
jpNew.setSalary(newSalary);
p.sendMessage(LanguageManager.getMessage("sucefully", pl));
return true;
}

if(args[1].equalsIgnoreCase("method") || args[1].equalsIgnoreCase(methodString)) {
if(args.length < 4) {
p.sendMessage(LanguageManager.getMessage("no-args", pl));
return true;
}
JobPlayer jpNew = PicoJobsAPI.getPlayersManager().getJobPlayer(args[2]);
if(jpNew == null) {
p.sendMessage(LanguageManager.getMessage("player-not-found", pl));
return true;
}
int newMethod = 0;
try {
newMethod = Integer.parseInt(args[3]);
} catch(Exception ex) {
p.sendMessage(LanguageManager.getMessage("no-args", pl));
return true;
}
jpNew.setMethod(newMethod);
p.sendMessage(LanguageManager.getMessage("sucefully", pl));
return true;
}

p.sendMessage(LanguageManager.getFormat("admin-commands", null));
}
return true;
}

Expand All @@ -123,18 +184,50 @@ public List<String> onTabComplete(CommandSender sender, Command cmd, String alia
String reloadString = LanguageManager.getSubCommandAlias("reload");
String updateString = LanguageManager.getSubCommandAlias("update");
String aboutString = LanguageManager.getSubCommandAlias("about");
String setString = LanguageManager.getSubCommandAlias("set");

String salaryString = LanguageManager.getSubCommandAlias("salary");
String methodString = LanguageManager.getSubCommandAlias("method");

if(!p.hasPermission("picojobs.admin")) return null;

List<String> list = new ArrayList<String>();

if(args.length == 1) {
List<String> list = new ArrayList<String>();
if(p.hasPermission("picojobs.admin")) {
list.add(helpString);
list.add(infoString);
list.add(reloadString);
list.add(updateString);
list.add(aboutString);
}
list.add(helpString);
list.add(infoString);
list.add(reloadString);
list.add(updateString);
list.add(aboutString);
list.add(setString);
return list;
}

if(args.length == 2) {
if(args[0].equalsIgnoreCase("set") || args[0].equalsIgnoreCase(setString)) {
list.add(salaryString);
list.add(methodString);
return list;
}
}

if(args.length == 3) {
if(args[0].equalsIgnoreCase("set") || args[0].equalsIgnoreCase(setString)) {
list.add("[<player>]");
return list;
}
}

if(args.length == 4) {
if(args[0].equalsIgnoreCase("set") || args[0].equalsIgnoreCase(setString)) {
if(args[1].equalsIgnoreCase("salary") || args[1].equalsIgnoreCase(salaryString)) {
list.add("[<" + salaryString + ">]");
} else if(args[1].equalsIgnoreCase("method") || args[1].equalsIgnoreCase(methodString)) {
list.add("[<" + methodString + ">]");
}
return list;
}
}
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,11 @@ public static List<String> getCommandAliases(String cmd) {
*
*/
public static String getSubCommandAlias(String subcmd) {
String chat = language.getConfigurationSection("aliases").getString(subcmd).toLowerCase();
String chat = language.getConfigurationSection("aliases").getString(subcmd);
if(chat == null) {
chat = subcmd;
}
chat = chat.toLowerCase();
return chat;
}

Expand Down
1 change: 0 additions & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# IMPORTANT #
# Some configurations have the ** PREMIUM ONLY ** tag, this means that the configurations are only for the premium version.
# Our plugin uses PlaceholderAPI to make placeholders, it's not required but if you want to use it you need to add it
# A detailed wiki of our plugin can be found here: https://github.com/Picono435/wiki
# All the configurations are commented, but if you still need help check the wiki or send a message in our discord
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/langs/en-GB.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ admin-commands: |-
&e/jobsadmin reload &6- &eReload all the possible configurations.
&e/jobsadmin update &6- &eInstalls a update of the plugin
&e/jobsadmin about &6- &eGets informations about the server and the plugin
&e/jobsadmin set <salary | method> <player> <amount> &6- &eSets the salary/method of a player
info-command: |-
&6Status of the player %player_name%
&eSalary: %jobplayer_salary%
Expand All @@ -43,7 +44,7 @@ left-job: "&cYou are not unemployed! We recommend you choose a new job or you wi
already-updated: "&cThe plugin is already in the lastest version, for more information check our WIKI."
update-started: "&aThe update of the plugin PicoJobs started, please wait..."
updated-sucefully: "&aThe plugin was updated sucefully, please restart the server to finish the update."
sucefully: "&aThe action was made sucefully."

##################################################################################
# #
Expand Down
20 changes: 10 additions & 10 deletions src/main/resources/settings/jobs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ jobs:
item-data: 0
# If you want to the item be enchanted or not
enchanted: false
# Set the permissions that this job should have ** PREMIUM ONLY **
# Set the permissions that this job should have
# REQUIRES VAULT
permissions:
permissions: # [SOON]
- kit.use.thief

# This is a example of a police job
Expand Down Expand Up @@ -71,9 +71,9 @@ jobs:
item-data: 0
# If you want to the item be enchanted or not
enchanted: false
# Set the permissions that this job should have ** PREMIUM ONLY **
# Set the permissions that this job should have
# REQUIRES VAULT
permissions:
permissions: # [SOON]
- kit.use.police

# This is a example of a miner job
Expand Down Expand Up @@ -108,9 +108,9 @@ jobs:
item-data: 0
# If you want to the item be enchanted or not
enchanted: false
# Set the permissions that this job should have ** PREMIUM ONLY **
# Set the permissions that this job should have
# REQUIRES VAULT
permissions:
permissions: # [SOON]
- kit.use.miner

# This is a example of a assassin job
Expand Down Expand Up @@ -143,9 +143,9 @@ jobs:
item-data: 0
# If you want to the item be enchanted or not
enchanted: true
# Set the permissions that this job should have ** PREMIUM ONLY **
# Set the permissions that this job should have
# REQUIRES VAULT
permissions:
permissions: # [SOON]
- kit.use.assassin

# This is a example of a assassin job
Expand Down Expand Up @@ -176,7 +176,7 @@ jobs:
item-data: 0
# If you want to the item be enchanted or not
enchanted: true
# Set the permissions that this job should have ** PREMIUM ONLY **
# Set the permissions that this job should have
# REQUIRES VAULT
permissions:
permissions: # [SOON]
- kit.use.fisher

0 comments on commit dd4406c

Please sign in to comment.