ThunderGemios10 / Survival-Games

Survival Games plugin for Spigot - UPDATED for 1.13+
https://www.spigotmc.org/resources/survival-games.17740/
GNU General Public License v3.0
25 stars 22 forks source link

[BUG] Bandages work outside of games #15

Closed PsychoLynx closed 8 years ago

PsychoLynx commented 8 years ago

Hey!

So I found this out by accident that I can right-click a paper when just minding my own business and still get healed 5 hears (and the paper get consumed) even though I'm nowhere near an SG arena, let alone in-game (I'm OP/Admin, so will have to see if this is the case for regular players as well)

So yeah - a fix would be nice - or at least would it be possible to add an option to toggle bandages off (as I have no use for them in my SG setup). Love the plugin - best rendition of the original I've seen thus far!

ThunderGemios10 commented 8 years ago

I'll try to check the code for it.

PsychoLynx commented 8 years ago

Hey! Any update on this yet?

ThunderGemios10 commented 8 years ago

@PsychoLynx Can't find the cause for this. Maybe its WorldEdit?

PsychoLynx commented 8 years ago

Updated Spigot, WorldEdit and SurvivalGames to their latest (dev) versions, still persists on a clean server with nothing else.

Would it be possible just to make a toggle the paper bandage off? (preferably backported to 1.9.4)

ThunderGemios10 commented 8 years ago

@PsychoLynx I think so, Try checking the configurations. There might be an option this this.

PsychoLynx commented 8 years ago

@ThunderGemios10 Well, I looked through all of the config files and didn't find one, hence why I'm asking.

ThunderGemios10 commented 8 years ago

@PsychoLynx Ok. This may be fixed in future updates. But if this really concerns you. You may disable bandages..

PsychoLynx commented 8 years ago

I would indeed love to disable the bandages if I could find the config option to do so! Newest build, fresh install - looked through all the files, nothing related to bandages I could see.

naeruru commented 8 years ago

The bandage class is located here. You could simply add the entire event into an if statement to check if the player is active (aka in game), else return. The easiest way to achieve this is to use isPlayerActive(); from the GameManager class, since it already returns true and false for you.

ThunderGemios10 commented 8 years ago

@Rushnett Thanks for the explanation. I'll get working on bugfixes soon and possibly add a disable option for Bandages.

ThunderGemios10 commented 8 years ago

@PsychoLynx @Rushnett Ok, I made a first attempt at using if statements. You can check the class. It may be incorrect but hey, I'm a new on using if statements.

naeruru commented 8 years ago

Oh, then I can help here. Looking at the current logic, it appears that bandages will always be used, since the if statement you put in doesnt get reached until after the whole bandage method is run through. It also prints your message when you are in an arena, because for some reason (I suppose the original author) made IsPlayerInactive() the exact same as IsPlayerActive() (basically it prints true if they are active, so it made your if statement loop into when someone was in game.

TL;DR: It still eats the papers no matter what, and the if statement you made doesnt stop anything, but loops while in game. Screenshot of what I meant when I tested: test image

Our (my friend and I) fix for when we handle this is the following:

public void onBandageUse(PlayerInteractEvent e) {
   Player p = e.getPlayer();
   Boolean active = GameManager.getInstance().isPlayerActive(p);
   if (!active) {
      return;
   }

   // rest of method here

}

This exits the event always if you arent in an arena.

ThunderGemios10 commented 8 years ago

@Rushnett Thanks again for the explanation. I'll try using your code.

ThunderGemios10 commented 8 years ago

@Rushnett Okay, I pushed the commit, I think it should work now.

naeruru commented 8 years ago

@ThunderGemios10 Yup, just compiled it and tested. Works just how it should.

ThunderGemios10 commented 8 years ago

@Rushnett Ok, Thank you for confirming it. Really appreciate it! You should add your name on the contributors list. on the main class.