-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDungeonManager.java
More file actions
218 lines (181 loc) · 5.26 KB
/
Copy pathDungeonManager.java
File metadata and controls
218 lines (181 loc) · 5.26 KB
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
package net.virtuallyabstract.minecraft;
import org.bukkit.plugin.java.*;
import org.bukkit.plugin.*;
import org.bukkit.event.*;
import org.bukkit.event.player.*;
import org.bukkit.entity.*;
import org.bukkit.inventory.*;
import org.bukkit.*;
import org.bukkit.block.*;
import org.bukkit.command.*;
import java.util.*;
import java.util.concurrent.*;
public class DungeonManager
{
private int width = 3, depth, height = 4;
private ConcurrentHashMap<String, ArrayList<LocationWrapper>> locationMap;
private ConcurrentHashMap<String, ArrayList<LocationWrapper>> triggerMap;
private Server server;
public DungeonManager(Server s, ConcurrentHashMap<String, ArrayList<Dungeon>> dungeonMap)
{
server = s;
locationMap = new ConcurrentHashMap<String, ArrayList<LocationWrapper>>();
triggerMap = new ConcurrentHashMap<String, ArrayList<LocationWrapper>>();
for(String key : dungeonMap.keySet())
{
for(Dungeon d : dungeonMap.get(key))
{
addDungeon(d);
}
}
}
public void addDungeon(Dungeon d)
{
addDungeon(d, false);
}
public void addDungeon(Dungeon d, boolean setMarkers)
{
if(!d.isPublished())
return;
if(d.getTeleporterLocation() != null && d.getStartingLocation() != null)
{
String key = WorldUtils.createLocationKey(d.getTeleporterLocation());
LocationWrapper lwStart = new LocationWrapper(d.getStartingLocation(), LocationWrapper.LocationType.DUNGEON_START, d);
if(!locationMap.containsKey(key))
locationMap.put(key, new ArrayList<LocationWrapper>());
locationMap.get(key).add(lwStart);
Collections.sort(locationMap.get(key));
if(setMarkers)
{
Location loc = d.getTeleporterLocation();
Block b = loc.getBlock();
b.setType(Material.TORCH);
}
}
if(d.getExitLocation() != null && d.getTeleporterLocation() != null)
{
String key = WorldUtils.createLocationKey(d.getExitLocation());
Location l = d.getExitDestination();
LocationWrapper lwExit = new LocationWrapper(l, LocationWrapper.LocationType.DUNGEON_EXIT, d);
if(!locationMap.containsKey(key))
locationMap.put(key, new ArrayList<LocationWrapper>());
locationMap.get(key).add(lwExit);
if(setMarkers)
{
Block b = l.getBlock();
b.setType(Material.REDSTONE_TORCH_ON);
}
}
for(LocationWrapper lw : d.listMonsterTriggers())
{
for(Location loc : lw.getTargetLocations())
{
String key = WorldUtils.createLocationKey(loc);
if(!triggerMap.containsKey(key))
triggerMap.put(key, new ArrayList<LocationWrapper>());
triggerMap.get(key).add(lw);
}
}
for(LocationWrapper lw : d.listSavePoints())
{
for(Location loc : lw.getTargetLocations())
{
String key = WorldUtils.createLocationKey(loc);
if(!triggerMap.containsKey(key))
triggerMap.put(key, new ArrayList<LocationWrapper>());
triggerMap.get(key).add(lw);
}
}
for(LocationWrapper lw : d.listScriptTriggers())
{
for(Location loc : lw.getTargetLocations())
{
String key = WorldUtils.createLocationKey(loc);
if(!triggerMap.containsKey(key))
triggerMap.put(key, new ArrayList<LocationWrapper>());
triggerMap.get(key).add(lw);
}
}
}
public void removeDungeon(Dungeon d)
{
if(d.getTeleporterLocation() != null)
{
String key = WorldUtils.createLocationKey(d.getTeleporterLocation());
ArrayList<LocationWrapper> toRemove = new ArrayList<LocationWrapper>();
if(locationMap.containsKey(key))
{
for(LocationWrapper lw : locationMap.get(key))
{
if(lw.getDungeon().equals(d))
toRemove.add(lw);
}
}
for(LocationWrapper lw : toRemove)
locationMap.get(key).remove(lw);
Collections.sort(locationMap.get(key));
}
if(d.getExitLocation() != null)
{
String key = WorldUtils.createLocationKey(d.getExitLocation());
ArrayList<LocationWrapper> toRemove = new ArrayList<LocationWrapper>();
if(locationMap.containsKey(key))
{
for(LocationWrapper lw : locationMap.get(key))
{
if(lw.getDungeon().equals(d))
toRemove.add(lw);
}
}
for(LocationWrapper lw : toRemove)
locationMap.get(key).remove(lw);
}
for(LocationWrapper lw : d.listMonsterTriggers())
{
for(Location loc : lw.getTargetLocations())
{
String key = WorldUtils.createLocationKey(loc);
if(!triggerMap.containsKey(key))
return;
triggerMap.get(key).remove(lw);
}
}
for(LocationWrapper lw : d.listSavePoints())
{
for(Location loc : lw.getTargetLocations())
{
String key = WorldUtils.createLocationKey(loc);
if(!triggerMap.containsKey(key))
return;
triggerMap.get(key).remove(lw);
}
}
for(LocationWrapper lw : d.listScriptTriggers())
{
for(Location loc : lw.getTargetLocations())
{
String key = WorldUtils.createLocationKey(loc);
if(!triggerMap.containsKey(key))
return;
triggerMap.get(key).remove(lw);
}
}
}
//public Location getStartingLocation()
//{
// return world.getSpawnLocation();
//}
public ArrayList<LocationWrapper> checkLocation(Location loc)
{
String key = WorldUtils.createLocationKey(loc);
ArrayList<LocationWrapper> retVal = new ArrayList<LocationWrapper>();
if(locationMap.containsKey(key))
{
Collections.sort(locationMap.get(key));
retVal.addAll(locationMap.get(key));
}
if(triggerMap.containsKey(key))
retVal.addAll(triggerMap.get(key));
return retVal;
}
}