mirror of
https://github.com/Zrips/Jobs.git
synced 2024-11-29 14:05:25 +01:00
Better give command handling
This commit is contained in:
parent
49e58de450
commit
8ecc36c306
2
pom.xml
2
pom.xml
@ -5,7 +5,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>Jobs</groupId>
|
||||
<artifactId>jobs</artifactId>
|
||||
<version>4.1.0</version>
|
||||
<version>4.1.1</version>
|
||||
<name>Jobs</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
<properties>
|
||||
|
@ -17,39 +17,53 @@ public class give implements Cmd {
|
||||
@JobCommand(2500)
|
||||
public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) {
|
||||
|
||||
if (args.length < 1 || Jobs.getJob(args[0]) == null && Jobs.getJob(args[1]) == null) {
|
||||
Player player = null;
|
||||
Job job = null;
|
||||
String itemName = null;
|
||||
|
||||
for (String one : args) {
|
||||
if (player == null) {
|
||||
player = Bukkit.getPlayer(one);
|
||||
if (player != null)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (job == null) {
|
||||
job = Jobs.getJob(one);
|
||||
if (job != null)
|
||||
continue;
|
||||
}
|
||||
itemName = one;
|
||||
}
|
||||
|
||||
if (player == null && sender instanceof Player)
|
||||
player = (Player) sender;
|
||||
|
||||
if (player == null) {
|
||||
sender.sendMessage(Jobs.getLanguage().getMessage("command.give.output.notonline", "%playername%", args[0]));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (job == null || itemName == null) {
|
||||
Jobs.getCommandManager().sendUsage(sender, "give");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length == 2 && sender instanceof Player) {
|
||||
Job job = Jobs.getJob(args[0]);
|
||||
for (JobItems item : job.getItems()) {
|
||||
if (item.getNode().equalsIgnoreCase(args[1])) {
|
||||
GiveItem.GiveItemForPlayer((Player) sender, item.getId(), 0, 1, item.getName(), item.getLore(), item.getEnchants());
|
||||
return true;
|
||||
}
|
||||
JobItems jItem = null;
|
||||
|
||||
for (JobItems item : job.getItems()) {
|
||||
if (item.getNode().equalsIgnoreCase(itemName)) {
|
||||
jItem = item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (jItem == null || jItem.getItemStack(player) == null) {
|
||||
sender.sendMessage(Jobs.getLanguage().getMessage("command.give.output.noitem"));
|
||||
return true;
|
||||
} else if (args.length == 3) {
|
||||
Job job = Jobs.getJob(args[1]);
|
||||
Player player = Bukkit.getPlayer(args[0]);
|
||||
if (player == null) {
|
||||
sender.sendMessage(Jobs.getLanguage().getMessage("command.give.output.notonline", "%playername%", args[0]));
|
||||
return true;
|
||||
}
|
||||
for (JobItems item : job.getItems()) {
|
||||
if (item.getNode().equalsIgnoreCase(args[2])) {
|
||||
GiveItem.GiveItemForPlayer(player, item.getId(), 0, 1, item.getName(), item.getLore(), item.getEnchants());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
sender.sendMessage(Jobs.getLanguage().getMessage("command.give.output.noitem"));
|
||||
return true;
|
||||
} else {
|
||||
Jobs.getCommandManager().sendUsage(sender, "give");
|
||||
return true;
|
||||
}
|
||||
|
||||
GiveItem.GiveItemForPlayer(player, jItem.getItemStack(player));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -18,10 +18,17 @@
|
||||
|
||||
package com.gamingmesh.jobs.container;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
public class JobItems {
|
||||
private String node;
|
||||
@ -48,6 +55,31 @@ public class JobItems {
|
||||
return this.node;
|
||||
}
|
||||
|
||||
public ItemStack getItemStack(Player player) {
|
||||
try {
|
||||
ItemStack item = new ItemStack(Material.getMaterial(id), amount, (short) data);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if (this.name != null)
|
||||
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name));
|
||||
if (lore != null) {
|
||||
List<String> TranslatedLore = new ArrayList<String>();
|
||||
for (String oneLore : lore) {
|
||||
TranslatedLore.add(ChatColor.translateAlternateColorCodes('&', oneLore.replace("[player]", player.getName())));
|
||||
}
|
||||
meta.setLore(TranslatedLore);
|
||||
}
|
||||
if (enchants != null)
|
||||
for (Entry<Enchantment, Integer> OneEnchant : enchants.entrySet()) {
|
||||
meta.addEnchant(OneEnchant.getKey(), OneEnchant.getValue(), true);
|
||||
}
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
@ -35,4 +35,10 @@ public class GiveItem {
|
||||
player.getPlayer().updateInventory();
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean GiveItemForPlayer(Player player, ItemStack item) {
|
||||
player.getInventory().addItem(item);
|
||||
player.getPlayer().updateInventory();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
name: Jobs
|
||||
description: Jobs Plugin for the BukkitAPI
|
||||
main: com.gamingmesh.jobs.Jobs
|
||||
version: 4.1.0
|
||||
version: 4.1.1
|
||||
website: https://www.spigotmc.org/resources/jobs-reborn.4216/
|
||||
author: phrstbrn
|
||||
softdepend: [Vault, iConomy, MythicMobs, McMMO, WorldGuard, MyPet]
|
||||
|
Loading…
Reference in New Issue
Block a user