Jump to content

[1.8][UNSOLVED] Scoreboard


Jacky2611

Recommended Posts

Hi!

 

I am just writing the last part of a minigame-server project and need a way to access the Scoreboard.

I know that I can use world.getScoreboard() to get the scoreboard, but now i am a little bit stuck.

 

I tried to use

.func_96516_a("adsasdasd");

to add a title to my scoreboard, but when i tested it nothing happened.

(Player joined after scoreboard was created)

 

So how would I set the title correctly? Or do I have to send my scoreboard to the player/add my player to the scoreboard?

 

Jacky

Here could be your advertisement!

Link to comment
Share on other sites

There is some method called "addScoreObjective", you might want that.

 

In case it is not deobfed in 1.8 (I found it on 1.7.10),

  it has two parameters : String, IScoreObjectiveCriteria, and it returns ScoreObjective.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to comment
Share on other sites

The problem is that the player doesn't even display stuff such as the teams color.

 

To create the teams I use:

	for(int i=0; i<teamNumber;i++){
		//scoreboard.createTeam(i+"");
		ScorePlayerTeam team = new ScorePlayerTeam(scoreboard,i+"");
		team.setTeamName(EnumTeam.values()[i].toString());
		team.func_178774_a(EnumTeam.values()[i].getChatColor());
		team.setNamePrefix("TEST");
		scoreboard.sendTeamUpdate(team);
	}

once the dim is generated.

 

And then I want to use:

		    		player.worldObj.getScoreboard().addPlayerToTeam(player.getName(), (i+""));

 

To add my player to the team. Problem is: nothing happens. No name suffix, no color, ...

 

According to a bukkit tut here I have to set the players scoreboard somehow, but I have no idea how I should do this.

 

I found

	player.setScore(int x);

 

But this requires an int for the data watcher, and I don't know how I can get the scoreboards id.

 

 

I will try to find some more information in the scoreboard command, but it would be awesome if someone could help me here.

Here could be your advertisement!

Link to comment
Share on other sites

In my main class:

 

 

...
    @EventHandler
    public void preInit(FMLPreInitializationEvent event)
    {
    	if(!baseFolder.exists()){
    		baseFolder.mkdir();
    	}
    	
	DimensionManager.registerProviderType(providerTypeSkyBattle, WorldProviderSkyBattle.class, true);

    	RegisterDimensions.register(true);

    	
    }

...

    @EventHandler
    public void serverStarted(FMLServerStartedEvent event){
    	RegisterDimensions.register(false);
    }

 

 

 

RegisterDimensionClass:

 

 

 

public class RegisterDimensions {

public static void register(boolean preInit){

	//SKYBATTLE
	for(int i=BlackGeckoServer.firstSkyBattleServer;i<25;i++){
		if(preInit){
			DimensionManager.registerDimension(i, BlackGeckoServer.providerTypeSkyBattle);
		} else {
			BlackGeckoServer.gameServer.put(i, new SkyBattle(i));
		}
	}





}

}

 

 

 

my Skybattle class:

 

 

