Closed theboomer closed 9 years ago
Were you testing in SinglePlayer by chance?
Forge version doesn't match the version sponge was built for
On Jun 17, 2015, at 3:03 AM, theboomer notifications@github.com wrote:
I've written a dummy plugin that subscribes to every event in the api and sends its name to the logger - not programmatically, but explicitly:
I know that most events will trigger multiple ways due to player being a human being a living etc, so I expect to see a lot of events for each action. Some events I have commented out (playerEvent, livingEvent, etc, due to genericness of them and console spam when moving around, OR due to crashing the server on start-up due to missing entirely), just to get an idea of what events are triggered AT THIS TIME for particular actions
What I found shocking is that everything seems to fire each event TWICE, I have posted a file on pastebin showing the output to console/log for various actions -- user types in chat, types a command, logs in, breaks a dirt block, drops from inventory, places a furnace block, places a chest, opens a chest, opens a furnace block... See Pastebin link for these examples: http://pastebin.com/V5xNgPbF
In all cases, every event in the 'chain' logs itself twice in a row, such as for example here =- drag away item from inventory PlayerDropItemEvent PlayerDropItemEvent HumanDropItemEvent HumanDropItemEvent LivingDropItemEvent LivingDropItemEvent EntityDropItemEvent EntityDropItemEvent ItemDropEvent ItemDropEvent
Currently using: Forge forge-1.8-11.14.1.1397-universal.jar Sponge file sponge-1.8-1446-2.1DEV-482.jar maven-repo/dependancies
Doubled behavior was seen with older sponge jars as well.
— Reply to this email directly or view it on GitHub.
Okay, kinda dumb on my part posting the versions and not noticing the mismatch :) However, I just got the 1446 forge version now, deleted the old one, and am using it.
I still get the exact same thing happening with forge-1.8-11.14.3.1446-universal.jar - each event logging twice
And no, not single mode, not IDE-based - pure straight compiled plugin jar put into a stand-alone test server
My entire single-class code is in this pastebin. I would really like to know if I'm hallucinating badly somehow, or if someone else gets the same result. I've triplechecked for somethign stupid like having two different plugin jar names in my mod folder, but all i have is this plugin and the sponge server jar.
You're going to be annoyed because I spotted the problem in 10 seconds.
You call game.getEventManager().register(this, this);
But the plugin main class is already registered on the event bus, so effectively each handler is getting called twice.
Remove that registration, it's needed only for other classes, not the main (@Plugin
) class.
ah, excellent :) Not annoyed at all - relieved.
Shouldn't we prevent multi registration because this is an invalid state?
Hi
I have the same issue and I do not call the service to register the plugin class. As you can see in my code I have worked around the bug with a boolean flag for now. @theboomer did the solution fix your issue?
package com.whippy.sponge.guard.main;
import java.io.IOException;
import org.json.simple.parser.ParseException;
import org.slf4j.Logger;
import org.spongepowered.api.Game;
import org.spongepowered.api.entity.EntityInteractionTypes;
import org.spongepowered.api.event.Subscribe;
import org.spongepowered.api.event.entity.player.PlayerBreakBlockEvent;
import org.spongepowered.api.event.entity.player.PlayerInteractEvent;
import org.spongepowered.api.event.state.ServerStartingEvent;
import org.spongepowered.api.item.inventory.ItemStack;
import org.spongepowered.api.plugin.Plugin;
import org.spongepowered.api.service.command.CommandService;
import org.spongepowered.api.text.Texts;
import org.spongepowered.api.text.format.TextColors;
import com.flowpowered.math.vector.Vector3d;
import com.google.common.base.Optional;
import com.google.inject.Inject;
import com.whippy.sponge.guard.beans.StaticsHandler;
import com.whippy.sponge.guard.beans.WorldLocation;
import com.whippy.sponge.guard.commands.FinaliseCommand;
import com.whippy.sponge.guard.orchestrator.ClickHandler;
@Plugin(id = "WhippyGuard", name = "WhippyGuard")
public class WhippyGuard {
private static final String WAND_ID = "minecraft:bone";
private static final boolean RIGHT_CLICK_BUG=true;
private boolean inRightClick = false;
@Inject
Game game;
@Inject
Logger logger;
@Subscribe
public void onServerStarting(ServerStartingEvent event) throws IOException, ParseException {
StaticsHandler.setClickHandler(new ClickHandler());
StaticsHandler.setGame(game);
StaticsHandler.setLogger(logger);
}
@Subscribe
public void onPreInitializationEvent(ServerStartingEvent event) {
CommandService cmdService = game.getCommandDispatcher();
cmdService.register(this, new FinaliseCommand(), "areaCommit");
}
@Subscribe
public void onPlayerBreakBlockEvent(PlayerBreakBlockEvent event){
}
@Subscribe
public void onPlayerInteractEvent(PlayerInteractEvent event){
Optional<ItemStack> itemInHand = event.getEntity().getItemInHand();
if(itemInHand.isPresent()){
if(itemInHand.get().getItem().getId().equals(WAND_ID)){
if(event.getInteractionType().equals(EntityInteractionTypes.USE)){
if((RIGHT_CLICK_BUG && !inRightClick) || !RIGHT_CLICK_BUG){
inRightClick = true;
if(event.getClickedPosition().isPresent()){
Vector3d vectorPoint = event.getClickedPosition().get();
WorldLocation point = new WorldLocation(event.getPlayer().getWorld().getName(), vectorPoint.getX(), vectorPoint.getY(), vectorPoint.getZ());
StaticsHandler.getClickHandler().playerAreaDefineClick( event.getEntity(), point);
}
}else if (RIGHT_CLICK_BUG){
inRightClick = false;
}
}else if(event.getInteractionType().equals(EntityInteractionTypes.ATTACK)){
event.getEntity().sendMessage(Texts.builder("leftclicked").color(TextColors.RED).build());
}
event.setCancelled(true);
}
}
}
}
@WhippyCleric that is not the same bug afaict, it's a bug with that specific event which I believe is related to Forge. See existing issue here.
Hi
Thanks for the pointer to the correct issue, I will live with my hack for now and just flip the boolean when forge is fixed
I've written a dummy plugin that subscribes to every event in the api and sends its name to the logger - not programmatically, but explicitly:
I know that most events will trigger multiple ways due to player being a human being a living etc, so I expect to see a lot of events for each action. Some events I have commented out (playerEvent, livingEvent, etc, due to genericness of them and console spam when moving around, OR due to crashing the server on start-up due to missing entirely), just to get an idea of what events are triggered AT THIS TIME for particular actions
What I found shocking is that everything seems to fire each event TWICE, I have posted a file on pastebin showing the output to console/log for various actions -- user types in chat, types a command, logs in, breaks a dirt block, drops from inventory, places a furnace block, places a chest, opens a chest, opens a furnace block... See Pastebin link for these examples: http://pastebin.com/V5xNgPbF
In all cases, every event in the 'chain' logs itself twice in a row, such as for example here =- drag away item from inventory PlayerDropItemEvent PlayerDropItemEvent HumanDropItemEvent HumanDropItemEvent LivingDropItemEvent LivingDropItemEvent EntityDropItemEvent EntityDropItemEvent ItemDropEvent ItemDropEvent
Currently using: Forge forge-1.8-11.14.1.1397-universal.jar Sponge file sponge-1.8-1446-2.1DEV-482.jar maven-repo/dependancies
Doubled behavior was seen with older sponge jars as well.