Skip to content

Commit bdc607b

Browse files
committed
Phase 1: Implementing more events for DEVs
Accidentally did an oopsies with Caching... Bump API core to 31, v0.5.2-BETA Fixed a probable memory leak, perhaps. IslandLevelCalculations are now LIVE! GET MORE BLOCKS.
1 parent e61fee6 commit bdc607b

19 files changed

Lines changed: 289 additions & 68 deletions

src/main/java/com/larryTheCoder/ASkyBlock.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,7 @@
6969
import org.sql2o.data.Table;
7070

7171
import java.io.File;
72-
import java.util.ArrayList;
73-
import java.util.HashMap;
74-
import java.util.Map;
75-
import java.util.Properties;
72+
import java.util.*;
7673

7774
import static com.larryTheCoder.database.TableSet.FETCH_WORLDS;
7875
import static com.larryTheCoder.database.TableSet.WORLDS_INSERT;
@@ -136,7 +133,7 @@ public void onEnable() {
136133
try {
137134
// Wohooo! Fast! Unique and Colorful!
138135
generateLevel();
139-
getServer().getLogger().info(getPrefix() + "§7Loading ASkyBlock - Bedrock Edition (API 30)");
136+
getServer().getLogger().info(getPrefix() + "§7Loading ASkyBlock - Bedrock Edition (API 31)");
140137

141138
// Only defaults
142139
initIslands();

src/main/java/com/larryTheCoder/cache/FastCache.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,12 @@ public void executeQuery(Connection connection) {
8181
if (stmt.rows().size() == 0) return;
8282

8383
for (Row plData : stmt.rows()) {
84-
Date date = Date.from(Timestamp.valueOf(plData.getString("lastLogin")).toInstant());
85-
if (date.compareTo(Date.from(Instant.now())) >= Settings.loadCacheBefore) continue;
84+
// Just an oopsies.
85+
try {
86+
Date date = Date.from(Timestamp.valueOf(plData.getString("lastLogin")).toInstant());
87+
if (date.compareTo(Date.from(Instant.now())) >= Settings.loadCacheBefore) continue;
88+
} catch (Throwable ignored) {
89+
}
8690

8791
String userName = plData.getString("playerName");
8892

src/main/java/com/larryTheCoder/cache/IslandData.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,9 @@ public class IslandData implements Cloneable {
7272
@Setter
7373
private int protectionRange = 0;
7474

75-
@Getter
76-
@Setter
75+
@Getter @Setter
7776
private int levelHandicap = 0;
78-
@Getter
79-
@Setter
77+
@Getter @Setter
8078
private int islandLevel = 0;
8179

8280
// CoopDatabase

src/main/java/com/larryTheCoder/cache/PlayerData.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import org.sql2o.Connection;
3636
import org.sql2o.data.Row;
3737

38-
import java.sql.Date;
38+
import java.sql.Timestamp;
3939
import java.time.Instant;
4040
import java.util.ArrayList;
4141
import java.util.Arrays;
@@ -189,7 +189,7 @@ public void executeQuery(Connection connection) {
189189
.addParameter("locale", locale)
190190
.addParameter("banList", Utils.arrayToString(banList))
191191
.addParameter("resetLeft", resetLeft)
192-
.addParameter("lastLogin", Date.from(Instant.now()))
192+
.addParameter("lastLogin", Timestamp.from(Instant.now()).toString())
193193
.executeUpdate();
194194

195195
connection.createQuery(PLAYER_UPDATE_DATA.getQuery())
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Adapted from the Wizardry License
3+
*
4+
* Copyright (c) 2016-2020 larryTheCoder and contributors
5+
*
6+
* Permission is hereby granted to any persons and/or organizations
7+
* using this software to copy, modify, merge, publish, and distribute it.
8+
* Said persons and/or organizations are not allowed to use the software or
9+
* any derivatives of the work for commercial use or any other means to generate
10+
* income, nor are they allowed to claim this software as their own.
11+
*
12+
* The persons and/or organizations are also disallowed from sub-licensing
13+
* and/or trademarking this software without explicit permission from larryTheCoder.
14+
*
15+
* Any persons and/or organizations using this software must disclose their
16+
* source code and have it publicly available, include this license,
17+
* provide sufficient credit to the original authors of the project (IE: larryTheCoder),
18+
* as well as provide a link to the original project.
19+
*
20+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21+
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR
22+
* PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
25+
* USE OR OTHER DEALINGS IN THE SOFTWARE.
26+
*/
27+
28+
package com.larryTheCoder.events;
29+
30+
import cn.nukkit.event.Cancellable;
31+
import com.larryTheCoder.cache.IslandData;
32+
import lombok.Getter;
33+
import lombok.Setter;
34+
35+
/**
36+
* An event in which the island has successfully calculates their island
37+
* level, this event will be called so that the developers can modify the amount of
38+
* scores that the player's island will get.
39+
*/
40+
public class IslandCalculateFinishEvent extends SkyBlockEvent implements Cancellable {
41+
42+
@Getter
43+
private final int lastLevel;
44+
@Getter @Setter
45+
private int islandLevel;
46+
47+
public IslandCalculateFinishEvent(IslandData island, int islandLevel, int lastLevel) {
48+
super(island);
49+
50+
this.islandLevel = islandLevel;
51+
this.lastLevel = lastLevel;
52+
}
53+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Adapted from the Wizardry License
3+
*
4+
* Copyright (c) 2016-2020 larryTheCoder and contributors
5+
*
6+
* Permission is hereby granted to any persons and/or organizations
7+
* using this software to copy, modify, merge, publish, and distribute it.
8+
* Said persons and/or organizations are not allowed to use the software or
9+
* any derivatives of the work for commercial use or any other means to generate
10+
* income, nor are they allowed to claim this software as their own.
11+
*
12+
* The persons and/or organizations are also disallowed from sub-licensing
13+
* and/or trademarking this software without explicit permission from larryTheCoder.
14+
*
15+
* Any persons and/or organizations using this software must disclose their
16+
* source code and have it publicly available, include this license,
17+
* provide sufficient credit to the original authors of the project (IE: larryTheCoder),
18+
* as well as provide a link to the original project.
19+
*
20+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21+
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR
22+
* PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
25+
* USE OR OTHER DEALINGS IN THE SOFTWARE.
26+
*/
27+
28+
package com.larryTheCoder.events;
29+
30+
import cn.nukkit.event.Cancellable;
31+
import com.larryTheCoder.cache.IslandData;
32+
33+
/**
34+
* An island level calculation event. This event will be called before
35+
* the island is being calculated, you can cancel this event if its needed.
36+
*/
37+
public class IslandCalculateLevelEvent extends SkyBlockEvent implements Cancellable {
38+
public IslandCalculateLevelEvent(IslandData island) {
39+
super(island);
40+
}
41+
}

src/main/java/com/larryTheCoder/events/IslandCreateEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
* @author larryTheCoder
3737
* @author tastybento
3838
*/
39-
public class IslandCreateEvent extends SkyBlockEvent implements Cancellable {
39+
public class IslandCreateEvent extends SkyBlockPlayerEvent implements Cancellable {
4040

4141
private static final HandlerList HANDLERS = new HandlerList();
4242

src/main/java/com/larryTheCoder/events/IslandEnterEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* @author larryTheCoder
3838
* @author tastybento
3939
*/
40-
public class IslandEnterEvent extends SkyBlockEvent {
40+
public class IslandEnterEvent extends SkyBlockPlayerEvent {
4141

4242
/**
4343
* Location of where the player entered the island or tried to enter

src/main/java/com/larryTheCoder/events/IslandExitEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* @author larryTheCoder
3838
* @author tastybento
3939
*/
40-
public class IslandExitEvent extends SkyBlockEvent {
40+
public class IslandExitEvent extends SkyBlockPlayerEvent {
4141

4242
/**
4343
* Location of where the player exited the island's protected area.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Adapted from the Wizardry License
3+
*
4+
* Copyright (c) 2016-2020 larryTheCoder and contributors
5+
*
6+
* Permission is hereby granted to any persons and/or organizations
7+
* using this software to copy, modify, merge, publish, and distribute it.
8+
* Said persons and/or organizations are not allowed to use the software or
9+
* any derivatives of the work for commercial use or any other means to generate
10+
* income, nor are they allowed to claim this software as their own.
11+
*
12+
* The persons and/or organizations are also disallowed from sub-licensing
13+
* and/or trademarking this software without explicit permission from larryTheCoder.
14+
*
15+
* Any persons and/or organizations using this software must disclose their
16+
* source code and have it publicly available, include this license,
17+
* provide sufficient credit to the original authors of the project (IE: larryTheCoder),
18+
* as well as provide a link to the original project.
19+
*
20+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21+
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR
22+
* PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
25+
* USE OR OTHER DEALINGS IN THE SOFTWARE.
26+
*/
27+
28+
package com.larryTheCoder.events;
29+
30+
import cn.nukkit.Player;
31+
import cn.nukkit.event.Cancellable;
32+
import cn.nukkit.level.Location;
33+
import com.larryTheCoder.cache.IslandData;
34+
import lombok.Getter;
35+
import lombok.Setter;
36+
37+
/**
38+
* This event will be called when the player are attempting to teleport to the
39+
* desired island location. The island can be the player's island or another island.
40+
*/
41+
public class IslandTeleportEvent extends SkyBlockPlayerEvent implements Cancellable {
42+
43+
@Getter @Setter
44+
private Location teleportLocation;
45+
46+
public IslandTeleportEvent(Player player, IslandData island, Location targetLocation) {
47+
super(player, island);
48+
49+
this.teleportLocation = targetLocation;
50+
}
51+
}

0 commit comments

Comments
 (0)