public class SkyBattle extends GameMode{

public int teamNumber;

public int playerPerTeam;

public List[] teams ={new ArrayList<EntityPlayer>(),new ArrayList<EntityPlayer>(),new ArrayList<EntityPlayer>(),new ArrayList<EntityPlayer>(),new ArrayList<EntityPlayer>(),new ArrayList<EntityPlayer>(),new ArrayList<EntityPlayer>(),new ArrayList<EntityPlayer>()};



public SkyBattle(int i) {
	this(i,1, 1,1);
}


public SkyBattle(int dim, int map, int teams, int playersPerTeam) {

	this.dim=dim;
	this.map=map;
	this.teamNumber=teams;
	this.playerPerTeam=playersPerTeam;
	this.state=EnumGameState.RESTARTING;

	this.resetWorld(EnumGameMode.SKY_BATTLE, this.map, this.dim);

	this.createScoreboard();



}

public void createScoreboard(){
	Scoreboard scoreboard = MinecraftServer.getServer().worldServerForDimension(this.dim).getScoreboard();

	for(int i=0; i<teamNumber;i++){
		//scoreboard.createTeam(i+"");
		ScorePlayerTeam team = new ScorePlayerTeam(scoreboard,i+"");
		team.setTeamName(EnumTeam.values()[i].toString());
		team.func_178774_a(EnumTeam.values()[i].getChatColor());
		team.setNamePrefix("TEST");
		scoreboard.sendTeamUpdate(team);
	}
}


@Override
public void joinPlayer(EntityPlayer player){
	boolean alreadyOnline=false;


	player.setCustomNameTag("asdasdasd");


	for(EntityPlayer player1 : this.players){
		if(player1 == player)
			alreadyOnline=true;
	}
	if(!alreadyOnline){
		this.players.add(player);
	}

	if(this.players.size()>=this.playerPerTeam*this.teamNumber){
		for (EntityPlayer player1 : this.players) {
		    player1.addChatComponentMessage(new ChatComponentText("The game has started."));
		    this.countdown();
		}
	}
}

@Override
public void disconnectPlayer(EntityPlayer player){
	players.remove(player);
    for(int i=0;i<this.teams.length;i++){
    	if(this.teams[i].contains(player))
    		this.teams[i].remove(player);
    }
   
}

public void joinTeam(EntityPlayer player, EnumTeam team){
	if(team.ordinal()<this.teamNumber){

			if(teams[team.ordinal()].contains(player)){

				teams[team.ordinal()].remove(player);

				player.addChatComponentMessage(new ChatComponentText("You left Team " + team.toString()));
			} else {
					if(teams[team.ordinal()].size()<this.playerPerTeam){

						for(int i=0; i<teams.length;i++){
							if(teams[i].contains(player)){
								teams[i].remove(player);
							}
						}

						teams[team.ordinal()].add(player);	


						player.addChatComponentMessage(new ChatComponentText(team.getChatColor() + "You joined team " + team.toString() + "."));
						player.setCustomNameTag(team.getChatColor()+player.getName());

					} else {
						player.addChatComponentMessage(new ChatComponentText("This team is already full."));
					}


				}

	} else {
		player.addChatComponentMessage(new ChatComponentText(EnumChatFormatting.DARK_RED+"The team you were about to join does not exist."));
	}
}

public void autojoinTeam(){
	for (EntityPlayer player : this.players) {
	    boolean isInTeam=false;
	    
	    for(int i=0;i<this.teams.length;i++){
	    	if(this.teams[i].contains(player))
	    		isInTeam=true;
	    }
	    
	    if(!isInTeam){
		    for(int i=0;i<this.teams.length;i++){
		    	if(this.teams[i].size()<this.playerPerTeam){
		    		this.teams[i].add(player);
		    		
		    		
		    		
					player.addChatComponentMessage(new ChatComponentText(EnumTeam.values()[i].getChatColor() + "You joined team " + EnumTeam.values()[i].toString() + "."));
					player.setCustomNameTag(EnumTeam.values()[i].getChatColor().toString() +player.getName());


					Scoreboard scoreboard = MinecraftServer.getServer().worldServerForDimension(this.dim).getScoreboard();


					scoreboard.addPlayerToTeam(player.getName(), (i+""));
					scoreboard.addPlayerToTeam(player.getName(), EnumTeam.values()[i].toString());
		    		
		    		//System.out.println(player.worldObj.getScoreboard().getTeam(i+"").);
		    		
		    		break;
		    	}
		    }
	    }



	}
}

@Override
public void start(){
	this.autojoinTeam();

	for(EntityPlayer player : players){
		DisplayTitle.sendTitle(player, S45PacketTitle.Type.TITLE, new ChatComponentText("SKY BATTLE")); //MOVE TO GAME MODE CLASS IN NEW FUNCTION!!!!
	}

	this.messageToAllPlayers(new ChatComponentText(EnumChatFormatting.AQUA +"The game has started!"));

	this.messageToAllPlayers(new ChatComponentText(EnumChatFormatting.WHITE +"As long as your beacon is not destroyed you can respawn at you base."));
	this.messageToAllPlayers(new ChatComponentText(EnumChatFormatting.WHITE +"Try to destroy the enemies beacon to win."));


}


}

 

 

 

 

Btw, for everyone who is creating something similar, I wrote a class to display a title. Its not perfect but it works:

 

 

 

