From da78feeab0e2af3c0f7f382eb79fa6f01d9fc7d2 Mon Sep 17 00:00:00 2001 From: Desco1 Date: Tue, 18 Aug 2020 19:28:20 +0200 Subject: Added clipboard as a parameter for the getkey command --- .../java/me/Danker/commands/GetkeyCommand.java | 29 ++++++++++++++++------ 1 file changed, 21 insertions(+), 8 deletions(-) (limited to 'src/main/java/me/Danker/commands/GetkeyCommand.java') diff --git a/src/main/java/me/Danker/commands/GetkeyCommand.java b/src/main/java/me/Danker/commands/GetkeyCommand.java index 80354fe..d32a56e 100644 --- a/src/main/java/me/Danker/commands/GetkeyCommand.java +++ b/src/main/java/me/Danker/commands/GetkeyCommand.java @@ -1,5 +1,9 @@ package me.Danker.commands; +import java.awt.Toolkit; +import java.awt.datatransfer.Clipboard; +import java.awt.datatransfer.StringSelection; + import me.Danker.handlers.ConfigHandler; import net.minecraft.command.CommandBase; import net.minecraft.command.CommandException; @@ -28,14 +32,23 @@ public class GetkeyCommand extends CommandBase implements ICommand { @Override public void processCommand(ICommandSender arg0, String[] arg1) throws CommandException { - final EntityPlayer player = (EntityPlayer)arg0; - final ConfigHandler cf = new ConfigHandler(); - - if (cf.getString("api", "APIKey").equals("")) { - player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "API key not set. Set your API key using /setkey.")); - } else { - player.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN + "Your set API key is " + EnumChatFormatting.DARK_GREEN + cf.getString("api", "APIKey"))); - } + EntityPlayer player = (EntityPlayer)arg0; + ConfigHandler cf = new ConfigHandler(); + Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); + StringSelection stringSelection = new StringSelection(cf.getString("api", "APIKey")); + + if (cf.getString("api", "APIKey").equals("")) { + player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "API key not set. Set your API key using /setkey.")); + } + else if (arg1.length == 0) { + player.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN + "Your set API key is " + EnumChatFormatting.DARK_GREEN + cf.getString("api", "APIKey"))); + } else if (arg1[0].equalsIgnoreCase("clipboard")){ + clipboard.setContents(stringSelection, null); + player.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN + "Your set API key has been copied to the clipboard.")); + } else { + player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Wrong command usage: /getkey (clipboard)")); + } + } } -- cgit From 7d56e9f24622cc16b60c1e23c1affcb809bd6772 Mon Sep 17 00:00:00 2001 From: bowser0000 Date: Tue, 18 Aug 2020 19:00:43 -0400 Subject: Remove mandatory parameter from /getkey No reason to have a parameter if you can't not have a parameter. --- src/main/java/me/Danker/commands/DHelpCommand.java | 2 +- src/main/java/me/Danker/commands/GetkeyCommand.java | 12 ++++-------- 2 files changed, 5 insertions(+), 9 deletions(-) (limited to 'src/main/java/me/Danker/commands/GetkeyCommand.java') diff --git a/src/main/java/me/Danker/commands/DHelpCommand.java b/src/main/java/me/Danker/commands/DHelpCommand.java index a2efa94..cd08a14 100644 --- a/src/main/java/me/Danker/commands/DHelpCommand.java +++ b/src/main/java/me/Danker/commands/DHelpCommand.java @@ -34,7 +34,7 @@ public class DHelpCommand extends CommandBase { EnumChatFormatting.GOLD + " /dhelp" + EnumChatFormatting.AQUA + " - Returns this message.\n" + EnumChatFormatting.GOLD + " /toggle " + EnumChatFormatting.AQUA + " - Toggles features. /toggle list returns values of every toggle.\n" + EnumChatFormatting.GOLD + " /setkey " + EnumChatFormatting.AQUA + " - Sets API key.\n" + - EnumChatFormatting.GOLD + " /getkey [clipboard]" + EnumChatFormatting.AQUA + " - Returns key set with /setkey.\n" + + EnumChatFormatting.GOLD + " /getkey" + EnumChatFormatting.AQUA + " - Returns key set with /setkey and copies it to your clipboard.\n" + EnumChatFormatting.GOLD + " /loot [winter/f(1-4)/session]" + EnumChatFormatting.AQUA + " - Returns loot received from slayer quests or fishing stats. /loot fishing winter returns winter sea creatures instead.\n" + EnumChatFormatting.GOLD + " /display [winter/f(1-4)/session]" + EnumChatFormatting.AQUA + " - Text display for trackers. /display fishing winter displays winter sea creatures instead.\n" + EnumChatFormatting.GOLD + " /resetloot " + EnumChatFormatting.AQUA + " - Resets loot for trackers. /resetloot confirm confirms the reset.\n" + diff --git a/src/main/java/me/Danker/commands/GetkeyCommand.java b/src/main/java/me/Danker/commands/GetkeyCommand.java index d32a56e..f06e66f 100644 --- a/src/main/java/me/Danker/commands/GetkeyCommand.java +++ b/src/main/java/me/Danker/commands/GetkeyCommand.java @@ -40,14 +40,10 @@ public class GetkeyCommand extends CommandBase implements ICommand { if (cf.getString("api", "APIKey").equals("")) { player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "API key not set. Set your API key using /setkey.")); } - else if (arg1.length == 0) { - player.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN + "Your set API key is " + EnumChatFormatting.DARK_GREEN + cf.getString("api", "APIKey"))); - } else if (arg1[0].equalsIgnoreCase("clipboard")){ - clipboard.setContents(stringSelection, null); - player.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN + "Your set API key has been copied to the clipboard.")); - } else { - player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Wrong command usage: /getkey (clipboard)")); - } + + clipboard.setContents(stringSelection, null); + player.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN + "Your set API key is " + EnumChatFormatting.DARK_GREEN + cf.getString("api", "APIKey") + "\n" + + EnumChatFormatting.GREEN + "Your set API key has been copied to the clipboard.")); } -- cgit