Group slayer

Linus

🍕
Dec 30, 2008
2,797
220
0
Early build of my group slayer system, some of you might like this

Code:
package server.model.players.skills.slayer;

import server.core.PlayerHandler;
import server.model.players.Client;

public class SlayerParty {


	public static boolean debug = false;
	public static int teamLeader = 0;
	public static int targetNpc = 1;
	public static int targetAmount = 2;
	public static int teamPlayerOne = 3;
	public static int teamPlayerTwo = 4;

	public static int[][] partyData = new int[100][5];

	private static boolean canJoin(Client user, Client otherUser, boolean invite){
		if(debug)
			System.out.println("invite: "+invite+", user: "+user.playerName+", "+(otherUser != null ? "otherUser: "+otherUser.playerName : "") );


		if(invite){
			if(otherUser != null){
				if(user.teamLeaderId == user.playerId){
					//leader inviting otherUser
					if(otherUser.inSlayerTeam){
						user.sendMessage("This user is already in a slayer party.");
						return false;
					}
					if(user.taskAmount > 0){
						if(user.slayerTask != otherUser.slayerTask && otherUser.slayerTask > 0 && otherUser.taskAmount > 0){
							user.sendMessage("Other user is already on another slayer task");
							return false;
						}
						if(user.taskAmount > otherUser.taskAmount && otherUser.taskAmount > 0){
							user.sendMessage("You have more kills left than the selected user.");
							return false;
						}
						if(user.slayerTask == otherUser.slayerTask && user.taskAmount <= otherUser.taskAmount){
							//same task but less or equal taskAmount left
							return true;
						} else {
							user.sendMessage("This user is already on another slayer task.");
							return false;
						}
					}

				} else {
					//user joining otherUser
					if(!otherUser.inSlayerTeam || otherUser.teamLeaderId != otherUser.playerId){
						user.sendMessage("This user is not the host of a slayer party.");
						return false;
					}

					if(user.slayerTask < 1 || otherUser.slayerTask < 1 || (user.taskAmount < 1 && otherUser.taskAmount < 1)){
						//either user has no task and can join
						return true;
					}

					if(user.slayerTask == otherUser.slayerTask && user.taskAmount <= otherUser.taskAmount){
						//same task but less or equal taskAmount left
						return true;
					} else {
						user.sendMessage("This user is already on another slayer task.");
						return false;
					}

				}
			} else{
				//user is null
				if(debug)
					System.out.println("User is null");
				return false;
			}

		} else {
			if(user.inSlayerTeam){
				user.sendMessage("You're already in a slayer party, you need to leave first.");
				return false;
			}

			if(user.taskAmount > 0){
				//user has task
				if(otherUser != null){
					//trying to join another team
					if(user.slayerTask != otherUser.slayerTask){
						user.sendMessage("You need to be on the same task to join a team.");
						return false;
					} else {
						if(user.taskAmount <= otherUser.taskAmount || user.taskAmount <= 0){
							//has less monsters left, join party and set new taskAmount
							return true;
						} else {
							user.sendMessage("Can not join the party, you have more kills left than the party owner.");
							return false;
						}
					}
				} else {
					//trying to make a team
				}
			}

			return true;
		}

		return true;
	}

	public static void createParty(Client user){
		if(user != null){
			if(user.inSlayerTeam){
				user.sendMessage("You're already in a Party, leave first!");
				return;
			}

			if(!canJoin(user, null, false)){
				return;
			}
			int slot = nextSlotWithNoTeam();
			partyData[slot][teamLeader] = user.playerId;
			partyData[slot][targetNpc] = user.slayerTask;
			partyData[slot][targetAmount] = user.taskAmount;
			user.teamLeaderId = user.playerId;
			user.slayerPartyId = slot;
			user.inSlayerTeam = true;
			user.sendMessage("You've created a Group Slayer Party! Use your Enchanted gem to invite.");
		}

	}

