2
2
3
3
import com .boydti .fawe .FaweAPI ;
4
4
import com .boydti .fawe .object .schematic .Schematic ;
5
+ import com .google .common .io .Files ;
5
6
import com .sk89q .worldedit .Vector ;
6
7
import com .sk89q .worldedit .extent .clipboard .Clipboard ;
7
8
import com .sk89q .worldedit .extent .clipboard .ClipboardFormats ;
8
9
import com .sk89q .worldedit .extent .clipboard .io .ClipboardFormat ;
9
10
import com .sk89q .worldedit .regions .CuboidRegion ;
11
+ import lombok .AccessLevel ;
12
+ import lombok .Getter ;
10
13
import me .illusion .skyblockcore .CorePlugin ;
11
14
import me .illusion .skyblockcore .island .Island ;
12
15
import me .illusion .skyblockcore .island .IslandData ;
16
+ import me .illusion .skyblockcore .island .grid .GridCell ;
13
17
import me .illusion .skyblockcore .sql .SQLSerializer ;
14
18
import org .bukkit .Bukkit ;
15
19
import org .bukkit .Location ;
21
25
import java .sql .PreparedStatement ;
22
26
import java .sql .ResultSet ;
23
27
import java .sql .SQLException ;
24
- import java .util .Arrays ;
28
+ import java .util .ArrayList ;
25
29
import java .util .UUID ;
26
30
import java .util .concurrent .CompletableFuture ;
27
31
28
- public class SkyblockPlayer {
32
+ import static me . illusion . skyblockcore . sql . SQLOperation .*;
29
33
30
- private static final String SAVE_SERIALIZED = "INSERT INTO uuid_data(uuid, id) VALUES (?, ?)" ;
31
- private static final String GET_SERIALIZED = "SELECT id FROM uuid_data WHERE uuid = ?" ;
32
- private static final String LOAD_ISLAND = "SELECT id FROM island_data WHERE uuid = ?" ;
33
- private static final String SAVE_ISLAND = "INSERT INTO island_data(uuid, id) VALUES (?, ?)" ;
34
+ @ Getter
35
+ public class SkyblockPlayer {
34
36
37
+ @ Getter (AccessLevel .NONE )
35
38
private final CorePlugin main ;
36
39
37
40
private final UUID uuid ;
@@ -44,30 +47,41 @@ public SkyblockPlayer(CorePlugin main, UUID uuid) {
44
47
this .uuid = uuid ;
45
48
46
49
CompletableFuture .runAsync (() -> {
50
+ File target = null ;
47
51
IslandData islandData = null ;
48
52
if (!this .load ()) {
49
53
System .out .println ("Inicializing Data" );
50
54
data = new PlayerData ();
51
55
System .out .println ("Loading cache" );
56
+ target = new File (main .getDataFolder () + File .separator + "cache" , uuid .toString () + ".schematic" );
57
+ try {
58
+ target .getParentFile ().mkdirs ();
59
+ target .createNewFile ();
60
+ Files .copy (main .getStartSchematic (), target );
61
+ } catch (IOException e ) {
62
+ e .printStackTrace ();
63
+ }
52
64
53
65
System .out .println ("Creating island data" );
54
- islandData = new IslandData (Arrays . asList ( uuid ), uuid );
66
+ islandData = new IslandData (null , uuid . toString ( ), uuid , new ArrayList <>() );
55
67
56
68
System .out .println ("Setting final data" );
57
- data .setIslandSchematic (main . getStartSchematic () );
69
+ data .setIslandSchematic (target );
58
70
data .setMoney (0 );
59
- data .setInventory (getPlayer ().getInventory ().getContents ());
71
+ data .getInventory (). updateArray (getPlayer ().getInventory ().getContents ());
60
72
}
61
73
62
74
IslandData finalIslandData = islandData ;
75
+ File finalTarget = target ;
63
76
Bukkit .getScheduler ().runTask (main , () -> {
64
77
65
78
System .out .println ("Loading island" );
66
- island = loadIsland (finalIslandData , main .getIslandConfig ().getNetherSettings ().getBukkitWorld (), data .getIslandSchematic ());
79
+ island = loadIsland (finalIslandData , main .getIslandConfig ().getOverworldSettings ().getBukkitWorld (), finalTarget );
80
+ finalIslandData .setIsland (island );
67
81
68
82
System .out .println ("Running update task" );
69
83
70
- data .setLastLocation (island .getCenter ());
84
+ data .getLastLocation (). update (island .getCenter ());
71
85
checkTeleport ();
72
86
updateInventory ();
73
87
saveIsland ();
@@ -90,7 +104,7 @@ private boolean load() {
90
104
91
105
IslandData islandData = (IslandData ) load (LOAD_ISLAND );
92
106
93
- getPlayer ().teleport (data .getLastLocation ());
107
+ getPlayer ().teleport (data .getLastLocation (). getLocation () );
94
108
95
109
for (UUID uuid : islandData .getUsers ())
96
110
if (Bukkit .getPlayer (uuid ) != null ) {
@@ -112,18 +126,22 @@ private void checkTeleport() {
112
126
World world = main .getIslandConfig ().getOverworldSettings ().getBukkitWorld ();
113
127
114
128
String worldName = world .getName ();
115
- String targetName = data .getLastLocation ().getWorld ().getName ();
129
+ String targetName = data .getLastLocation ().getLocation (). getWorld ().getName ();
116
130
117
131
if (worldName .equalsIgnoreCase (targetName ))
118
- getPlayer ().teleport (data .getLastLocation ().add (island .getCenter ()));
132
+ getPlayer ().teleport (data .getLastLocation ().getLocation (). add (island .getCenter ()));
119
133
else
120
- getPlayer ().teleport (data .getLastLocation ());
134
+ getPlayer ().teleport (data .getLastLocation (). getLocation () );
121
135
}
122
136
123
137
private Island loadIsland (IslandData data , World world , File schem ) {
124
138
Location one = null ;
125
139
Location two = null ;
126
140
Location center = null ;
141
+ GridCell cell = main .getGrid ().getFirstCell ();
142
+
143
+ cell .setOccupied (true );
144
+
127
145
try {
128
146
Schematic schematic = ClipboardFormat .SCHEMATIC .load (schem );
129
147
Clipboard clipboard = schematic .getClipboard ();
@@ -132,13 +150,26 @@ private Island loadIsland(IslandData data, World world, File schem) {
132
150
two = new Location (world , clipboard .getMaximumPoint ().getBlockX (), clipboard .getMaximumPoint ().getBlockY (), clipboard .getMaximumPoint ().getBlockZ ());
133
151
center = new Location (world , clipboard .getOrigin ().getBlockX (), clipboard .getOrigin ().getBlockY (), clipboard .getOrigin ().getBlockZ ());
134
152
135
- schematic .paste (FaweAPI .getWorld (world .getName ()), clipboard .getOrigin (), false );
153
+ int distance = main .getIslandConfig ().getOverworldSettings ().getDistance ();
154
+ center = center .add (cell .getXPos () * distance , 0 , cell .getYPos () * distance );
155
+ one = one .add (cell .getXPos () * distance , 0 , cell .getYPos () * distance );
156
+ two = two .add (cell .getXPos () * distance , 0 , cell .getYPos () * distance );
136
157
137
- } catch (IOException e ) {
158
+ Bukkit .getLogger ().info (String .format ("Pasting island at %s %s %s (%s)" , center .getX (), center .getY (), center .getZ (), center .getWorld ().getName ()));
159
+ schematic .paste (
160
+ FaweAPI .getWorld (
161
+ world .getName ()),
162
+ clipboard .getOrigin (),
163
+ false );
164
+
165
+
166
+ } catch (Exception e ) {
138
167
e .printStackTrace ();
139
168
}
140
169
141
- return new Island (one , two , center , data );
170
+ Bukkit .broadcastMessage ("post-paste" );
171
+
172
+ return new Island (one , two , center , data , cell );
142
173
}
143
174
144
175
private Object load (String sql ) {
@@ -162,12 +193,14 @@ private Object load(String sql) {
162
193
// ----- DATA SAVING -----
163
194
164
195
public void save () {
165
- data .setInventory (getPlayer ().getInventory ().getContents ());
196
+ data .getInventory (). updateArray (getPlayer ().getInventory ().getContents ());
166
197
saveIsland ();
167
198
CompletableFuture .runAsync (() -> saveObject (data , SAVE_SERIALIZED ));
168
199
169
200
if (island .getData ().getUsers ().stream ().noneMatch (uuid -> !this .uuid .equals (uuid ) && Bukkit .getPlayer (uuid ) == null ))
170
201
island .cleanIsland ();
202
+
203
+ data .getIslandSchematic ().delete ();
171
204
}
172
205
173
206
private void saveObject (Object object , String SQL ) {
@@ -179,7 +212,7 @@ private void saveObject(Object object, String SQL) {
179
212
statement .setString (1 , uuid .toString ());
180
213
statement .setLong (2 , id );
181
214
182
- statement .execute ();
215
+ statement .executeUpdate ();
183
216
} catch (SQLException e ) {
184
217
e .printStackTrace ();
185
218
}
@@ -191,7 +224,7 @@ private void updateInventory() {
191
224
if (data == null )
192
225
getPlayer ().getInventory ().clear ();
193
226
194
- getPlayer ().getInventory ().setContents (data .getInventory ());
227
+ getPlayer ().getInventory ().setContents (data .getInventory (). getArray () );
195
228
}
196
229
197
230
// ----- DATA PRE-SAVE -----
0 commit comments