Development Assistance Team Teleport

Discussion in 'Plugin Help/Development/Requests' started by WingedMLGPro, Apr 10, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    WingedMLGPro

    Hey guys,
    I am creating a minigame and at the start i want to teleport each team to a random location!
    I am trying to figure this out but it comes up with an error.
    Here is my code:
    Code:
    for (UHCTeam teams : UHCMain.getTeams()) {
                        Player teamMembers = (Player) teams.getMembers();
                        Random r = new Random();
                        Location teleportLoc = null;
                        int x = r.nextInt(1000)+1;
                        int y = 150;
                        int z = r.nextInt(1000)+1;
    
                        boolean onLand = false;
    
                        while (onLand==false){
                            teleportLoc = new Location(teamMembers.getWorld(), x, y, z);
                            if (teleportLoc.getBlock().getType() != Material.AIR){
                                onLand = true;
                            } else y--;
                        }
    If you know plz tell me!
    Thanks.
    WingedMLGPro
     
  2. Offline

    mine-care

    The error?
    use ! operator instead of comparason of booleans.
    i assume get MemberS returns a collection or array so casting will result in a ClassCastException there...
    Assuming that the UHCMain is the main plugin class, Dont abuse static!
     
    ChipDev likes this.
  3. Offline

    WingedMLGPro

    @mine-care Well, how would i get a player instance of UHCMain.getTeams()
     
  4. Offline

    nverdier

    @WingedMLGPro Pass an instance of the main class to the class you want to use the method in.
     
  5. Offline

    WingedMLGPro

    @nverdier what do u mean?? I dont get what u r saying
     
  6. Offline

    nverdier

  7. Offline

    WingedMLGPro

    @nverdier I know Java, I just dont get what u mean and how that will get a Player instance.
     
  8. Offline

    mine-care

    @WingedMLGPro ok, we all got a litle messed here solets try to clear things up.
    Dont use static to acess members of classes, as you know java is an Object Oriented Programing language, Static is used to make a field the same for all the instances of an object. So instead of using static, pass the instance of your main class (in this case UHCMain ) to the rest of the classes like listeners and so on by their constructor.

    May i see UHCMain class?

    umm, As i see, getTeams() returns a collection (or array) of UCHTeam objects, So in your code you cast
    teams.getMembers() (that from the name of it, might return an array or collection of players) to a single player object. You need to handle it as a collection/array....

    May i see UHCTeam class?


    Lastly, don't store Player objects anywhere in your code or if you do handle them properly. They lead to ram leakage D:
     
  9. Offline

    WingedMLGPro

    @mine-care Thanks for being so nice :D
    Here is the UHCMain class:
    Code:
    package me.benkea;
    
    import me.benkea.Commands.ForceStart;
    import me.benkea.Commands.StatsCMD;
    import me.benkea.Commands.TeamCmd;
    import me.benkea.Listeners.*;
    import me.benkea.Teams.*;
    import me.benkea.Util.GameState;
    import me.benkea.Util.StatsConfigManager;
    import me.benkea.Util.TimeManager;
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.block.Block;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import java.io.File;
    import java.util.ArrayList;
    import java.util.List;
    
    /**
    * Created by 35047 on 8/04/15.
    */
    public class UHCMain extends JavaPlugin {
    
        public static StatsConfigManager StatsSettings = StatsConfigManager.getInstance();
    
        public static String Error = "§4§lERROR>> §c";
        public static String DATABASE = "§6§lSwi§e§lfty§6§l>§e§l>§r ";
        public static String CantFindPlayer = "§4§lERROR>> §4Sorry, but we could not find the player ";
        public static String NoCONSOLE = "§4§lERROR>> §4Sorry, But the Console can't run this command!";
        public static String TAG = "§6§lSwi§e§lfty§6§l>§e§l>§r ";
        public static String TAG2 = "§6§l/§e§l/ ";
        public static String SwiftyAnnounment = "§6§lSwi§e§lfty§6§l>§e§l>§r ";
        public static String PermCONSOLE = "§c§l/§4§l/ §cYou are not as cool as a Console, so stop trying to use this command!";
        public static String PermOWNER = "§c§l/§4§l/ §cYou are not as cool as a Owner, so stop trying to use this command!";
        public static String PermHEADADMIN = "§c§l/§4§l/ §cYou are not as cool as a HeadAdmin, so stop trying to use this command!";
        public static String PermAdmin = "§c§l/§4§l/ §cYou are not as cool as a Admin, so stop trying to use this command!";
        public static String PermMOD = "§c§l/§4§l/ §cYou are not as cool as a Mod, so stop trying to use this command!";
        public static String PermVIP = "§c§l/§4§l/ §cYou are not as cool as a VIP, so stop trying to use this command!";
        public static String PermHELPER = "§c§l/§4§l/ §cYou are not as cool as a Helper, so stop trying to use this command!";
        public static String PermIMMORTAL = "§c§l/§4§l/ §cYou are not as cool as a Immortal, so stop trying to use this command!";
        public static String PermLEGEND = "§c§l/§4§l/ §cYou are not as cool as a Legend, so stop trying to use this command!";
        public static String PermELITE = "§c§l/§4§l/ §cYou are not as cool as a Elite, so stop trying to use this command!";
        public static String PermHERO = "§c§l/§4§l/ §cYou are not as cool as a Hero, so stop trying to use this command!";
        public static String PermSergeant = "§c§l/§4§l/ §cYou are not as cool as a Sergeant, so stop trying to use this command!";
    
        private static List<UHCTeam> teams = new ArrayList<UHCTeam>();
        private static int ticks = 0;
        public static int MIN_PLAYERS = 6;
        private static GameState state;
    
        public static GameState getState() {
            return state;
        }
    
        public static void setState(GameState state) {
            UHCMain.state = state;
        }
    
        public static int getTicks() {
            return ticks;
        }
    
        public static void setTicks(int ticks) {
            UHCMain.ticks = ticks;
        }
    
        public static UHCTeam getTeam(Player p) {
            for (UHCTeam team : getTeams()) {
                if (team.getMembers().contains(p.getName())) {
                    return team;
                }
            }
            return null;
        }
    
        public static UHCTeam getTeam(String name) {
    
            for (UHCTeam team : getTeams()) {
                if (team.getName().equalsIgnoreCase(name)) {
                    return team;
                }
            }
    
            return null;
        }
    
        public static List<UHCTeam> getTeams() {
            return teams;
        }
    
        public static UHCMain instance;
    
        public static UHCMain getInstance() {
            return instance;
        }
    
        @Override
        public void onLoad() {
            delDir(new File("world"));
        }
    
        public void regListeners(){
            PluginManager pm = Bukkit.getPluginManager();
            pm.registerEvents(new joinListener(), this);
            pm.registerEvents(new MoveListener(), this);
            pm.registerEvents(new UtilListeners(), this);
            pm.registerEvents(new RegenListener(), this);
            pm.registerEvents(new ChatEvent(), this);
            pm.registerEvents(new StatsEvent(), this);
            pm.registerEvents(new TeamInvListener(), this);
        }
    
        public void regCmd(){
            this.getCommand("team").setExecutor(new TeamCmd());
            this.getCommand("stats").setExecutor(new StatsCMD());
            this.getCommand("ForceStart").setExecutor(new ForceStart());
        }
    
        @Override
        public void onEnable() {
    
            StatsSettings.setup(this);
    
            instance = this;
    
            regListeners();
            regCmd();
    
            state = GameState.STARTING;
    
            teams.add(new Blue());
            teams.add(new Gray());
            teams.add(new Green());
            teams.add(new Orange());
            teams.add(new Purple());
            teams.add(new Red());
            teams.add(new Spectators());
            teams.add(new White());
            teams.add(new Yellow());
    
            Bukkit.getServer().getScheduler().runTaskTimer(this, new TimeManager(), 20L, 20L);
    
        }
    
        @Override
        public void onDisable() {
    
            StatsSettings.saveConfig();
    
            instance = null;
    
        }
    
        public static List<Block> LocBetweenPoints(Location l1, Location l2){
    
            List<Block> blocks = new ArrayList<Block>();
    
            int topBlockX = (l1.getBlockX() < l2.getBlockX() ? l2.getBlockX() : l1.getBlockX());
            int bottomBlockX = l1.getBlockX()  > l2.getBlockX() ? l2.getBlockX() : l1.getBlockX();
    
            int topBlockY = (l1.getBlockY() < l2.getBlockY() ? l2.getBlockY() : l1.getBlockY());
            int bottomBlockY = l1.getBlockY()  > l2.getBlockY() ? l2.getBlockY() : l1.getBlockY();
    
            int topBlockZ = (l1.getBlockZ() < l2.getBlockZ() ? l2.getBlockZ() : l1.getBlockZ());
            int bottomBlockZ = l1.getBlockZ()  > l2.getBlockZ() ? l2.getBlockZ() : l1.getBlockZ();
    
            for (int x = bottomBlockX; x <= topBlockX; x++){
                for (int y = bottomBlockY; y <= topBlockX; y++){
                    for (int z = bottomBlockZ; z <= topBlockZ; z++){
    
                        Block block = l1.getWorld().getBlockAt(x, y, z);
                        blocks.add(block);
    
                    }
                }
            }
    
            return blocks;
        }
    
        public static String formatTime(int seconds){
    
            int hours = seconds/ 3600;
            int remainder = seconds % 3600;
            int mins = remainder / 60;
            int secs = remainder % 60;
    
            if (hours > 0){
                return hours+":"+mins+":"+secs;
            }
            else  if (mins > 0){
                return mins+":"+secs;
            }
            else{
                return String.valueOf(secs);
            }
        }
    
        public static void delDir(File dir) {
    
            if (dir.isDirectory()) {
                String[] children = dir.list();
                for (int i = 0; i < children.length; i++) {
                    delDir(new File(dir, children[i]));
                }
            }
            dir.delete();
        }
    }
    
    And here is the UHCTeam class:

    Code:
    package me.benkea.Teams;
    
    import com.sun.tools.javac.util.List;
    import org.bukkit.ChatColor;
    
    import java.util.ArrayList;
    
    /**
    * Created by 35047 on 8/04/15.
    */
    public interface UHCTeam {
    
        public String getName();
    
        public java.util.List<String> getMembers();
    
        public ChatColor getColour();
    
    }
    
     
  10. Offline

    mine-care

    @WingedMLGPro OH GOD That static! As i said previusly eliminate it! it ruins OOP.

    I think the problem here is obvius :p
    You can pay a look on Bukkit class documentation to find the proper method that turns String (playername) to Player (or OfflinePlayer) Object.
    Also i dont really think this import is needed :) i sugest a cleanup.

    Hopefully that helps.
     
  11. Offline

    WingedMLGPro

    @mine-care OH, can i do List <Player> getMembers(); ????

    @mine-care I GOT IT! TY SO MUCH <3

    @mine-care Actually Jks, lol.
    Here is the error it comes up with now:
    1.04 18:59:32 [Server] INFO at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [spigot-20141113a.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
    11.04 18:59:32 [Server] INFO at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:490) [spigot-20141113a.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
    11.04 18:59:32 [Server] INFO at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:584) [spigot-20141113a.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
    11.04 18:59:32 [Server] INFO at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:289) [spigot-20141113a.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
    11.04 18:59:32 [Server] INFO at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:641) [spigot-20141113a.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
    11.04 18:59:32 [Server] INFO at org.bukkit.craftbukkit.v1_7_R4.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:350) [spigot-20141113a.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
    11.04 18:59:32 [Server] INFO at org.bukkit.craftbukkit.v1_7_R4.scheduler.CraftTask.run(CraftTask.java:71) ~[spigot-20141113a.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
    11.04 18:59:32 [Server] INFO at me.benkea.Util.TimeManager.run(TimeManager.java:65) ~[?:?]
    11.04 18:59:32 [Server] INFO java.lang.ClassCastException: java.util.ArrayList cannot be cast to org.bukkit.entity.Player
    11.04 18:59:32 [Server] WARN Task #36420 for SwiftyUHC v1.0 generated an exception

    Here is my TimeManager:
    Code:
    package me.benkea.Util;
    
    import me.benkea.Teams.UHCTeam;
    import me.benkea.UHCMain;
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.Sound;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.PlayerInventory;
    
    import java.util.Random;
    
    /**
    * Created by 35047 on 8/04/15.
    */
    public class TimeManager implements Runnable {
    
        public int LOBBY_SECONDS= 120;
        public int MIN_PLAYERS = 6;
        public int WARMUP_SECONDS = 30;
    
        @Override
        public void run(){
    
            if (UHCMain.getTicks() > 0){
                UHCMain.setTicks(UHCMain.getTicks()-1);
            }
    
            if (UHCMain.getState()==GameState.STARTING){
                UHCMain.setState(GameState.LOBBY);
            }
    
            if (UHCMain.getState()==GameState.LOBBY){
    
                int online = Bukkit.getServer().getOnlinePlayers().length;
    
                for (Player pl : Bukkit.getOnlinePlayers()){
                    if (UHCMain.getTicks()== 20 || UHCMain.getTicks()== 40 ||UHCMain.getTicks()== 60 ||UHCMain.getTicks()== 80 ||UHCMain.getTicks()== 100 || UHCMain.getTicks()==120){
                        pl.sendMessage(UHCMain.TAG2+"§6UHC begins in "+UHCMain.formatTime(UHCMain.getTicks())+"...");
                        pl.sendMessage(UHCMain.TAG2 + "§6There are " + Bukkit.getOnlinePlayers().length + " players waiting to play UHC!  ");
                    }
                    if (UHCMain.getTeam(pl) == null && UHCMain.getTicks()== 30 || UHCMain.getTeam(pl) == null && UHCMain.getTicks()== 60 ||UHCMain.getTeam(pl) == null && UHCMain.getTicks()== 90) {
                        pl.sendMessage(UHCMain.TAG2 + "§c§lYou are not in a team! §cType /team to select your team!");
                    } else if (UHCMain.getTeam(pl) != null && UHCMain.getTicks()== 30 || UHCMain.getTeam(pl) != null && UHCMain.getTicks()== 60 ||UHCMain.getTeam(pl) != null && UHCMain.getTicks()== 90){
                        pl.sendMessage(UHCMain.TAG2 + "You are in team " + UHCMain.getTeam(pl).getColour() + UHCMain.getTeam(pl).getName());
                    }
                }
                if (UHCMain.getTicks()==0){
                    if (online >= MIN_PLAYERS){
                        UHCMain.setState(GameState.LOADING);
                    }
                    else {
                        UHCMain.setTicks(LOBBY_SECONDS);
                        for (Player pl : Bukkit.getOnlinePlayers()){
                            pl.sendMessage(UHCMain.TAG2+"§4UHC requires "+MIN_PLAYERS+" players to begin!");
                            pl.playSound(pl.getLocation(), Sound.CLICK, 1, 1);
                        }
                    }
                }
            }
            else if (UHCMain.getState()==GameState.LOADING){
                for (Player pl : Bukkit.getOnlinePlayers()){
                    for (UHCTeam teams : UHCMain.getTeams()) {
                        Player teamMembers = (Player) teams.getMembers();
                        Random r = new Random();
                        Location teleportLoc = null;
                        int x = r.nextInt(1000)+1;
                        int y = 150;
                        int z = r.nextInt(1000)+1;
    
                        boolean onLand = false;
    
                        while (onLand==false){
                            teleportLoc = new Location(teamMembers.getWorld(), x, y, z);
                            if (teleportLoc.getBlock().getType() != Material.AIR){
                                onLand = true;
                            } else y--;
                        }
                        teamMembers.teleport(new Location(teamMembers.getWorld(), teleportLoc.getX(), teleportLoc.getBlockY() + 1, teleportLoc.getZ()));
                        Bukkit.broadcastMessage(UHCMain.TAG2+"Teleporting Players...");
                        for (Player all : Bukkit.getOnlinePlayers()) {
                            PlayerInventory pi = all.getInventory();
                            pi.clear();
                            pi.setArmorContents(null);
                            all.setHealth(all.getMaxHealth());
                            all.setFireTicks(0);
                            all.setFoodLevel(20);
                            all.setSaturation(8F);
                            UHCMain.setState(GameState.WARMUP);
                        }
                    }
                }
            }
            else if (UHCMain.getState()==GameState.WARMUP){
    
                int online = Bukkit.getOnlinePlayers().length;
            }
        }
    }
    
    Here is my UHCMain:

    Code:
    package me.benkea;
    
    import me.benkea.Commands.ForceStart;
    import me.benkea.Commands.StatsCMD;
    import me.benkea.Commands.TeamCmd;
    import me.benkea.Listeners.*;
    import me.benkea.Teams.*;
    import me.benkea.Util.GameState;
    import me.benkea.Util.StatsConfigManager;
    import me.benkea.Util.TimeManager;
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.block.Block;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import java.io.File;
    import java.util.ArrayList;
    import java.util.List;
    
    /**
    * Created by 35047 on 8/04/15.
    */
    public class UHCMain extends JavaPlugin {
    
        public static StatsConfigManager StatsSettings = StatsConfigManager.getInstance();
    
        public static String Error = "§4§lERROR>> §c";
        public static String DATABASE = "§6§lSwi§e§lfty§6§l>§e§l>§r ";
        public static String CantFindPlayer = "§4§lERROR>> §4Sorry, but we could not find the player ";
        public static String NoCONSOLE = "§4§lERROR>> §4Sorry, But the Console can't run this command!";
        public static String TAG = "§6§lSwi§e§lfty§6§l>§e§l>§r ";
        public static String TAG2 = "§6§l/§e§l/ ";
        public static String SwiftyAnnounment = "§6§lSwi§e§lfty§6§l>§e§l>§r ";
        public static String PermCONSOLE = "§c§l/§4§l/ §cYou are not as cool as a Console, so stop trying to use this command!";
        public static String PermOWNER = "§c§l/§4§l/ §cYou are not as cool as a Owner, so stop trying to use this command!";
        public static String PermHEADADMIN = "§c§l/§4§l/ §cYou are not as cool as a HeadAdmin, so stop trying to use this command!";
        public static String PermAdmin = "§c§l/§4§l/ §cYou are not as cool as a Admin, so stop trying to use this command!";
        public static String PermMOD = "§c§l/§4§l/ §cYou are not as cool as a Mod, so stop trying to use this command!";
        public static String PermVIP = "§c§l/§4§l/ §cYou are not as cool as a VIP, so stop trying to use this command!";
        public static String PermHELPER = "§c§l/§4§l/ §cYou are not as cool as a Helper, so stop trying to use this command!";
        public static String PermIMMORTAL = "§c§l/§4§l/ §cYou are not as cool as a Immortal, so stop trying to use this command!";
        public static String PermLEGEND = "§c§l/§4§l/ §cYou are not as cool as a Legend, so stop trying to use this command!";
        public static String PermELITE = "§c§l/§4§l/ §cYou are not as cool as a Elite, so stop trying to use this command!";
        public static String PermHERO = "§c§l/§4§l/ §cYou are not as cool as a Hero, so stop trying to use this command!";
        public static String PermSergeant = "§c§l/§4§l/ §cYou are not as cool as a Sergeant, so stop trying to use this command!";
    
        private static List<UHCTeam> teams = new ArrayList<UHCTeam>();
        private static int ticks = 0;
        public static int MIN_PLAYERS = 6;
        private static GameState state;
    
        public static GameState getState() {
            return state;
        }
    
        public static void setState(GameState state) {
            UHCMain.state = state;
        }
    
        public static int getTicks() {
            return ticks;
        }
    
        public static void setTicks(int ticks) {
            UHCMain.ticks = ticks;
        }
    
        public static UHCTeam getTeam(Player p) {
            for (UHCTeam team : getTeams()) {
                if (team.getMembers().contains(p)) {
                    return team;
                }
            }
            return null;
        }
    
        public static UHCTeam getTeam(String name) {
    
            for (UHCTeam team : getTeams()) {
                if (team.getName().equalsIgnoreCase(name)) {
                    return team;
                }
            }
    
            return null;
        }
    
        public static List<UHCTeam> getTeams() {
            return teams;
        }
    
        public static UHCMain instance;
    
        public static UHCMain getInstance() {
            return instance;
        }
    
        @Override
        public void onLoad() {
            delDir(new File("world"));
        }
    
        public void regListeners(){
            PluginManager pm = Bukkit.getPluginManager();
            pm.registerEvents(new joinListener(), this);
            pm.registerEvents(new MoveListener(), this);
            pm.registerEvents(new UtilListeners(), this);
            pm.registerEvents(new RegenListener(), this);
            pm.registerEvents(new ChatEvent(), this);
            pm.registerEvents(new StatsEvent(), this);
            pm.registerEvents(new TeamInvListener(), this);
        }
    
        public void regCmd(){
            this.getCommand("team").setExecutor(new TeamCmd());
            this.getCommand("stats").setExecutor(new StatsCMD());
            this.getCommand("ForceStart").setExecutor(new ForceStart());
        }
    
        @Override
        public void onEnable() {
    
            StatsSettings.setup(this);
    
            instance = this;
    
            regListeners();
    
            regCmd();
    
            state = GameState.STARTING;
    
            teams.add(new Blue());
            teams.add(new Gray());
            teams.add(new Green());
            teams.add(new Orange());
            teams.add(new Purple());
            teams.add(new Red());
            teams.add(new Spectators());
            teams.add(new White());
            teams.add(new Yellow());
    
            Bukkit.getServer().getScheduler().runTaskTimer(this, new TimeManager(), 20L, 20L);
    
        }
    
        @Override
        public void onDisable() {
    
            StatsSettings.saveConfig();
    
            instance = null;
    
        }
    
        public static List<Block> LocBetweenPoints(Location l1, Location l2){
    
            List<Block> blocks = new ArrayList<Block>();
    
            int topBlockX = (l1.getBlockX() < l2.getBlockX() ? l2.getBlockX() : l1.getBlockX());
            int bottomBlockX = l1.getBlockX()  > l2.getBlockX() ? l2.getBlockX() : l1.getBlockX();
    
            int topBlockY = (l1.getBlockY() < l2.getBlockY() ? l2.getBlockY() : l1.getBlockY());
            int bottomBlockY = l1.getBlockY()  > l2.getBlockY() ? l2.getBlockY() : l1.getBlockY();
    
            int topBlockZ = (l1.getBlockZ() < l2.getBlockZ() ? l2.getBlockZ() : l1.getBlockZ());
            int bottomBlockZ = l1.getBlockZ()  > l2.getBlockZ() ? l2.getBlockZ() : l1.getBlockZ();
    
            for (int x = bottomBlockX; x <= topBlockX; x++){
                for (int y = bottomBlockY; y <= topBlockX; y++){
                    for (int z = bottomBlockZ; z <= topBlockZ; z++){
    
                        Block block = l1.getWorld().getBlockAt(x, y, z);
                        blocks.add(block);
    
                    }
                }
            }
    
            return blocks;
        }
    
        public static String formatTime(int seconds){
    
            int hours = seconds/ 3600;
            int remainder = seconds % 3600;
            int mins = remainder / 60;
            int secs = remainder % 60;
    
            if (hours > 0){
                return hours+":"+mins+":"+secs;
            }
            else  if (mins > 0){
                return mins+":"+secs;
            }
            else{
                return String.valueOf(secs);
            }
        }
    
        public static void delDir(File dir) {
    
            if (dir.isDirectory()) {
                String[] children = dir.list();
                for (int i = 0; i < children.length; i++) {
                    delDir(new File(dir, children[i]));
                }
            }
            dir.delete();
        }
    }
    
    And here is my UHCTeam:

    Code:
    package me.benkea.Teams;
    
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    
    import java.util.List;
    
    /**
    * Created by 35047 on 8/04/15.
    */
    public interface UHCTeam {
    
        public String getName();
    
        public List<Player> getMembers();
    
        public ChatColor getColour();
    
    }
    
    EDIT by Timtower: merged posts
     
    Last edited by a moderator: Apr 12, 2015
  12. Offline

    mine-care

    Casting!!! Read and you will find the solution way better than I would explain :- )
     
  13. Offline

    WingedMLGPro

    @mine-care
    well how do i make an ArrayList if it cant be casted to a Player and i need a Player instance!
     
  14. Offline

    mine-care

    @WingedMLGPro
    imagine a list as a table,

    o : Player1
    1 : Player2
    2 : Player3

    so you cannot cast X players to one player object, You will need to loop through them as you did with teams with a for/each loop or any other of your choise
     
  15. Offline

    dylzqn

    I have no clue as I am with this project lawl :D
     
  16. Offline

    WingedMLGPro

    @mine-care so would i do something like
    List<Player> teamMembers = teams.getMembers();
    and then somehow get a instance of that??
     
  17. Offline

    mine-care

  18. Offline

    WingedMLGPro

    @mine-care alright, i have read it, and i get it but how will i do that with a player instance because a player instance is just one person! And i dont think there is a nother way u can telerport someone without a player instance.
     
  19. Offline

    WingedMLGPro

  20. Offline

    mine-care

  21. Offline

    WingedMLGPro

  22. Offline

    mine-care

  23. Offline

    WingedMLGPro

  24. Offline

    nverdier

  25. Offline

    WingedMLGPro

    @mine-care would i do UHCTeam team = UHCMain.getTeams.getMembers();
    and then for (int i = 0; i < team.length; i++){
    Player teams = (Player)//somethinghere[ i ]
    }

    lol, i can use any of them

    EDIT by Timtower: merged posts
     
    Last edited by a moderator: Apr 15, 2015
  26. Offline

    mine-care

    @WingedMLGPro Any loop would do,
    Also getMembers() returs a list of player (NOT RECOMENDED!) and so you cannot assign a UHCTeam object to a List of Players!? thats not gonna heppend.
    Please revise your java a litle bit focusing on objects.
     
  27. Offline

    WingedMLGPro

    @mine-care dont worry about this anymore, sorry. im making a GameAPI with my own teams atm!
     
  28. Offline

    mine-care

    @WingedMLGPro Well still it is a good idea to take a litle revision :) it never hurt anyone :D
     
  29. Offline

    WingedMLGPro

  30. Offline

    Corndogoz

    well, here is what i would do:
    Code:
    for (Player p:teams.getMembers()){
    //do something with that player
    }
    basicly what this does is get number 1 on the list and set it has player p, do something, and then get number 2, then 3, then 4 and so on
     
Thread Status:
Not open for further replies.

Share This Page