	public static void disbandParty(Client user, boolean kicked){
		if(user != null){
			if(!user.inSlayerTeam || user.slayerPartyId < 0){
				user.sendMessage("You're not in a slayer party!");
				return;
			}
			if(slotWithSpecificOwner(user) < 0){ //not host
				Client host = (Client) PlayerHandler.players[user.teamLeaderId];
				if(host != null){
					if(partyData[slotWithSpecificOwner(host)][teamPlayerOne] == user.playerId){
						partyData[slotWithSpecificOwner(host)][teamPlayerOne] = -1;
						host.sendMessage(kicked ? user.playerName+ " has been kicked from your party." : user.playerName+ " has left your party.");
						user.inSlayerTeam = false;
						user.slayerPartyId = -1;
						user.teamLeaderId = -1;
					} else
						if(partyData[slotWithSpecificOwner(host)][teamPlayerTwo] == user.playerId){
							partyData[slotWithSpecificOwner(host)][teamPlayerTwo] = -1;
							host.sendMessage(kicked ? user.playerName+ " has been kicked from your party." : user.playerName+ " has left your party.");
							user.inSlayerTeam = false;
							user.slayerPartyId = -1;
							user.teamLeaderId = -1;
						}
				}
			} else {
				int slot = slotWithSpecificOwner(user);
				if(partyData[slot][teamLeader] == user.playerId){
					partyData[slot][teamLeader] = -1;
					messageTeam(partyData[slot][teamPlayerOne], partyData[slot][teamPlayerTwo], true);
					partyData[slot][teamPlayerOne] = -1;
					partyData[slot][teamPlayerTwo] = -1;
					user.slayerPartyId = -1;
					user.teamLeaderId = -1;
					user.inSlayerTeam = false;
					user.sendMessage("You have disbanded the party!");
					return;
				}
			}
			updateKillcount(user.slayerPartyId, -1, new int[2]);
			user.slayerPartyId = -1;
			user.teamLeaderId = -1;
			user.inSlayerTeam = false;
			user.sendMessage(kicked ? "You have been kicked from the slayer party" : "You've left the slayer party!");
		}
	}

	public static void joinParty(Client user, Client otherUser, boolean invite){
		if(user != null && otherUser != null){

			if(debug)
				System.out.println("Was invited ? "+invite);

			if(invite){

				if(!canJoin(user, otherUser, true)){
					if(debug)
						System.out.println("User cant join");
					return;
				}
				if(debug)
					System.out.println("User can join");

				if(otherUser.inSlayerTeam){
					user.sendMessage("This user is already in a slayer party.");
					return;
				}

				otherUser.invitedToParty = user.playerId;
				otherUser.sendMessage(user.playerName+" has invited you to join their Slayer party.. Command ::acceptinvite");
			} else { //join other team

				if(!canJoin(user, otherUser, false)){
					return;
				}

				if(slotWithSpecificOwner(otherUser) > -1){
					if(partyData[slotWithSpecificOwner(otherUser)][teamPlayerOne] == -1){
						//Client host = (Client) PlayerHandler.players[user.teamLeaderId];
						partyData[slotWithSpecificOwner(otherUser)][teamPlayerOne] = user.playerId;
						otherUser.sendMessage(user.playerName +" has joined the slayer party!");
						user.teamLeaderId = otherUser.playerId;
						user.sendMessage("You have joined "+otherUser.playerName+"'s Slayer party!");
						user.slayerPartyId = otherUser.slayerPartyId;
						user.inSlayerTeam = true;
						updateKillcount(slotWithSpecificOwner(otherUser), -1, new int[2]);
					} else 
						if(partyData[slotWithSpecificOwner(otherUser)][teamPlayerTwo] == -1){
							partyData[slotWithSpecificOwner(otherUser)][teamPlayerTwo] = user.playerId;
							otherUser.sendMessage(user.playerName +" has joined the Slayer party!");
							user.teamLeaderId = otherUser.playerId;
							user.sendMessage("You have joined "+otherUser.playerName+"'s Slayer party!");
							user.slayerPartyId = otherUser.slayerPartyId;
							user.inSlayerTeam = true;
							updateKillcount(slotWithSpecificOwner(otherUser), -1, new int[2]);
						} else {
							user.sendMessage("That party is full already!");
						}
				} else {
					user.sendMessage("That user does not have an active slayer party!");
				}

			}
		}
	}

