aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCow <cow@volloeko.de>2020-06-23 23:33:30 +0200
committerCow <cow@volloeko.de>2020-06-23 23:33:30 +0200
commit4570bbdc873f2c3b0905ca936226118b9a88a7b5 (patch)
treefa302c044a60436bd7adea3cea2bc5daeba19275 /src
parent77735fd8edacd9dc996db8de424f5ee7c73dff77 (diff)
downloadCowlection-4570bbdc873f2c3b0905ca936226118b9a88a7b5.tar.gz
Cowlection-4570bbdc873f2c3b0905ca936226118b9a88a7b5.tar.bz2
Cowlection-4570bbdc873f2c3b0905ca936226118b9a88a7b5.zip
Enhanced auctions' tooltips: price per item
Diffstat (limited to 'src')
-rw-r--r--src/main/java/eu/olli/cowmoonication/config/MooConfig.java5
-rw-r--r--src/main/java/eu/olli/cowmoonication/listener/PlayerListener.java72
-rw-r--r--src/main/resources/assets/cowmoonication/lang/en_US.lang2
3 files changed, 79 insertions, 0 deletions
diff --git a/src/main/java/eu/olli/cowmoonication/config/MooConfig.java b/src/main/java/eu/olli/cowmoonication/config/MooConfig.java
index dd6b462..097f0de 100644
--- a/src/main/java/eu/olli/cowmoonication/config/MooConfig.java
+++ b/src/main/java/eu/olli/cowmoonication/config/MooConfig.java
@@ -38,6 +38,7 @@ public class MooConfig {
public static boolean showBestFriendNotifications;
public static boolean showFriendNotifications;
public static boolean showGuildNotifications;
+ public static boolean showAdvancedTooltips;
public static String[] tabCompletableNamesCommands;
private static String numeralSystem;
// logs search config
@@ -127,6 +128,8 @@ public class MooConfig {
"showFriendNotifications", false, "Set to true to receive friends' login/logout messages, set to false hide them."), true);
Property propShowGuildNotifications = addConfigEntry(cfg.get(Configuration.CATEGORY_CLIENT,
"showGuildNotifications", false, "Set to true to receive guild members' login/logout messages, set to false hide them."), true);
+ Property propShowAdvancedTooltips = addConfigEntry(cfg.get(Configuration.CATEGORY_CLIENT,
+ "showAdvancedTooltips", true, "Set to true to show advanced tooltips, set to false show default tooltips."), true);
Property propNumeralSystem = addConfigEntry(cfg.get(Configuration.CATEGORY_CLIENT,
"numeralSystem", "Arabic numerals: 1, 4, 10", "Use Roman or Arabic numeral system?", new String[]{"Arabic numerals: 1, 4, 10", "Roman numerals: I, IV, X"}), true);
Property propTabCompletableNamesCommands = addConfigEntry(cfg.get(Configuration.CATEGORY_CLIENT,
@@ -158,6 +161,7 @@ public class MooConfig {
showBestFriendNotifications = propShowBestFriendNotifications.getBoolean();
showFriendNotifications = propShowFriendNotifications.getBoolean();
showGuildNotifications = propShowGuildNotifications.getBoolean();
+ showAdvancedTooltips = propShowAdvancedTooltips.getBoolean();
numeralSystem = propNumeralSystem.getString();
tabCompletableNamesCommands = propTabCompletableNamesCommands.getStringList();
moo = propMoo.getString();
@@ -176,6 +180,7 @@ public class MooConfig {
propShowBestFriendNotifications.set(showBestFriendNotifications);
propShowFriendNotifications.set(showFriendNotifications);
propShowGuildNotifications.set(showGuildNotifications);
+ propShowAdvancedTooltips.set(showAdvancedTooltips);
propNumeralSystem.set(numeralSystem);
propTabCompletableNamesCommands.set(tabCompletableNamesCommands);
propMoo.set(moo);
diff --git a/src/main/java/eu/olli/cowmoonication/listener/PlayerListener.java b/src/main/java/eu/olli/cowmoonication/listener/PlayerListener.java
index 9a443b1..12fe6f3 100644
--- a/src/main/java/eu/olli/cowmoonication/listener/PlayerListener.java
+++ b/src/main/java/eu/olli/cowmoonication/listener/PlayerListener.java
@@ -1,15 +1,87 @@
package eu.olli.cowmoonication.listener;
import eu.olli.cowmoonication.Cowmoonication;
+import eu.olli.cowmoonication.config.MooConfig;
import eu.olli.cowmoonication.util.TickDelay;
+import eu.olli.cowmoonication.util.Utils;
+import net.minecraft.init.Blocks;
+import net.minecraft.init.Items;
+import net.minecraft.inventory.ContainerChest;
+import net.minecraft.item.Item;
+import net.minecraft.item.ItemStack;
+import net.minecraft.util.EnumChatFormatting;
+import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.network.FMLNetworkEvent;
+import org.apache.commons.lang3.StringUtils;
+
+import java.text.NumberFormat;
+import java.text.ParseException;
+import java.util.List;
+import java.util.Locale;
public class PlayerListener {
private final Cowmoonication main;
+ private final NumberFormat numberFormatter;
public PlayerListener(Cowmoonication main) {
this.main = main;
+ numberFormatter = NumberFormat.getNumberInstance(Locale.US);
+ numberFormatter.setMaximumFractionDigits(0);
+ }
+
+ @SubscribeEvent
+ public void onItemTooltip(ItemTooltipEvent e) {
+ if (!MooConfig.showAdvancedTooltips) {
+ return;
+ }
+ if (e.entityPlayer.openContainer instanceof ContainerChest) {
+ // for auction house: show price for each item if multiple items are sold at once
+ int stackSize = e.itemStack.stackSize;
+ if ((stackSize == 1 && !isSubmitBidItem(e.itemStack)) || e.toolTip.size() < 4) {
+ // only 1 item or irrelevant tooltip - nothing to do here, abort!
+ return;
+ }
+
+ if (isSubmitBidItem(e.itemStack)) {
+ // special case: "place bid on an item" interface ("Auction View")
+ ItemStack auctionedItem = e.entityPlayer.openContainer.getInventory().get(13);
+ stackSize = auctionedItem.stackSize;
+ if (stackSize == 1) {
+ // still only 1 item, abort!
+ return;
+ }
+ }
+
+ List<String> toolTip = e.toolTip;
+
+ // starting with i=1 because first line is never the one we're looking for
+ for (int i = 1; i < toolTip.size(); i++) {
+ String toolTipLineUnformatted = EnumChatFormatting.getTextWithoutFormattingCodes(toolTip.get(i));
+ if (toolTipLineUnformatted.startsWith("Top bid: ")
+ || toolTipLineUnformatted.startsWith("Starting bid: ")
+ || toolTipLineUnformatted.startsWith("Buy it now: ")
+ || toolTipLineUnformatted.startsWith("Sold for: ")
+ || toolTipLineUnformatted.startsWith("New bid: ") /* special case: 'Submit Bid' item */) {
+
+ try {
+ long price = numberFormatter.parse(StringUtils.substringBetween(toolTipLineUnformatted, ": ", " coins")).longValue();
+ double priceEach = price / (double) stackSize;
+ String formattedPriceEach = priceEach < 5000 ? numberFormatter.format(priceEach) : Utils.formatNumberWithAbbreviations(priceEach);
+ String pricePerItem = EnumChatFormatting.YELLOW + " (" + formattedPriceEach + " each)";
+ toolTip.set(i, toolTip.get(i) + pricePerItem);
+ return;
+ } catch (ParseException ex) {
+ return;
+ }
+ }
+ }
+ }
+ }
+
+ private boolean isSubmitBidItem(ItemStack itemStack) {
+ return (itemStack.getItem().equals(Items.gold_nugget) || itemStack.getItem().equals(Item.getItemFromBlock(Blocks.gold_block)))
+ && (itemStack.hasDisplayName() && (itemStack.getDisplayName().endsWith("Submit Bid") || itemStack.getDisplayName().endsWith("Collect Auction")));
}
@SubscribeEvent
diff --git a/src/main/resources/assets/cowmoonication/lang/en_US.lang b/src/main/resources/assets/cowmoonication/lang/en_US.lang
index b4abb56..3c861fd 100644
--- a/src/main/resources/assets/cowmoonication/lang/en_US.lang
+++ b/src/main/resources/assets/cowmoonication/lang/en_US.lang
@@ -6,6 +6,8 @@ cowmoonication.config.showFriendNotifications=Show friend notifications
cowmoonication.config.showFriendNotifications.tooltip=Set to true to receive friends' login/logout messages, set to false hide them.
cowmoonication.config.showGuildNotifications=Show guild notifications
cowmoonication.config.showGuildNotifications.tooltip=Set to true to receive guild members' login/logout messages, set to false hide them.
+cowmoonication.config.showAdvancedTooltips=Show advanced tooltips
+cowmoonication.config.showAdvancedTooltips.tooltip=Set to true to show advanced tooltips, set to false show default tooltips.
cowmoonication.config.numeralSystem=Numeral system
cowmoonication.config.numeralSystem.tooltip=Use Roman or Arabic numeral system?
cowmoonication.config.tabCompletableNamesCommands=Commands with Tab-completable usernames