/*
 * This file is part of TackleBox, licensed under the MIT License (MIT).
 *
 * Copyright (c) InspireNXE <http://github.com/InspireNXE/>
 * Copyright (c) contributors
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package org.inspirenxe.tacklebox;

import org.spongepowered.api.data.Transaction;
import org.spongepowered.api.data.key.Keys;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.action.FishingEvent;
import org.spongepowered.api.item.inventory.ItemStackSnapshot;
import org.spongepowered.api.plugin.Plugin;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.Texts;

import java.util.Optional;

@Plugin(id = "tacklebox", name = "TackleBox")
public class TackleBox {

    @Listener
    public void onFishingStop(FishingEvent.Stop event) {
        final Optional<Player> player = event.getCause().first(Player.class);
        if (!player.isPresent()) return;

        final Transaction<ItemStackSnapshot> transaction = event.getItemStackTransaction();
        if (!transaction.isValid()) return;

        final Text text = transaction.getFinal().get(Keys.DISPLAY_NAME).get();

        player.get().sendMessage(Texts.of("You reeled in ",
                !text.toString().endsWith("s") ? "a " : "",
                text));
    }
}

@@ -1526,16 +1526,61 @@
 gEvent;%0A
+import org.spongepowered.api.item.ItemTypes;%0A
 import o
@@ -1760,16 +1760,41 @@
 Texts;%0A%0A
+import java.util.Locale;%0A
 import j
@@ -2180,17 +2180,16 @@
     if (
-!
 transact
@@ -2196,16 +2196,50 @@
 ion.
-isValid(
+getFinal().getType().equals(ItemTypes.NONE
 )) r
@@ -2272,16 +2272,25 @@
  text = 
+Texts.of(
 transact
@@ -2311,33 +2311,38 @@
 .get
-(Keys.DISPLAY_NAME
+Type().getTranslation(
 ).get()
+)
 ;%0A%0A 
@@ -2402,92 +2402,596 @@
 in %22
-,
+), format(text));
 %0A    
+%7D%0A%0A
     
-        !t
+private Text format(Text text) %7B%0A        String plain = T
 ext
+s
 .to
-String().endsWith(%22s%22) ?
+Plain(text);%0A        if (!plain.endsWith(%22s%22)) %7B%0A            if (startsWithAny(plain, %22a%22, %22e%22, %22i%22, %22o%22, %22u%22)) %7B%0A                plain =
  %22a
+n
  %22 
-: %22%22,%0A                text))
++ plain;%0A            %7D else %7B%0A                plain = %22a %22 + plain;%0A            %7D%0A        %7D%0A        return Texts.of(plain);%0A    %7D%0A%0A    private boolean startsWithAny(String text, String... values) %7B%0A        for (String value : values) %7B%0A            if (text.startsWith(value)) %7B%0A                return true;%0A            %7D%0A        %7D%0A        return false
 ;%0A  

Improve name handling