	private static boolean kickPlayer(Client user){
		if(user != null){
			disbandParty(user, true);
			return true;
		}
		return false;
	}

	public static void kickPlayerOption(Client user){
		if(user != null){
			if(user.inSlayerTeam){
				if(user.slayerPartyId > -1){
					Client partyHost = (Client) PlayerHandler.players[partyData[user.slayerPartyId][teamLeader]];
					if(partyHost != null){
						if(partyHost == user){
							int party = partyHost.slayerPartyId;
							if(user.groupSlayerMemberClicked == 1 && partyData[party][teamPlayerOne] != -1 || user.groupSlayerMemberClicked == 2 && partyData[party][teamPlayerTwo] != -1){
								Client partyPlayer = (Client) PlayerHandler.players[partyData[party][user.groupSlayerMemberClicked == 1 ? teamPlayerOne : (user.groupSlayerMemberClicked == 2 ? teamPlayerTwo : null)]];
								if(partyPlayer != null)
								{
									if(kickPlayer(partyPlayer)){
										user.sendMessage("You kicked "+partyPlayer.playerName+" from the slayer party.");
									} else {
										if(debug)
											System.out.println("Something unexpected just happened.");
									}
								}
							} else {
								//user.sendMessage("There is no user in that slot");
							}
						} else {
							//not leader of the team
						}
					} else {
						//user.sendMessage("There is no team leader for that party");
					}
				}
			}
			user.groupSlayerMemberClicked = -1;
			user.groupSlayerOptions = -1;
			user.getPA().closeAllWindows();
		}
	}

	public static void manageTeam(Client user){
		if(user != null){
			if(user.inSlayerTeam){
				if(user.slayerPartyId > -1){
					Client partyHost = (Client) PlayerHandler.players[partyData[user.slayerPartyId][teamLeader]];
					if(partyHost != null){
						if(partyHost == user){
							int party = partyHost.slayerPartyId;
							String playerOne = "(Empty)";
							String playerTwo = "(Empty)";
							if(partyData[party][teamPlayerOne] != -1){
								Client partyPlayerOne = (Client) PlayerHandler.players[partyData[party][teamPlayerOne]];
								if(partyPlayerOne != null)
									playerOne = partyPlayerOne.playerName;
							}
							if(partyData[party][teamPlayerTwo] != -1){
								Client partyPlayerTwo = (Client) PlayerHandler.players[partyData[party][teamPlayerTwo]];
								if(partyPlayerTwo != null)
									playerTwo = partyPlayerTwo.playerName;
							}

							user.getDH().sendOption4(partyHost.playerName, playerOne, playerTwo, "Back");
							user.groupSlayerOptions = 2;
							return;
						} else {
							user.sendMessage("Only the party leader can make these changes.");
						}
					}
				}
			}
			user.groupSlayerOptions = -1;
			user.getPA().closeAllWindows();
		}
	}

	private static void messageTeam(int p1, int p2, boolean disbanded){
		if(p1 > -1){
			Client playerOne = (Client) PlayerHandler.players[p1];
			if(playerOne != null){
				if(disbanded){
					playerOne.inSlayerTeam = false;
					playerOne.slayerPartyId = -1;
					playerOne.teamLeaderId = -1;
					playerOne.invitedToParty = -1;
				}
				playerOne.sendMessage(disbanded ? "Your slayer party has been disbanded by the leader." : "Your slayer party has finished a slayer task.");
			}
		}
		if(p2 > -1){
			Client playerTwo = (Client) PlayerHandler.players[p2];
			if(playerTwo != null){
				if(disbanded){
					playerTwo.inSlayerTeam = false;
					playerTwo.slayerPartyId = -1;
					playerTwo.teamLeaderId = -1;
					playerTwo.invitedToParty = -1;
				}
				playerTwo.sendMessage(disbanded ? "Your slayer party has been disbanded by the leader." : "Your slayer party has finished a slayer task.");
			}
		}
		return;


	}

	public static int nextSlotWithNoTeam(){
		for(int i = 0; i < partyData.length; i++){
			if(partyData[i][teamLeader] < 1){
				return i;
			}
		}
		return 0;
	}

