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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
/*
* This file is part of Kenshins Hide and Seek
*
* Copyright (c) 2022 Tyler Murphy.
*
* Kenshins Hide and Seek free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* he Free Software Foundation version 3.
*
* Kenshins Hide and Seek is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package net.tylermurphy.hideAndSeek.game;
import com.cryptomorin.xseries.messages.Titles;
import net.md_5.bungee.api.ChatColor;
import net.tylermurphy.hideAndSeek.Main;
import net.tylermurphy.hideAndSeek.configuration.Items;
import net.tylermurphy.hideAndSeek.configuration.Map;
import org.bukkit.GameMode;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
@SuppressWarnings("deprecation")
public class PlayerLoader {
public static void loadHider(Player player, Map map){
map.getGameSpawn().teleport(player);
loadPlayer(player);
player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED,1000000,5,false,false));
Titles.sendTitle(player, 10, 70, 20, ChatColor.WHITE + "" + message("HIDER_TEAM_NAME"), ChatColor.WHITE + message("HIDERS_SUBTITLE").toString());
if(map.isBlockHuntEnabled()){
openBlockHuntPicker(player, map);
}
}
public static void loadSeeker(Player player, Map map){
map.getGameSeekerLobby().teleport(player);
loadPlayer(player);
Titles.sendTitle(player, 10, 70, 20, ChatColor.WHITE + "" + message("SEEKER_TEAM_NAME"), ChatColor.WHITE + message("SEEKERS_SUBTITLE").toString());
}
public static void loadSpectator(Player player, Map map){
map.getGameSpawn().teleport(player);
loadPlayer(player);
player.setAllowFlight(true);
player.setFlying(true);
player.setFallDistance(0.0F);
player.getInventory().setItem(flightToggleItemPosition, flightToggleItem);
player.getInventory().setItem(teleportItemPosition, teleportItem);
Main.getInstance().getBoard().getPlayers().forEach(otherPlayer -> otherPlayer.hidePlayer(player));
Titles.sendTitle(player, 10, 70, 20, ChatColor.GRAY + "" + ChatColor.BOLD + "SPECTATING", ChatColor.WHITE + message("SPECTATOR_SUBTITLE").toString());
}
public static void resetPlayer(Player player, Board board){
if(board.isSpectator(player)) return;
loadPlayer(player);
if (board.isSeeker(player)) {
if (pvpEnabled)
for(ItemStack item : Items.SEEKER_ITEMS)
player.getInventory().addItem(item);
for(PotionEffect effect : Items.SEEKER_EFFECTS)
player.addPotionEffect(effect);
} else if (board.isHider(player)) {
if (pvpEnabled)
for(ItemStack item : Items.HIDER_ITEMS)
player.getInventory().addItem(item);
for(PotionEffect effect : Items.HIDER_EFFECTS)
player.addPotionEffect(effect);
if (glowEnabled) {
player.getInventory().addItem(glowPowerupItem);
}
}
}
public static void unloadPlayer(Player player){
player.setGameMode(GameMode.ADVENTURE);
player.getInventory().clear();
Main.getInstance().getDisguiser().reveal(player);
for(PotionEffect effect : player.getActivePotionEffects()) {
player.removePotionEffect(effect.getType());
}
if (Main.getInstance().supports(9)) {
AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);
if (attribute != null) player.setHealth(attribute.getValue());
for(Player temp : Main.getInstance().getBoard().getPlayers()) {
Main.getInstance().getGame().getGlow().setGlow(player, temp, false);
}
} else {
player.setHealth(player.getMaxHealth());
}
Main.getInstance().getBoard().getPlayers().forEach(temp -> {
player.showPlayer(temp);
temp.showPlayer(player);
});
player.setAllowFlight(false);
player.setFlying(false);
player.setFallDistance(0.0F);
}
public static void joinPlayer(Player player, Map map){
map.getLobby().teleport(player);
loadPlayer(player);
if (lobbyStartItem != null && (!lobbyItemStartAdmin || player.hasPermission("hideandseek.start")))
player.getInventory().setItem(lobbyItemStartPosition, lobbyStartItem);
if (lobbyLeaveItem != null)
player.getInventory().setItem(lobbyItemLeavePosition, lobbyLeaveItem);
}
private static void loadPlayer(Player player){
player.setFlying(false);
player.setAllowFlight(false);
player.setGameMode(GameMode.ADVENTURE);
player.getInventory().clear();
for(PotionEffect effect : player.getActivePotionEffects()) {
if(effect.getType().getName().equals("INVISIBILITY") && Main.getInstance().getDisguiser().disguised(player)) continue;
player.removePotionEffect(effect.getType());
}
player.setFoodLevel(20);
if (Main.getInstance().supports(9)) {
AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);
if (attribute != null) player.setHealth(attribute.getValue());
} else {
player.setHealth(player.getMaxHealth());
}
}
public static void openBlockHuntPicker(Player player, Map map){
int slots = ((map.getBlockHunt().size()-1)/9)*9+9;
Inventory inventory = Main.getInstance().getServer().createInventory(null, slots, "Select a Block: " + map.getName());
for(int i=0;i<map.getBlockHunt().size();i++){
inventory.setItem(i, new ItemStack(map.getBlockHunt().get(i)));
}
player.openInventory(inventory);
}
}
|