mirror of
https://github.com/Zrips/Jobs.git
synced 2024-12-01 15:03:36 +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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>Jobs</groupId>
|
<groupId>Jobs</groupId>
|
||||||
<artifactId>jobs</artifactId>
|
<artifactId>jobs</artifactId>
|
||||||
<version>4.1.0</version>
|
<version>4.1.1</version>
|
||||||
<name>Jobs</name>
|
<name>Jobs</name>
|
||||||
<url>http://maven.apache.org</url>
|
<url>http://maven.apache.org</url>
|
||||||
<properties>
|
<properties>
|
||||||
|
@ -17,39 +17,53 @@ public class give implements Cmd {
|
|||||||
@JobCommand(2500)
|
@JobCommand(2500)
|
||||||
public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) {
|
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;
|
||||||
Jobs.getCommandManager().sendUsage(sender, "give");
|
Job job = null;
|
||||||
return true;
|
String itemName = null;
|
||||||
|
|
||||||
|
for (String one : args) {
|
||||||
|
if (player == null) {
|
||||||
|
player = Bukkit.getPlayer(one);
|
||||||
|
if (player != null)
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.length == 2 && sender instanceof Player) {
|
if (job == null) {
|
||||||
Job job = Jobs.getJob(args[0]);
|
job = Jobs.getJob(one);
|
||||||
for (JobItems item : job.getItems()) {
|
if (job != null)
|
||||||
if (item.getNode().equalsIgnoreCase(args[1])) {
|
continue;
|
||||||
GiveItem.GiveItemForPlayer((Player) sender, item.getId(), 0, 1, item.getName(), item.getLore(), item.getEnchants());
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
itemName = one;
|
||||||
}
|
}
|
||||||
sender.sendMessage(Jobs.getLanguage().getMessage("command.give.output.noitem"));
|
|
||||||
return true;
|
if (player == null && sender instanceof Player)
|
||||||
} else if (args.length == 3) {
|
player = (Player) sender;
|
||||||
Job job = Jobs.getJob(args[1]);
|
|
||||||
Player player = Bukkit.getPlayer(args[0]);
|
|
||||||
if (player == null) {
|
if (player == null) {
|
||||||
sender.sendMessage(Jobs.getLanguage().getMessage("command.give.output.notonline", "%playername%", args[0]));
|
sender.sendMessage(Jobs.getLanguage().getMessage("command.give.output.notonline", "%playername%", args[0]));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
for (JobItems item : job.getItems()) {
|
|
||||||
if (item.getNode().equalsIgnoreCase(args[2])) {
|
if (job == null || itemName == null) {
|
||||||
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");
|
Jobs.getCommandManager().sendUsage(sender, "give");
|
||||||
return true;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
GiveItem.GiveItemForPlayer(player, jItem.getItemStack(player));
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,10 +18,17 @@
|
|||||||
|
|
||||||
package com.gamingmesh.jobs.container;
|
package com.gamingmesh.jobs.container;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
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.enchantments.Enchantment;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
public class JobItems {
|
public class JobItems {
|
||||||
private String node;
|
private String node;
|
||||||
@ -48,6 +55,31 @@ public class JobItems {
|
|||||||
return this.node;
|
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() {
|
public int getId() {
|
||||||
return this.id;
|
return this.id;
|
||||||
}
|
}
|
||||||
|
@ -35,4 +35,10 @@ public class GiveItem {
|
|||||||
player.getPlayer().updateInventory();
|
player.getPlayer().updateInventory();
|
||||||
return true;
|
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
|
name: Jobs
|
||||||
description: Jobs Plugin for the BukkitAPI
|
description: Jobs Plugin for the BukkitAPI
|
||||||
main: com.gamingmesh.jobs.Jobs
|
main: com.gamingmesh.jobs.Jobs
|
||||||
version: 4.1.0
|
version: 4.1.1
|
||||||
website: https://www.spigotmc.org/resources/jobs-reborn.4216/
|
website: https://www.spigotmc.org/resources/jobs-reborn.4216/
|
||||||
author: phrstbrn
|
author: phrstbrn
|
||||||
softdepend: [Vault, iConomy, MythicMobs, McMMO, WorldGuard, MyPet]
|
softdepend: [Vault, iConomy, MythicMobs, McMMO, WorldGuard, MyPet]
|
||||||
|
Loading…
Reference in New Issue
Block a user