	public static void setTask(int team, int npcId, int taskAmount){
		if(team > -1){

			Client host = (Client) PlayerHandler.players[partyData[team][teamLeader]];

			if(host != null){

				partyData[team][targetNpc] = npcId;
				partyData[team][targetAmount] = taskAmount;

				if(debug)
					System.out.println("taskChanged for host");

				taskChanged(host, team, -1, new int[2]);

				if(partyData[team][teamPlayerOne] != -1){
					Client partyPlayerOne = (Client) PlayerHandler.players[partyData[team][teamPlayerOne]];

					if(partyPlayerOne != null){
						if(debug)
							System.out.println("taskChanged for player one");
						partyPlayerOne.slayerTask = npcId;
						partyPlayerOne.taskAmount = taskAmount;
						taskChanged(partyPlayerOne, team, -1, new int[2]);
					} else {
						partyData[team][teamPlayerOne] = -1;
					}
				}
				if(partyData[team][teamPlayerTwo] != -1){
					Client partyPlayerTwo = (Client) PlayerHandler.players[partyData[team][teamPlayerTwo]];

					if(partyPlayerTwo != null){
						if(debug)
							System.out.println("taskChanged for player two");
						partyPlayerTwo.slayerTask = npcId;
						partyPlayerTwo.taskAmount = taskAmount;
						taskChanged(partyPlayerTwo, team, -1, new int[2]);
					} else {
						partyData[team][teamPlayerTwo] = -1;
					}
				}
			}
		} else {
			return;
		}
	}

	public static void setTeamLeader(Client user){
		if(user != null){
			if(user.inSlayerTeam){
				if(user.slayerPartyId > -1){
					Client partyHost = (Client) PlayerHandler.players[partyData[user.slayerPartyId][teamLeader]];
					if(partyHost != null){
						if(partyHost == user){
							int party = partyHost.slayerPartyId;
							Client partyPlayer = null;
							if(partyData[party][user.groupSlayerMemberClicked == 1 ? teamPlayerOne : (user.groupSlayerMemberClicked == 2 ? teamPlayerTwo : -1)] != -1){
								partyPlayer = (Client) PlayerHandler.players[partyData[party][user.groupSlayerMemberClicked == 1 ? teamPlayerOne : (user.groupSlayerMemberClicked == 2 ? teamPlayerTwo : -1)]];
							}
							if(partyPlayer != null){
								partyData[party][teamLeader] = partyPlayer.playerId;
								partyData[party][user.groupSlayerMemberClicked == 1 ? teamPlayerOne : teamPlayerTwo] = user.playerId;
								partyPlayer.teamLeaderId = partyPlayer.playerId;
								partyPlayer.sendMessage(user.playerName+" has made you the slayer party leader.");

								if(partyData[party][teamPlayerOne] != -1){
									Client partyPlayerOne = (Client) PlayerHandler.players[partyData[party][teamPlayerOne]];
									if(partyPlayerOne != null)
									{
										partyPlayerOne.teamLeaderId = partyPlayer.playerId;
										partyPlayerOne.sendMessage(partyPlayer.playerName+" has been set as the new slayer party leader.");
									}
								}
								if(partyData[party][teamPlayerTwo] != -1){
									Client partyPlayerTwo = (Client) PlayerHandler.players[partyData[party][teamPlayerTwo]];
									if(partyPlayerTwo != null)
									{
										partyPlayerTwo.teamLeaderId = partyPlayer.playerId;
										partyPlayerTwo.sendMessage(partyPlayer.playerName+" has been set as the new slayer party leader.");
									}
								}

							}
						} else {
							user.sendMessage("Only the party leader can make these changes.");
						}
					}
				}
			}
			user.groupSlayerMemberClicked = -1;
			user.groupSlayerOptions = -1;
			user.getPA().closeAllWindows();
		}
	}

	public static void showPartyOptions(Client user){
		user.getDH().sendOption4("Create party", "Disband/Leave party", "Manage team", "");
		user.groupSlayerOptions = 1;
		user.nextChat = 0;
	}

