#[HELP] Sending Lists Between Classes

1 messages · Page 1 of 1 (latest)

hybrid echo
#

TaggingSystem.java

package me.assailent.infancyminigames.tagging;

import me.assailent.infancyminigames.InfancyMinigames;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import me.assailent.infancyminigames.tagging.TipQueue;

import java.util.List;

public class TaggingSystem implements Listener {
    public TaggingSystem(InfancyMinigames plugin) {
        Bukkit.getPluginManager().registerEvents(this, plugin);
    }

    List<Player> tagList = TipQueue.getPlayerList();
    
    public void onTag(EntityDamageByEntityEvent entityEvent) {
        if (tagList.contains(entityEvent.getDamager())) {

        }
    }
}
#

TipQueue.java

package me.assailent.infancyminigames.tagging;

import me.assailent.infancyminigames.InfancyMinigames;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.*;
import org.bukkit.entity.Player;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class TipQueue {

    private final InfancyMinigames plugin;
    private boolean tipQueueEnabled = false;
    private boolean tipEnabled = false;

    public Player inPlayer;
    private Random random = new Random();
    public TipQueue(InfancyMinigames plugin) {
        this.plugin = plugin;
    }


    int tipQueueTimerVal = 60;
    public void setTimer() {
        tipQueueTimerVal = 60;
    }

    List<Player> playerList = new ArrayList<Player>();

    Location smallMap1 = new Location(Bukkit.getWorld("Minigames"), -83, -60, 29, -180, 0);
    private String tip = (ChatColor.GOLD + "[" + ChatColor.LIGHT_PURPLE + "TIP" + ChatColor.GOLD + "] " + ChatColor.WHITE);

    public void tipQueueTrigger(Player p) {
        if (!tipEnabled & !playerList.contains(p)) {
            playerList.add(p);
            if (playerList.size() == 2) {
                if (!tipQueueEnabled) {
                    tipQueueEnabled = true;
                    setTimer();
                    this.plugin.getServer().getScheduler().runTaskTimer(this.plugin, task -> {
                        tipQueueTimerVal--;
                        if (tipQueueTimerVal <= 0) {
                            startTip();
                        }
                        for (int i = 0; playerList.size() > i; i++) {
                            if (tipQueueTimerVal <= 0) {
                                playerList.get(i).spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(tip + "Game Starting"));
#
                                tipEnabled = true;
                                task.cancel();
                            } else if (tipQueueTimerVal < 15) {
                                this.plugin.getServer().getWorld("Minigames").playSound(playerList.get(i).getLocation(), Sound.BLOCK_NOTE_BLOCK_BANJO, 1, 1);
                                playerList.get(i).spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(tip + tipQueueTimerVal + " Seconds 'Till Game Start"));
                            } else if (tipQueueTimerVal == 30) {
                                this.plugin.getServer().getWorld("Minigames").playSound(playerList.get(i).getLocation(), Sound.BLOCK_NOTE_BLOCK_BANJO, 1, 1);
                            } else {
                                playerList.get(i).spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(tip + tipQueueTimerVal + " Seconds 'Till Game Start"));
                            }
                        }
                    }, 0L, 20L);
                }
            }
#
            p.sendMessage(ChatColor.AQUA + "-----------------------------------------------------");
            p.sendMessage(tip + "Joining a queue for tip!");
            p.sendMessage(tip + "There are " + playerList.size() + " Players in queue for tip!");
            p.sendMessage(tip + "Tip needs atleast 2 players to start!");
            p.sendMessage(ChatColor.AQUA + "-----------------------------------------------------");
            for (int i = 0; playerList.size() > i; i++) {
                if (playerList.get(i) != p) {
                    playerList.get(i).sendMessage(tip + p.getDisplayName() + " Joined the queue for tip!");
                    playerList.get(i).sendMessage(tip + ChatColor.GREEN + playerList.size() + ChatColor.WHITE + " are in queue!");
                }
            }
        } else if (tipEnabled) {
            p.spigot().sendMessage(ChatMessageType.CHAT, new TextComponent(tip + "A game of tip has already started!"));
        } else if (playerList.contains(p)) {
            p.spigot().sendMessage(ChatMessageType.CHAT, new TextComponent(tip + "You've already joined a game of tip!"));
        }
    }
    public void startTip() {
        inPlayer = playerList.get(random.nextInt(playerList.size()));
        for (int i = 0; playerList.size() > i; i++) {
            playerList.get(i).teleport(smallMap1);
            if (playerList.get(i) == inPlayer) {
                playerList.get(i).sendMessage(ChatColor.AQUA + "-----------------------------------------------------");
#
                playerList.get(i).sendMessage(tip + "You are " + ChatColor.RED + "IN! " + ChatColor.WHITE + "Tag other players by hitting them!");
                playerList.get(i).sendMessage(ChatColor.AQUA + "-----------------------------------------------------");
            } else {
                playerList.get(i).sendMessage(ChatColor.AQUA + "-----------------------------------------------------");
                playerList.get(i).sendMessage(tip + "You are " + ChatColor.AQUA + "OUT! " + ChatColor.WHITE + "Don't let the IN Player tip you!");
                playerList.get(i).sendMessage(tip + inPlayer.getDisplayName() + " is in!");
                playerList.get(i).sendMessage(ChatColor.AQUA + "-----------------------------------------------------");
            }
        }
    }

    public List<Player> getPlayerList() {
        return playerList;
    }
}
median elbow
#

?paste

grave belfryBOT
hybrid echo
#

shi mb

#

List im trying to move is known as "tagList" and "playerList"

bleak wren
#

This feels like a learn java moment

hybrid echo
#

yea probably

#

I'm not new to programming its just java really has its quirks

bleak wren
#

You need a TipQueue instance to get a variable or run a method that isn't static

light comet
#

?di

grave belfryBOT
hybrid echo
#

and I barely ever do interclass stuff

bleak wren
hybrid echo
#

I haven't encountered it before or atleast not that I took note of

#

well thats not true

#

If its that i forgot my constructor then yes I do remember that now i just was being dumb