public class DisplayTitle {

public static boolean sendTitle(EntityPlayer player, S45PacketTitle.Type type){
	if (type != S45PacketTitle.Type.CLEAR && type != S45PacketTitle.Type.RESET){
		return false;
	} else {
		return sendTitle(player, type, null);
	}
}


public static boolean sendTitle(EntityPlayer player, S45PacketTitle.Type type, ChatComponentText message){
	return sendTitle(player, type, message, 1, 5, 1);
}


public static boolean sendTitle(EntityPlayer player, S45PacketTitle.Type type, ChatComponentText message, int fadeIn, int stay, int fadeOut){
	EntityPlayerMP entityplayermp =(EntityPlayerMP) player;

	ICommandSender commandSender = MinecraftServer.getServer();


	if (type != S45PacketTitle.Type.CLEAR && type != S45PacketTitle.Type.RESET){

		S45PacketTitle s45packettitle1;
		try {
			s45packettitle1 = new S45PacketTitle(type, ChatComponentProcessor.func_179985_a(commandSender, message, player));
		    entityplayermp.playerNetServerHandler.sendPacket(s45packettitle1);
		    return true;
		} catch (CommandException e) {
			// TODO Auto-generated catch block
			return false;
		}
	    
	} else {
        S45PacketTitle s45packettitle = new S45PacketTitle(type, (IChatComponent)null);
        entityplayermp.playerNetServerHandler.sendPacket(s45packettitle);	
        return true;
}
}
}

 

 

Here could be your advertisement!

Link to comment
Share on other sites