	private static int slotWithSpecificOwner(Client owner){
		if(owner != null){
			for(int i = 0; i < partyData.length; i++){
				if(partyData[i][teamLeader] == owner.playerId){
					return i;
				}
			}
		}
		return -1;
	}

	/***
	 *
	 * 1: TeamID
	 * 
	 * 2: TeamData
	 * 	- 0 Team Leader Id
	 *	- 1 Target NPC Id
	 *	- 2 Target Amount
	 *	- 3 User slot
	 *	- 4 User slot
	 */

	public static void start(){
		long a = System.currentTimeMillis();
		for(int i = 0; i < partyData.length; i++){
			partyData[i][teamLeader] = -1;
			partyData[i][teamPlayerOne] = -1;
			partyData[i][teamPlayerTwo] = -1;
		}
		long took = System.currentTimeMillis() - a;
		System.out.println("SlayerParty data initiated in "+took+"ms");
	}

	private static void resetTask(int team){
		partyData[team][targetNpc] = -1;
		partyData[team][targetAmount] = -1;
	}
	
	private static void taskChanged(Client c, int team, int xpAmount, int[] location){
		int npcX = location[0];
		int npcY = location[1];
		if(partyData[team][targetAmount] <= 0 && partyData[team][targetNpc] >= 1){
			//last kill
			c.slayerTask = -1;
			c.taskAmount = 0;
			c.slayerPartyId = team;

			if(xpAmount > 0){

				if(c.slayerPartyId == team && partyData[team][teamLeader] == c.playerId && partyData[team][teamPlayerOne] < 0 && partyData[team][teamPlayerTwo] < 0){
					//if client is leader and no other is in team
					if(debug)
						System.out.println("Reset team: "+team);
					resetTask(team);
				} else {
					//if client is last browsed player in team
					if(partyData[team][teamPlayerOne] == c.playerId && partyData[team][teamPlayerTwo] < 0){
						if(debug)
							System.out.println("Player one reset team: "+team);
						resetTask(team);
					} else if(partyData[team][teamPlayerTwo] == c.playerId){
						if(debug)
							System.out.println("Player two reset team: "+team);
						resetTask(team);
					}
				}
				
				c.finishedTasks++;
				c.slayerPoints++; 
				c.getDH().sendStatement("Your party has completed a slayer task.");
				c.nextChat = -1;

				if(debug)
					System.out.println("Player xp incomming");
				
				if(c.distanceToPoint(npcX, npcY) < 30){
					
					if(debug)
						System.out.println("Text should show");
					
					c.sendMessage("<col=80000>You received an extra "+(xpAmount * 2)+" xp for this kill.");
					c.sendMessage("<col=80000>You have now completed "+c.finishedTasks+" Slayer tasks. You have "+c.slayerPoints+" Slayer points.");
					c.getPA().addSkillXP(((xpAmount/2) * 2), 18);
				} else {
					c.sendMessage("<col=80000>You were to far away to receive any bonus xp for this task.");
					c.sendMessage("<col=80000>You have now completed "+c.finishedTasks+" Slayer tasks. You have "+c.slayerPoints+" Slayer points.");
				}
			}
		} else {
			c.slayerTask = partyData[team][targetNpc];
			c.taskAmount = partyData[team][targetAmount];
			c.slayerPartyId = team;

			if(xpAmount > 0){
				c.totalSlayerKills++;
				if(c.distanceToPoint(npcX, npcY) < 30){
					c.getPA().addSkillXP(xpAmount/2, 18);
				} else {
					c.sendMessage("<col=80000>You are to far away to receive any xp from your slayer party task.");
				}
			}
		}
	}

	public static void updateKillcount(int team, int xpAmount, int[] location){
		if(team > -1){

			Client host = (Client) PlayerHandler.players[partyData[team][teamLeader]];

			if(host != null){

				taskChanged(host, team, xpAmount, location);

				if(partyData[team][teamPlayerOne] != -1){
					Client partyPlayerOne = (Client) PlayerHandler.players[partyData[team][teamPlayerOne]];

					if(partyPlayerOne != null){
						if(debug)
							System.out.println("Player one in team bout to change");
						taskChanged(partyPlayerOne, team, xpAmount, location);
					} else {
						partyData[team][teamPlayerOne] = -1;
					}
				}
				if(partyData[team][teamPlayerTwo] != -1){
					Client partyPlayerTwo = (Client) PlayerHandler.players[partyData[team][teamPlayerTwo]];

					if(partyPlayerTwo != null){
						if(debug)
							System.out.println("Player two in team bout to change");
						taskChanged(partyPlayerTwo, team, xpAmount, location);
					} else {
						partyData[team][teamPlayerTwo] = -1;
					}
				}
			}
		} else {
			return;
		}
	}

