Skip to content

Commit

Permalink
Adding new /od write command
Browse files Browse the repository at this point in the history
This command will output the item's information to a file inside the
OtherDrops plugin folder. It will allow you to easily copy and paste the
item's corrected syntax when wanting to make custom drops.
  • Loading branch information
CoolLord22 committed May 5, 2018
1 parent 5ba18e5 commit 373cd45
Showing 1 changed file with 62 additions and 12 deletions.
74 changes: 62 additions & 12 deletions src/com/gmail/zariust/otherdrops/OtherDropsCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

package com.gmail.zariust.otherdrops;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -43,7 +47,6 @@
import think.rpgitems.item.ItemManager;
import think.rpgitems.item.RPGItem;

import com.gmail.zariust.common.CMEnchantment;
import com.gmail.zariust.common.Verbosity;
import com.gmail.zariust.otherdrops.data.CreatureData;
import com.gmail.zariust.otherdrops.drop.DropResult;
Expand Down Expand Up @@ -72,7 +75,8 @@ private enum OBCommand {
HEROESTEST("heroestest", "ht", ""),
RPGTEST("rpg", "", ""),
DROP("drop", "d,o", "otherdrops.admin.drop"),
TRIGGERS("triggers", "t", "otherdrops.admin.triggers");
TRIGGERS("triggers", "t", "otherdrops.admin.triggers"),
WRITE("write", "wf", "otherdrops.admin.id");

private String cmdName;
private String cmdShort;
Expand Down Expand Up @@ -184,6 +188,9 @@ public boolean onCommand(CommandSender sender, Command command,
case RPGTEST:
cmdRpgTest(sender, args);
break;
case WRITE:
cmdWriteFile(sender);
break;
case TRIGGERS:
String triggers = "";
for (Trigger value : Trigger.values()) {
Expand Down Expand Up @@ -535,16 +542,16 @@ private void cmdId(CommandSender sender, String[] args) {
sender.sendMessage("No living entity found.");
}
} else {
String itemMsg = "Item in hand: " + playerItem.getType()
+ "@" + playerItem.getDurability() + " maxdura:"
+ playerItem.getType().getMaxDurability() + " dura%:"
+ getDurabilityPercentage(playerItem) + " detail: "
+ playerItem.toString();
String itemMsg = playerItem.getType() + "@" + playerItem.getDurability() + " maxdura:" + playerItem.getType().getMaxDurability() +
" dura%:" + getDurabilityPercentage(playerItem) + " detail: " + playerItem.toString();
if (playerItem.getItemMeta() != null && playerItem.getItemMeta().getDisplayName() != null)
itemMsg += " lorename: \"" + playerItem.getItemMeta().getDisplayName().replaceAll(" §", "&") + "\"";
sender.sendMessage(itemMsg);
itemMsg += " name: \"" + playerItem.getItemMeta().getDisplayName().replaceAll(" §", "&") + "\"";

((Player) sender).sendRawMessage(ChatColor.GREEN + "Item in hand: " + ChatColor.WHITE + itemMsg.replaceAll("§", "&"));
sender.sendMessage("");

Block block = player.getTargetBlock(new HashSet<Material>(), 100);
sender.sendMessage("Block looked at is " + block.toString()
((Player) sender).sendRawMessage(ChatColor.GREEN + "Block looked at is " + ChatColor.WHITE + block.toString()
+ " mat: " + block.getType().toString()
+ " lightlevel: " + block.getLightLevel()
+ " lightfromsky: " + block.getLightFromSky()
Expand Down Expand Up @@ -572,13 +579,56 @@ private void cmdId(CommandSender sender, String[] args) {
}
}
}

sender.sendMessage("");
((Player) sender).sendRawMessage(ChatColor.GREEN + "The item config is:§r " + ChatColor.WHITE + itemFinalWriteData.replaceAll("§", "&"));

}
}

private void cmdWriteFile(CommandSender sender) {
if (sender instanceof Player) {
File folder = new File("plugins" + File.separator + "OtherDrops");
BufferedWriter out = null;

Player player = (Player) sender;
ItemStack playerItem = player.getInventory().getItemInMainHand();

String itemFinalWriteData = "";

itemFinalWriteData += playerItem.getType();
itemFinalWriteData += "@" + playerItem.getDurability();
if(!playerItem.getEnchantments().isEmpty()) {
itemFinalWriteData += "!";
for(Enchantment enchInMap : playerItem.getEnchantments().keySet()) {
itemFinalWriteData += enchInMap.getName() + "#" + playerItem.getEnchantmentLevel(enchInMap) + "!";
}
}

if(playerItem.getItemMeta() != null) {
if(playerItem.getItemMeta().getDisplayName() != null) {
itemFinalWriteData += "~" + playerItem.getItemMeta().getDisplayName();
}
if(playerItem.getItemMeta().getLore() != null) {
List<String> loreList = playerItem.getItemMeta().getLore();
for(String loreLine : loreList) {
itemFinalWriteData += ";" + loreLine;
}
}
}

try {
File configFile = new File(folder.getAbsolutePath() + File.separator + "ItemOutput" + ".txt");
configFile.getParentFile().mkdirs();
configFile.createNewFile();
out = new BufferedWriter(new FileWriter(configFile));
out.write(itemFinalWriteData + "\n");
out.close();
} catch (IOException exception) {
exception.printStackTrace();
}

((Player) sender).sendRawMessage(ChatColor.GREEN + "The item config is:§r " + ChatColor.WHITE + itemFinalWriteData.replaceAll("§", "&"));
}
}
/*
* "/od show" command - shows conditions and triggers for the specified
* block
Expand Down

0 comments on commit 373cd45

Please sign in to comment.