/*
 * This file is part of Sponge, licensed under the MIT License (MIT).
 *
 * Copyright (c) SpongePowered <https://www.spongepowered.org>
 * 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.spongepowered.test;

import org.spongepowered.api.Sponge;
import org.spongepowered.api.command.CommandResult;
import org.spongepowered.api.command.args.GenericArguments;
import org.spongepowered.api.command.spec.CommandSpec;
import org.spongepowered.api.data.key.Keys;
import org.spongepowered.api.data.type.ParrotVariant;
import org.spongepowered.api.entity.Entity;
import org.spongepowered.api.entity.EntityTypes;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.entity.InteractEntityEvent;
import org.spongepowered.api.event.filter.cause.Root;
import org.spongepowered.api.event.game.state.GamePreInitializationEvent;
import org.spongepowered.api.plugin.Plugin;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.format.TextColors;

@Plugin(id = "parrotdatatest", name = "Parrot Data Test", description = "A plugin to test parrot data.", version = "0.0.0")
public class ParrotDataTest {

    private ParrotVariant parrotVariant;

    @Listener
    public void onGamePreInitialization(GamePreInitializationEvent event) {
        Sponge.getCommandManager().register(this,
                CommandSpec.builder()
                        .arguments(GenericArguments.onlyOne(GenericArguments.catalogedElement(Text.of("parrot variant"), ParrotVariant.class)))
                        .executor((src, args) -> {
                            this.parrotVariant = args.<ParrotVariant>getOne("parrot variant").get();

                            src.sendMessage(Text.of(TextColors.DARK_GREEN, "Click a parrot to change their variant to: ",
                                    TextColors.GRAY, this.parrotVariant.getName()));

                            return CommandResult.success();
                        })
                        .build(),
                "parrottest");
    }

    @Listener
    public void onEntityInteract(InteractEntityEvent event, @Root Player player) {
        final Entity entity = event.getTargetEntity();
        if (entity.getType().equals(EntityTypes.PARROT) && this.parrotVariant != null) {
            entity.offer(Keys.PARROT_VARIANT, this.parrotVariant);
            player.sendMessage(Text.of(TextColors.GOLD, "The selected parrot has been turned to the variant: ",
                    TextColors.GRAY, this.parrotVariant.getName()));
            this.parrotVariant = null;
        }
    }

}

@@ -1274,16 +1274,49 @@
 .test;%0A%0A
+import com.google.inject.Inject;%0A
 import o
@@ -1396,16 +1396,68 @@
 Result;%0A
+import org.spongepowered.api.command.CommandSource;%0A
 import o
@@ -2092,16 +2092,69 @@
 Plugin;%0A
+import org.spongepowered.api.plugin.PluginContainer;%0A
 import o
@@ -2395,50 +2395,167 @@
 est 
-%7B%0A%0A    private ParrotVariant parrotVariant
+implements LoadableModule %7B%0A%0A    @Inject private PluginContainer container;%0A%0A    private final ParrotDataEventListener listener = new ParrotDataEventListener()
 ;%0A%0A 
@@ -2951,33 +2951,45 @@
            this.
-p
+listener.setP
 arrotVariant = a
@@ -2984,19 +2984,17 @@
 tVariant
- = 
+(
 args.%3CPa
@@ -3035,16 +3035,17 @@
 %22).get()
+)
 ;%0A%0A     
@@ -3211,33 +3211,45 @@
 lors.GRAY, this.
-p
+listener.getP
 arrotVariant.get
@@ -3236,32 +3236,34 @@
 getParrotVariant
+()
 .getName()));%0A%0A 
@@ -3421,33 +3421,286 @@
     %7D%0A%0A    @
-Listener%0A
+Override%0A    public void enable(CommandSource src) %7B%0A        Sponge.getEventManager().registerListeners(this.container, this.listener);%0A    %7D%0A%0A    public static class ParrotDataEventListener %7B%0A%0A        private ParrotVariant parrotVariant;%0A%0A        @Listener%0A    
     public v
@@ -3778,16 +3778,20 @@
         
+    
 final En
@@ -3837,16 +3837,20 @@
         
+  
+  
 if (enti
@@ -3934,16 +3934,20 @@
         
+    
 entity.o
@@ -4005,16 +4005,20 @@
         
+   
+ 
 player.s
@@ -4121,32 +4121,36 @@
                 
+    
 TextColors.GRAY,
@@ -4190,24 +4190,28 @@
             
+   
+ 
 this.parrotV
@@ -4225,16 +4225,257 @@
 = null;%0A
+            %7D%0A        %7D%0A%0A        public ParrotVariant getParrotVariant() %7B%0A            return this.parrotVariant;%0A        %7D%0A%0A        public void setParrotVariant(ParrotVariant parrotVariant) %7B%0A            this.parrotVariant = parrotVariant;%0A
         

Fix ParrotDataTest disabling some ShouldFire flags (#2652)