summaryrefslogtreewikicommitdiff
path: root/src/main/java/net/tylermurphy/hideAndSeek/configuration/Map.java
blob: 8c3f8a75a5f3ab44b141337210b80f8303bb1b68 (plain)
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
package net.tylermurphy.hideAndSeek.configuration;

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

import net.tylermurphy.hideAndSeek.game.events.Border;
import net.tylermurphy.hideAndSeek.world.WorldLoader;
import net.tylermurphy.hideAndSeek.util.Location;
import org.bukkit.*;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;

import static net.tylermurphy.hideAndSeek.configuration.Config.*;

public class Map {

  private final String name;

  private Location 
    spawnPosition = Location.getDefault(),
    lobbyPosition = Location.getDefault(),
    seekerLobbyPosition = Location.getDefault();

  private int 
    xBoundMin = 0,
    zBoundMin = 0,
    xBoundMax = 0,
    zBoundMax = 0,
    xWorldBorder = 0,
    zWorldBorder = 0,
    worldBorderSize = 0,
    worldBorderDelay = 0,
    worldBorderChange = 0;

  private boolean
    blockhunt = false;

  private List<Material>
    blockhuntBlocks = new ArrayList<>();

  private final Border
    worldBorder;

  private final WorldLoader
    worldLoader;

  public Map(String name) {
    this.name = name;
    this.worldBorder = new Border(this);
    this.worldLoader = new WorldLoader(this);
  }

  public void setSpawn(Location pos) {
    this.spawnPosition = pos;
  }

  public void setLobby(Location pos) {
    this.lobbyPosition = pos;
  }

  public void setSeekerLobby(Location pos) {
    this.seekerLobbyPosition = pos;
  }

  public void setWorldBorderData(int x, int z, int size, int delay, int move) {
    if(size < 1) {
      this.worldBorderSize = 0;
      this.worldBorderDelay = 0;
      this.worldBorderChange = 0;
      this.xWorldBorder = 0;
      this.zWorldBorder = 0;
    } else {
      this.worldBorderSize = size;
      this.worldBorderDelay = delay;
      this.worldBorderChange = move;
      this.xWorldBorder = x;
      this.zWorldBorder = z;
    }
    this.worldBorder.resetWorldBorder();
  }

  public void setBlockhunt(boolean enabled, List<Material> blocks) {
    this.blockhunt = enabled;
    this.blockhuntBlocks = blocks;
  }

  public void setBoundMin(int x, int z) {
    this.xBoundMin = x;
    this.zBoundMin = z;
  }

  public void setBoundMax(int x, int z) {
    this.xBoundMax = x;
    this.zBoundMax = z;
  }

  @NotNull
  public Location getGameSpawn() {
    if(mapSaveEnabled) {
      return spawnPosition.changeWorld("hs_"+name);
    } else {
      return spawnPosition;
    }
  }

  @NotNull
  public String getGameSpawnName() {
    if(mapSaveEnabled)
      return getGameSpawn().getWorld();
    else
      return getSpawn().getWorld();
  }

  @NotNull
  public Location getSpawn() {
    return spawnPosition;
  }

  @NotNull
  public String getSpawnName() {
    return getSpawn().getWorld();
  }

  @NotNull
  public Location getLobby() {
    return lobbyPosition;
  }

  @NotNull
  public String getLobbyName() {
    return getLobby().getWorld();
  }

  @NotNull
  public Location getSeekerLobby() {
    return seekerLobbyPosition;
  }

  @NotNull
  public String getSeekerLobbyName() {
    return getSeekerLobby().getWorld();
  }

  @NotNull
  public Location getGameSeekerLobby() {
    if(mapSaveEnabled) {
      return seekerLobbyPosition.changeWorld("hs_"+name);
    } else {
      return seekerLobbyPosition;
    }
  }

  public boolean isWorldBorderEnabled() {
    return worldBorderSize > 0;
  }

  @NotNull
  public Vector getWorldBorderPos() {
    return new Vector(
      xWorldBorder,
      0,
      zWorldBorder
    );
  }

  @NotNull
  public Vector getWorldBorderData() {
    return new Vector(
      worldBorderSize,
      worldBorderDelay,
      worldBorderChange
    );
  }

  @NotNull
  public Border getWorldBorder() {
    return worldBorder;
  }

  public boolean isBlockHuntEnabled() {
    return blockhunt;
  }

  @NotNull
  public List<Material> getBlockHunt() {
    return blockhuntBlocks;
  }

  @NotNull
  public Vector getBoundsMin() {
    return new Vector(
      xBoundMin,
      0,
      zBoundMin
    );
  }

  @NotNull
  public Vector getBoundsMax() {
    return new Vector(
      xBoundMax,
      0,
      zBoundMax
    );
  }

  @NotNull
  public String getName() {
    return name;
  }

  @NotNull
  public WorldLoader getWorldLoader() {
    return worldLoader;
  }

  public boolean isNotSetup() {
    if (spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0 || !spawnPosition.exists()) return true;
    if (lobbyPosition.getBlockX() == 0 && lobbyPosition.getBlockY() == 0 && lobbyPosition.getBlockZ() == 0 || !lobbyPosition.exists()) return true;
    if (exitPosition == null || exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0 || !exitPosition.exists()) return true;
    if (seekerLobbyPosition.getBlockX() == 0 && seekerLobbyPosition.getBlockY() == 0 && seekerLobbyPosition.getBlockZ() == 0 || !seekerLobbyPosition.exists()) return true;
    if (mapSaveEnabled && !getGameSpawn().exists()) return true;
    if (blockhunt && blockhuntBlocks.isEmpty()) return true;
    if(isWorldBorderEnabled() &&
        new Vector(spawnPosition.getX(), 0, spawnPosition.getZ()).distance(new Vector(xWorldBorder, 0, zWorldBorder)) > 100) return true;
    return xBoundMin == 0 || zBoundMin == 0 || xBoundMax == 0 || zBoundMax == 0;
  }

  public boolean isSpawnNotSetup() {
    return spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0;
  }

  public boolean isBoundsNotSetup() {
    return xBoundMin == 0 || zBoundMin == 0 || xBoundMax == 0 || zBoundMax == 0;
  }

}