All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.tvd12.gamebox.entity.Player Maven / Gradle / Ivy

There is a newer version: 1.2.4
Show newest version
package com.tvd12.gamebox.entity;

import com.tvd12.ezyfox.builder.EzyBuilder;
import com.tvd12.ezyfox.util.EzyEquals;
import com.tvd12.ezyfox.util.EzyHashCodes;
import com.tvd12.gamebox.constant.IPlayerRole;
import com.tvd12.gamebox.constant.IPlayerStatus;
import com.tvd12.gamebox.constant.PlayerRole;
import com.tvd12.gamebox.constant.PlayerStatus;

import lombok.Getter;
import lombok.Setter;

@Getter
public class Player {

	protected final String name;
	@Setter
	protected IPlayerRole role = PlayerRole.NULL;
	@Setter
	protected IPlayerStatus status = PlayerStatus.NULL;
	@Setter
	protected long currentRoomId;
	
	public Player(String name) {
		this.name = name;
	}
	
	protected Player(Builder builder) {
		this(builder.name);
	}
	
	@Override
	public boolean equals(Object obj) {
		return new EzyEquals()
				.function(t -> t.name)
				.isEquals(this, obj);
	}
	
	@Override
	public int hashCode() {
		return new EzyHashCodes()
				.append(name)
				.toHashCode();
	}
	
	@Override
	public String toString() {
		return name;
	}
	
	public static Builder builder() {
		return new Builder<>();
	}

	@SuppressWarnings("unchecked")
	public static class Builder> implements EzyBuilder {
		
		protected String name;
		
		public B name(String name) {
			this.name = name;
			return (B)this;
		}
		
		@Override
		public Player build() {
			preBuild();
			return newProduct();
		}
		
		protected void preBuild() {
		}
		
		protected Player newProduct() {
			return new Player(this);
		}
		
	}
	
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy