Skip to content

Commit

Permalink
add command '/nu enchantinfo' NyaaCat#9
Browse files Browse the repository at this point in the history
  • Loading branch information
cyilin committed Aug 27, 2016
1 parent a726d23 commit 69aa14f
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 3 deletions.
64 changes: 61 additions & 3 deletions src/main/java/cat/nyaa/nyaautils/CommandHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import cat.nyaa.nyaautils.exhibition.ExhibitionCommands;
import cat.nyaa.utils.*;
import cat.nyaa.utils.internationalizer.I16rEnchantment;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.*;
import org.bukkit.command.CommandSender;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
Expand All @@ -14,6 +12,7 @@
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;

import java.util.Map;
import java.util.Random;

public class CommandHandler extends CommandReceiver<NyaaUtils> {
Expand Down Expand Up @@ -168,8 +167,11 @@ public void commandEnchant(CommandSender sender, Arguments args) {
}
if (success) {
p.sendMessage(I18n._("user.enchant.success"));
p.getWorld().spawnParticle(Particle.ENCHANTMENT_TABLE, p.getEyeLocation(), 300);
p.getWorld().playSound(p.getLocation(), Sound.BLOCK_ENCHANTMENT_TABLE_USE, 1.0F, 1.0F);
} else {
p.sendMessage(I18n._("user.enchant.fail"));
p.getWorld().spawnParticle(Particle.SLIME, p.getEyeLocation(), 200);
if (deleteItem) {
main = new ItemStack(Material.AIR);
}
Expand All @@ -180,6 +182,62 @@ public void commandEnchant(CommandSender sender, Arguments args) {
}
}

@SubCommand(value = "enchantinfo", permission = "nu.enchantinfo")
public void commandEnchantInfo(CommandSender sender, Arguments args) {
Player p = asPlayer(sender);
ItemStack item = getItemInOffHand(sender);

if (!BasicItemMatcher.containsMatch(NyaaUtils.instance.cfg.enchantSrc, item)) {
sender.sendMessage(I18n._("user.enchant.invalid_src"));
return;
}

Map<Enchantment, Integer> enchant;
if (item.getType().equals(Material.ENCHANTED_BOOK)) {
EnchantmentStorageMeta meta = (EnchantmentStorageMeta) item.getItemMeta();
enchant = meta.getStoredEnchants();
} else {
enchant = item.getEnchantments();
}

sender.sendMessage(I18n._("user.enchant.list_ench_header"));
for (Enchantment e : enchant.keySet()) {
if (I16rEnchantment.fromEnchantment(e) != null) {
Message msg = new Message(e.getName() + ": ");
msg.append(I16rEnchantment.fromEnchantment(e).getUnlocalizedName());
msg.append(" " + I18n._("user.enchantinfo.enchant_level", enchant.get(e)));
p.spigot().sendMessage(msg.inner);
} else {
if (e == null || e.getName() == null || e.getName().equalsIgnoreCase("Custom Enchantment")) {
continue;
}
p.sendMessage(e.getName() + ": " + e.getName() + " " +
I18n._("user.enchantinfo.enchant_level", enchant.get(e)));
}
}
long cooldown = 0;
if (plugin.enchantCooldown.containsKey(p.getUniqueId())) {
cooldown = plugin.enchantCooldown.get(p.getUniqueId()) + (plugin.cfg.enchantCooldown / 20 * 1000);
}
float percent;
msg(sender, "user.enchantinfo.info_0");
if (cooldown > System.currentTimeMillis()) {
percent = (plugin.cfg.chanceModerate +
plugin.cfg.chanceFail + plugin.cfg.chanceDestroy) / 100.0F;
msg(sender, "user.enchantinfo.info_1", 0);
} else {
percent = (plugin.cfg.chanceSuccess + plugin.cfg.chanceModerate +
plugin.cfg.chanceFail + plugin.cfg.chanceDestroy) / 100.0F;
msg(sender, "user.enchantinfo.info_1", (int) (plugin.cfg.chanceSuccess / percent));
}
msg(sender, "user.enchantinfo.info_2", (int) (plugin.cfg.chanceModerate / percent));
msg(sender, "user.enchantinfo.info_3", (int) (plugin.cfg.chanceFail / percent));
msg(sender, "user.enchantinfo.info_4", (int) (plugin.cfg.chanceDestroy / percent));
if (cooldown > System.currentTimeMillis()) {
msg(sender, "user.enchantinfo.info_cooldown", (int) ((cooldown - System.currentTimeMillis()) / 1000));
}
}

@SubCommand(value = "show", permission = "nu.show")
public void commandShow(CommandSender sender, Arguments args) {
ItemStack item = getItemInHand(sender);
Expand Down
12 changes: 12 additions & 0 deletions src/main/resources/lang/en_US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ user:
&r&&fn &n underline
&r&&fo &o ltalic
&r&&fr &r reset
enchantinfo:
info_0: "=== Chance ==="
info_1: "Success: %d%%"
info_2: "Moderate: %d%%"
info_3: "Fail: %d%%"
info_4: "Destroy: %d%%"
info_cooldown: "Cooldown: %d seconds remaining "
enchant_level: "Level: %d"
manual:
no_description: "No description"
no_usage: "No usage"
Expand Down Expand Up @@ -153,6 +161,10 @@ manual:
description: "Reset youself suffix"
usage: "/nu resetsuffix"

enchantinfo:
description: "Show enchant info"
usage: "/nu enchantinfo"

exhibition:
description: "Create or modify exhibition items"
usage: "/nu exhibition help"
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,5 @@ permissions:
nu.project:
description: Set player velocity
default: op
nu.enchantinfo:
default: true

0 comments on commit 69aa14f

Please sign in to comment.