Skip to content

Commit

Permalink
No more caching player object due to possibility of being null when p…
Browse files Browse the repository at this point in the history
…layer goes offline
  • Loading branch information
Despical committed Nov 16, 2023
1 parent 9e4ec47 commit e8193c8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
4 changes: 2 additions & 2 deletions .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ If you still didn't find an answer see documentation section below.
<dependency>
<groupId>com.github.Despical</groupId>
<artifactId>KOTL</artifactId>
<version>2.7.5</version>
<version>2.7.6</version>
<scope>compile</scope>
</dependency>
```
Expand All @@ -54,7 +54,7 @@ repositories {
```
```
dependencies {
compileOnly group: "com.github.Despical", name: "KOTL", version: "2.7.5;
compileOnly group: "com.github.Despical", name: "KOTL", version: "2.7.6;
}
```
</details>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>me.despical</groupId>
<artifactId>king-of-the-ladder</artifactId>
<version>2.7.5</version>
<version>2.7.6</version>
<name>King of the Ladder</name>
<url>https://www.spigotmc.org/resources/80686/</url>

Expand Down
14 changes: 6 additions & 8 deletions src/main/java/me/despical/kotl/user/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,23 @@ public class User {
private static long cooldownCounter = 0;

private final UUID uuid;
private final Player player;
private final Map<String, Double> cooldowns;
private final Map<StatsStorage.StatisticType, Integer> stats;

private Scoreboard cachedScoreboard;

public User(UUID uuid) {
this.uuid = uuid;
this.player = plugin.getServer().getPlayer(uuid);
this.cooldowns = new HashMap<>();
this.stats = new EnumMap<>(StatsStorage.StatisticType.class);
}

public Arena getArena() {
return plugin.getArenaRegistry().getArena(player);
return plugin.getArenaRegistry().getArena(getPlayer());
}

public Player getPlayer() {
return player;
return plugin.getServer().getPlayer(uuid);
}

public UUID getUniqueId() {
Expand All @@ -83,7 +81,7 @@ public int getStat(StatsStorage.StatisticType statisticType) {
public void setStat(StatsStorage.StatisticType stat, int value) {
stats.put(stat, value);

plugin.getServer().getScheduler().runTask(plugin, () -> plugin.getServer().getPluginManager().callEvent(new KOTLPlayerStatisticChangeEvent(getArena(), player, stat, value)));
plugin.getServer().getScheduler().runTask(plugin, () -> plugin.getServer().getPluginManager().callEvent(new KOTLPlayerStatisticChangeEvent(getArena(), getPlayer(), stat, value)));
}

public void addStat(StatsStorage.StatisticType stat, int value) {
Expand All @@ -95,17 +93,17 @@ public void performReward(final Reward.RewardType rewardType) {
}

public void giveKit() {
plugin.getKitManager().giveKit(player);
plugin.getKitManager().giveKit(getPlayer());
}

public void cacheScoreboard() {
this.cachedScoreboard = this.player.getScoreboard();
this.cachedScoreboard = getPlayer().getScoreboard();
}

public void removeScoreboard() {
if (this.cachedScoreboard == null) return;

this.player.setScoreboard(this.cachedScoreboard);
this.getPlayer().setScoreboard(this.cachedScoreboard);
this.cachedScoreboard = null;
}

Expand Down

0 comments on commit e8193c8

Please sign in to comment.