	public static void userOptions(Client user){
		if(user != null){
			if(user.inSlayerTeam){
				if(user.slayerPartyId > -1){
					Client partyHost = (Client) PlayerHandler.players[partyData[user.slayerPartyId][teamLeader]];
					if(partyHost != null){
						int party = partyHost.slayerPartyId;
						if(user.groupSlayerMemberClicked == 1 && partyData[party][teamPlayerOne] != -1 || user.groupSlayerMemberClicked == 2 && partyData[party][teamPlayerTwo] != -1){
							Client partyPlayer = (Client) PlayerHandler.players[partyData[party][user.groupSlayerMemberClicked == 1 ? teamPlayerOne : (user.groupSlayerMemberClicked == 2 ? teamPlayerTwo : null)]];
							if(partyPlayer != null)
							{
								user.groupSlayerOptions = 3;
								user.getDH().sendOption3(partyPlayer.playerName, "Kick", "Set leader", "Back");
								return;
							}
						} else {
							//user.sendMessage("There is no user in that slot");
						}
					} else {
						//user.sendMessage("There is no team leader for that party");
					}
				}
			}
			user.groupSlayerMemberClicked = -1;
			user.groupSlayerOptions = -1;
			user.getPA().closeAllWindows();
		}
	}

}
 
Why is everything static? You should be using objects

