From 6e65173ba6d86914c679c26c9151d39b1473e76a Mon Sep 17 00:00:00 2001 From: minenash Date: Sun, 12 Feb 2017 12:01:25 -0500 Subject: [PATCH] Added Naming Module --- src/com/redstoner/misc/Main.java | 2 + src/com/redstoner/modules/naming/Naming.java | 115 +++++++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 src/com/redstoner/modules/naming/Naming.java diff --git a/src/com/redstoner/misc/Main.java b/src/com/redstoner/misc/Main.java index a5691ec..0537798 100644 --- a/src/com/redstoner/misc/Main.java +++ b/src/com/redstoner/misc/Main.java @@ -24,6 +24,7 @@ import com.redstoner.modules.mentio.Mentio; import com.redstoner.modules.misc.Misc; import com.redstoner.modules.motd.Motd; import com.redstoner.modules.nametags.Nametags; +import com.redstoner.modules.naming.Naming; import com.redstoner.modules.pmtoggle.Pmtoggle; import com.redstoner.modules.reports.Reports; import com.redstoner.modules.saylol.Saylol; @@ -70,6 +71,7 @@ public class Main extends JavaPlugin ModuleLoader.addModule(Mentio.class); ModuleLoader.addModule(Misc.class); ModuleLoader.addModule(Motd.class); + ModuleLoader.addModule(Naming.class); ModuleLoader.addModule(Nametags.class); ModuleLoader.addModule(Pmtoggle.class); ModuleLoader.addModule(Reports.class); diff --git a/src/com/redstoner/modules/naming/Naming.java b/src/com/redstoner/modules/naming/Naming.java new file mode 100644 index 0000000..acbc05c --- /dev/null +++ b/src/com/redstoner/modules/naming/Naming.java @@ -0,0 +1,115 @@ +package com.redstoner.modules.naming; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.command.CommandSender; +import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import com.nemez.cmdmgr.Command; +import com.redstoner.misc.Utils; +import com.redstoner.modules.Module; + +import net.md_5.bungee.api.ChatColor; +import net.minecraft.server.v1_11_R1.BlockPosition; +import net.minecraft.server.v1_11_R1.ChatMessage; +import net.minecraft.server.v1_11_R1.ContainerAnvil; +import net.minecraft.server.v1_11_R1.EntityHuman; +import net.minecraft.server.v1_11_R1.EntityPlayer; +import net.minecraft.server.v1_11_R1.PacketPlayOutOpenWindow; + +public class Naming implements Module{ + + boolean enabled = false; + + @Command(hook = "anvil") + public void anvil(CommandSender sender) { + EntityPlayer p = ((CraftPlayer) sender).getHandle(); + AnvilContainer container = new AnvilContainer(p); + int c = p.nextContainerCounter(); + p.playerConnection.sendPacket(new PacketPlayOutOpenWindow(c,"minecraft:anvil",new ChatMessage("Repairing",new Object[]{}),0)); + p.activeContainer = container; + p.activeContainer.windowId = c; + p.activeContainer.addSlotListener(p); + } + + @Command(hook = "name") + public void name(CommandSender sender, String name){ + name = ChatColor.translateAlternateColorCodes('&', name); + ItemStack item = ((Player)sender).getInventory().getItemInMainHand(); + ItemMeta meta = item.getItemMeta(); + meta.setDisplayName(name); + item.setItemMeta(meta); + Utils.sendMessage(sender, null, "Name set to " + name); + } + + @Command(hook = "lore") + public void lore(CommandSender sender, String name){ + List lore = new ArrayList(); + name = ChatColor.translateAlternateColorCodes('&', name); + lore.add(name); + ItemStack item = ((Player)sender).getInventory().getItemInMainHand(); + ItemMeta meta = item.getItemMeta(); + meta.setLore(lore); + item.setItemMeta(meta); + item.getItemMeta().setLore(lore); + Utils.sendMessage(sender, null, "Lore set to " + name); + } + + public class AnvilContainer extends ContainerAnvil { + public AnvilContainer(EntityHuman entity) { + super(entity.inventory, entity.world, new BlockPosition(0, 0, 0), entity); + } + public boolean a(EntityHuman entityhuman) { + return true; + } + } + @Override + public void onEnable() { + enabled = true; + + } + @Override + public void onDisable() { + enabled = false; + } + @Override + public boolean enabled() { + return enabled; + } + + @Override + public String getCommandString() { + // TODO Auto-generated method stub + return "command anvil {\n" + + " [empty] {\n" + + " run anvil;\n" + + " type player;\n" + + " help Opens anvil GUI.;\n" + + " perm utils.anvil;\n" + + " }\n" + + "}\n" + + "\n" + + "command name {\n" + + " [string:name...] {\n" + + " run name name;\n" + + " type player;\n" + + " help Names item in hand.;\n" + + " perm utils.name;\n" + + " }\n" + + "}\n" + + "\n" + + "command lore {\n" + + " [string:name...] {\n" + + " run lore name;\n" + + " type player;\n" + + " help Adds lore to item in hand.;\n" + + " perm utils.lore;\n" + + " }\n" + + "}"; + } + +}