-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayerJoin.java
55 lines (39 loc) · 1.73 KB
/
playerJoin.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package me.bretmounet.scavengerhunt;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.scoreboard.Team;
import javax.swing.*;
import java.sql.*;
import java.util.*;
public class playerJoin implements Listener {
public static Connection connection = Scavengerhunt.connection; // Establishes a connection to mySQL database
@EventHandler
public void event(PlayerJoinEvent event) throws SQLException {
Player player = event.getPlayer();
UUID id = player.getUniqueId();
String playerName = id.toString(); //stores player's uuid instead of username since it can change
List<String> playersTeam = new ArrayList<>();
List<Boolean> onTeam = new ArrayList<>();
TeamManager.getTeamNames();
TeamManager.getPlayersTeam(playerName,playersTeam,onTeam);
TeamManager.createTeams();
if(!onTeam.isEmpty()) {
if (onTeam.get(0) == true){
TeamManager.assignTeam(playersTeam.get(0),player);
player.sendMessage("Welcome Back!");
}
}else{
player.sendMessage(ChatColor.GOLD + "You are not on a team. Use /create to create a team or /join to join a team");
}
Statement statement = connection.createStatement(); // creates a statement used to access data from database.
statement.close(); // closes statement
player.setScoreboard(TeamManager.board);
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent e) {
}
}