Code:
[COLOR=#C26230][FONT=monospace]public [/FONT][/COLOR][COLOR=#C26230][FONT=monospace]static [/FONT][/COLOR][COLOR=#C26230][FONT=monospace]int[/FONT][/COLOR][COLOR=#E6E1DC][FONT=monospace][][] partyData = [/FONT][/COLOR][COLOR=#C26230][FONT=monospace]new[/FONT][/COLOR][COLOR=#C26230][FONT=monospace]int[/FONT][/COLOR][COLOR=#E6E1DC][FONT=monospace][[/FONT][/COLOR][COLOR=#A5C261][FONT=monospace]100[/FONT][/COLOR][COLOR=#E6E1DC][FONT=monospace]][[/FONT][/COLOR][COLOR=#A5C261][FONT=monospace]5[/FONT][/COLOR][COLOR=#E6E1DC][FONT=monospace]];[/FONT][/COLOR]
This really does not warrant an array, it makes everything so much more confusing and difficult to read - use an object.


Code:
[COLOR=#FFC66D][FONT=monospace]messageTeam[/FONT][/COLOR][COLOR=#D0D0FF][FONT=monospace]([COLOR=#C26230]int[/COLOR] p1, [COLOR=#C26230]int[/COLOR] p2, boolean disbanded)[/FONT][/COLOR]
What are 'p1' and 'p2'? Use clear naming.


oh my lord[spoil]
1DbYwUD.png

[/spoil]You don't need to chain all those if statements together, as you can see it creates a really long mess.

Reduce it by doing simple things like
Code:
if (user == null) {
    return;
}
[continue code here]
compared to
Code:
if (user != null) {
    [continue code here]
}


Code:
[COLOR=#C26230][FONT=monospace]int[/FONT][/COLOR][COLOR=#D0D0FF][FONT=monospace][] location[/FONT][/COLOR]
Again, use objects.

I could go on, but you get the picture.
Hope this helps you learn and improve, feel free to pm me if you want any advice or help
 
As Tesla stated, why the hell is everything static? I can guarantee you this has A LOT of flaws in it due to that very specific issue.
All in all, I'll be honest with you. This is just plain bad. Everything is static, nothing is final. Nothing is dynamic; Just because you carry on the Player parameter in every method doesn't mean it's dynamic by any means. Everything within this class is shared by all the players.
Try to avoid things like:
Direct accessing to fields, rather use getters and setters.
Cluttering all the variables of a specific event in Player class - Avoid it, make a new class, store all the variables within it and store the class on the Player class.
Use final as much as you can (You can use it in absolutely everything for the specific code you've written).
Try avoiding multi-dimensional arrays. You don't even need it in this case.

Some specifics(Irrelevant to java):
The distance check is done between two players not between the dying monster and a player.
For the distance check, the amount of squares is 16 on RS.
There were a lot of inconsistencies within the messages sent to players, often missing punctuation, random capitalization and whatnot.

Try avoiding the aforementioned things, after-all this is the code that you're presenting to us, presentations should be done properly.
 
As Tesla stated, why the hell is everything static? I can guarantee you this has A LOT of flaws in it due to that very specific issue.

Such as?

There's nothing really wrong with making methods static and paramatizing player objects in the methods, especially in this instance. The only alternative is setting a player object in the constructor and using that instead but that's a pretty bad design for most things.

But yeah this snippet is absolutely brutal
 
Such as?

There's nothing really wrong with making methods static and paramatizing player objects in the methods, especially in this instance. The only alternative is setting a player object in the constructor and using that instead but that's a pretty bad design for most things.

But yeah this snippet is absolutely brutal

I wasn't speaking of only the methods, but rather the actual variables within. But since you asked about the methods themselves:
In general, static methods are usually avoided because interfaces and abstract classes don't define static methods, nor can they call the super() method.
In this specific case, all the variables are static, I must point this out before continuing. These variables should not, by any means, be static. Unless they're actual constants, you will only be able to call those variables through static methods. This is where the main issue pops in - these n on-final variables should've all been non-static. The 'public static int[][] partyData = new int[100][5];' variable at the top will most certainly be causing issues; Because it's static, all players will be accessing this same variable. I really don't even understand why Linus has created this variable as it's just really a bad way of doing this in my opinion. My main question here is - What happens if the 100 slots run out? I didn't even bother reading through the entire code but it didn't seem as if you had any checks for that event - it'll just break down if I'm not mistaken.
You're saving 5 different integers within the partyData array. You should've saved these separately on the players rather, since this information is something that doesn't just disappear (although it does for you as soon as the server restarts). Instead of saving these variables on the Player class and cluttering it up big time, I'd rather personally have saved them inside an object to avoid.. well, cluttering. You should actually be saving around 5-10 variables, having them all sit within the Player class really does clutter it out (Just consider having tens if not hundreds of features all coded in the exact same manner - you'd have hundreds of variables like that). Another aforementioned thing I must point out is that you're directly accessing the variables from a different class. You should avoid that and use getters and setters. Now consider those hundreds of variables alongside the getters and setters, you'd have 6 times more lines being taken up by it (considering 3 lines per method).
I mean I could keep going on and on about this but the part that annoys me the most is the overall appearance of this (besides the actual flaws in the code). It's just so all-over the place. I'd much rather have something like this (Note it's still an unfinished project of mine, therefore there may actually be more variables coming) https://puu.sh/wtYeV/fe507ad2bb.png
If you look at the variables amount, you may finally understand what I was trying to say with the above. It'll become incredibly cluttered by the end (Note: This is also for a 881 revision which requires far more variables than any lower revisions, RS has been advancing Slayer by a lot lately).

I'd like you to explain to me why this is bad design:
The only alternative is setting a player object in the constructor and using that instead but that's a pretty bad design for most things.
It makes little to no sense to me.
 
I'd like you to explain to me why this is bad design:
The only alternative is setting a player object in the constructor and using that instead but that's a pretty bad design for most things.
It makes little to no sense to me.

Every time a host leaves a party its removed from the array.
Cap of 100? Thats up to 300 players doing team slayer at the same time.

I totally understand what you're trying to say though
I think that this way works just fine for my project and surely I'll rewrite it when I get the time.
 
I have to say thank you for releasing something. It really seems that this server section was always having releases. Now there is trolls everywhere scaring everyone to release anything.
 

Users who are viewing this thread (total: 1, members: 0, guests: 1)

Who read this thread (total members: 1)