You should get team from Scoreboard class, via Scoreboard#createTeam(String).

  (In case it wasn't deobfuscated in 1.8, the method returns ScorePlayerTeam)

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to comment
Share on other sites

oh, looks like my player actually joined my team, but the nametag color was never changed....

I am using

team.func_178774_a(EnumChatFormatting.RED);

But nothing really changes. Any ideas why?

 

Here is my latest SkyBattle class.

 

 

package com.blackgeckogames.server.mod.minigames.skybattle;

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

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.network.play.server.S45PacketTitle;
import net.minecraft.scoreboard.ScorePlayerTeam;
import net.minecraft.scoreboard.Scoreboard;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.world.World;
import net.minecraftforge.common.DimensionManager;

import com.blackgeckogames.server.mod.minigames.GameMode;
import com.blackgeckogames.server.mod.utilities.DisplayTitle;

public class SkyBattle extends GameMode{

public int teamNumber;

public int playerPerTeam;

public List[] teams ={new ArrayList<EntityPlayer>(),new ArrayList<EntityPlayer>(),new ArrayList<EntityPlayer>(),new ArrayList<EntityPlayer>(),new ArrayList<EntityPlayer>(),new ArrayList<EntityPlayer>(),new ArrayList<EntityPlayer>(),new ArrayList<EntityPlayer>()};



public SkyBattle(int i) {
	this(i,1, 1,1);
}


public SkyBattle(int dim, int map, int teams, int playersPerTeam) {

	this.dim=dim;
	this.map=map;
	this.teamNumber=teams;
	this.playerPerTeam=playersPerTeam;
	this.state=EnumGameState.RESTARTING;

	this.resetWorld(EnumGameMode.SKY_BATTLE, this.map, this.dim);

	this.createScoreboard();



}

public void createScoreboard(){
	Scoreboard scoreboard = MinecraftServer.getServer().worldServerForDimension(this.dim).getScoreboard();

	for(int i=0; i<teamNumber;i++){
		if(scoreboard.getTeam(EnumTeam.values()[i].toString())==null){
			scoreboard.createTeam(EnumTeam.values()[i].toString());
		}
		//ScorePlayerTeam team = new ScorePlayerTeam(scoreboard,i+"");
		ScorePlayerTeam team = scoreboard.getTeam(EnumTeam.values()[i].toString());
		team.setTeamName(EnumTeam.values()[i].toString());
		team.func_178774_a(EnumChatFormatting.RED);
		team.setNamePrefix("TEST");

		scoreboard.sendTeamUpdate(team);
	}
}


@Override
public void joinPlayer(EntityPlayer player){
	boolean alreadyOnline=false;


	player.setCustomNameTag("asdasdasd");


	for(EntityPlayer player1 : this.players){
		if(player1 == player)
			alreadyOnline=true;
	}
	if(!alreadyOnline){
		this.players.add(player);
	}

	if(this.players.size()>=this.playerPerTeam*this.teamNumber){
		for (EntityPlayer player1 : this.players) {
		    player1.addChatComponentMessage(new ChatComponentText("The game has started."));
		    this.countdown();
		}
	}
}

@Override
public void disconnectPlayer(EntityPlayer player){
	players.remove(player);
    for(int i=0;i<this.teams.length;i++){
    	if(this.teams[i].contains(player))
    		this.teams[i].remove(player);
    }
   
}

public void joinTeam(EntityPlayer player, EnumTeam team){
	if(team.ordinal()<this.teamNumber){

			if(teams[team.ordinal()].contains(player)){

				teams[team.ordinal()].remove(player);

				player.addChatComponentMessage(new ChatComponentText("You left Team " + team.toString()));
			} else {
					if(teams[team.ordinal()].size()<this.playerPerTeam){

						for(int i=0; i<teams.length;i++){
							if(teams[i].contains(player)){
								teams[i].remove(player);
							}
						}

						teams[team.ordinal()].add(player);	


						player.addChatComponentMessage(new ChatComponentText(team.getChatColor() + "You joined team " + team.toString() + "."));
						player.setCustomNameTag(team.getChatColor()+player.getName());

					} else {
						player.addChatComponentMessage(new ChatComponentText("This team is already full."));
					}


				}

	} else {
		player.addChatComponentMessage(new ChatComponentText(EnumChatFormatting.DARK_RED+"The team you were about to join does not exist."));
	}
}

public void autojoinTeam(){
	for (EntityPlayer player : this.players) {
	    boolean isInTeam=false;
	    
	    for(int i=0;i<this.teams.length;i++){
	    	if(this.teams[i].contains(player))
	    		isInTeam=true;
	    }
	    
	    if(!isInTeam){
		    for(int i=0;i<this.teams.length;i++){
		    	if(this.teams[i].size()<this.playerPerTeam){
		    		this.teams[i].add(player);
		    		
		    		
		    		
					player.addChatComponentMessage(new ChatComponentText(EnumTeam.values()[i].getChatColor() + "You joined team " + EnumTeam.values()[i].toString() + "."));
					player.setCustomNameTag(EnumTeam.values()[i].getChatColor().toString() +player.getName());


					Scoreboard scoreboard = MinecraftServer.getServer().worldServerForDimension(this.dim).getScoreboard();


					//scoreboard.addPlayerToTeam(player.getName(), (i+""));
					scoreboard.addPlayerToTeam(player.getName(), EnumTeam.values()[i].toString());
		    		
		    		//System.out.println(player.worldObj.getScoreboard().getTeam(i+"").);
		    		
		    		break;
		    	}
		    }
	    }



	}
}

@Override
public void start(){
	this.autojoinTeam();

	for(EntityPlayer player : players){
		DisplayTitle.sendTitle(player, S45PacketTitle.Type.TITLE, new ChatComponentText("SKY BATTLE"));
	}

	this.messageToAllPlayers(new ChatComponentText(EnumChatFormatting.AQUA +"The game has started!"));

	this.messageToAllPlayers(new ChatComponentText(EnumChatFormatting.WHITE +"As long as your beacon is not destroyed you can respawn at you base."));
	this.messageToAllPlayers(new ChatComponentText(EnumChatFormatting.WHITE +"Try to destroy the enemies beacon."));


}


}

 

 

Here could be your advertisement!

Link to comment
Share on other sites

Ok, fixed it by using:

 

            team.func_178774_a(EnumTeam.values()[i].getChatColor());
            team.setNamePrefix(EnumTeam.values()[i].getChatColor().toString());
            team.setNameSuffix(EnumChatFormatting.RESET.toString());			

 

Thats great. However, all my players are automatically added to the scoreboard. Not so great. Also it seems like the same scoreboard is used in all dimensions. How can i avoid this?

Here could be your advertisement!

Link to comment
Share on other sites

Ok, not sure why, but after I added some empty lines the player isn't in the first team by default.

However, he still keeps his in team in another dim...

 

 

@SubscribeEvent
public void onEntityJoinWorldEvent(EntityJoinWorldEvent event){
	if(event.entity instanceof EntityPlayer){
                
                 ...

		if(BlackGeckoServer.gameServer.containsKey(event.world.provider.getDimensionId())){
			System.out.println("JOINED !!!!!!");
			BlackGeckoServer.gameServer.get(event.world.provider.getDimensionId()).joinPlayer(player);
		}	
	}
}

Here could be your advertisement!

Link to comment
Share on other sites

Oh. I just found out that Scoreboard is saved in mapStorage, which is for per map, not per world.

  Then, you should have to add/remove player in the Team when the player joins/leaves the world.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.