Betonquest: Global tags and points

Created on 21 Dec 2016  路  14Comments  路  Source: BetonQuest/BetonQuest

Just like regular tags, but global - the same for all players.

All 14 comments

It'll be awsome 馃帀

I know this sounds stupid, but one should always keep it simple and stupid ;)
How about misusing the playerdata with "global" as player-id?

It would make this change fairly trivial (adding new conditions/events with a hardcoded playerId), but could possible break some other code.

@Co0sh @Namnodorel @joblo2213
What are you thinking?

Would be easy to use in conditions, but also break all existing (custom) conditions and interfere with the plan to replace player IDs with Player objects.

On the other hand, the player object would be an API change already, so with that we wouldn't break any code. global would have be equivalent to player = null though

Why would it break conditions?

The thought behind it was to just be able to use a Playerdata-Object to store the global points and Tags. A condition would never be checked with a global Playerdata, but it could be used if programmed explicitly.

I will make this clearer when I'm back on my desk

Oh I'm sorry, I first misread what you wrote and then apparently didn't think straight either... Nevermind.

No problem :)
Let's wait what the others have to say.

Okay, so I went through your post three more times, and this is what confused me (I think):

adding new conditions/events with a hardcoded playerId

Could you explain that a little bit more?

/**
 * BetonQuest - advanced quests for Bukkit
 * Copyright (C) 2016  Jakub "Co0sh" Sapalski
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package pl.betoncraft.betonquest.events;

import org.bukkit.scheduler.BukkitRunnable;

import pl.betoncraft.betonquest.BetonQuest;
import pl.betoncraft.betonquest.Instruction;
import pl.betoncraft.betonquest.InstructionParseException;
import pl.betoncraft.betonquest.api.QuestEvent;
import pl.betoncraft.betonquest.database.PlayerData;
import pl.betoncraft.betonquest.utils.PlayerConverter;
import pl.betoncraft.betonquest.utils.Utils;

/**
 * Adds or removes tags from the player
 * 
 * @author Jakub Sapalski
 */
public class GlobalTagEvent extends QuestEvent {

    private final String[] tags;
    private final boolean add;

    public GlobalTagEvent(Instruction instruction) throws InstructionParseException {
        super(instruction);
        persistent = true;
        add = instruction.next().equalsIgnoreCase("add");
        tags = instruction.getArray();
        for (int i = 0; i < tags.length; i++) {
            tags[i] = Utils.addPackage(instruction.getPackage(), tags[i]);
        }
    }

    @Override
    public void run(String playerID) {


                // CHANGE Don't read the tag from the player
                playerID = "global";


        if (PlayerConverter.getPlayer(playerID) != null) {
            PlayerData playerData = BetonQuest.getInstance().getPlayerData(playerID);
            if (add) {
                for (String tag : tags) {
                    playerData.addTag(tag);
                }
            } else {
                for (String tag : tags) {
                    playerData.removeTag(tag);
                }
            }
        } else {
            new BukkitRunnable() {
                @Override
                public void run() {
                    PlayerData playerData = new PlayerData(playerID);
                    if (add) {
                        for (String tag : tags) {
                            playerData.addTag(tag);
                        }
                    } else {
                        for (String tag : tags) {
                            playerData.removeTag(tag);
                        }
                    }
                }
            }.runTaskAsynchronously(BetonQuest.getInstance());
        }
    }
}

like this, instead of reading the tags from the playerId we are getting, we just use the "global" player.
(Search for CHANGE, to find the exact position where I was setting this)

Also note that this is a new Condition "globaltag", the normal "tag" condition is unaffected.

But do we really need an additional event? Wouldn't it be easier to specify an optional "global" argument/flag?

That would be possible to, but I wouldn't find it that intuitiv, but that could be just me being weird^^

And it is planned to make a global argument for objectives, which would add further to the confusion.

In the end I'm happy with everything :)

I am currently working on a possible implementation of this
(see joblo2213/BetonQuest/global-tags-n-points).

The conclusion I came to is that it would be best to have separate sql tables for the global tags and points to prevent any stange db issues.

Also I find it more convinient to have seperate events and conditions for this global tags to have a explcite separation so that beginners don't mix them up.

I'm happy about any comment what is good and what should be tweaked, it's still verry WIP.
@MWFIAE @Namnodorel @Co0sh

Closed in d6839aa.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Defnder picture Defnder  路  5Comments

joblo2213 picture joblo2213  路  3Comments

Wolf2323 picture Wolf2323  路  4Comments

digital-r picture digital-r  路  6Comments

soliddanii picture soliddanii  路  5Comments