Skip to content

Commit

Permalink
Fixed issues with saving missions to db
Browse files Browse the repository at this point in the history
  • Loading branch information
PeachesMLG committed Aug 4, 2023
1 parent 5d427e3 commit 2afc3b2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,8 @@ public TeamMission getTeamMission(Island island, String missionName) {
if (teamMission.isPresent()) {
return teamMission.get();
} else {
//TODO need to consider reworking this, it could generate some lag
IridiumSkyblock.getInstance().getDatabaseManager().getTeamMissionTableManager().save(newTeamMission);
IridiumSkyblock.getInstance().getDatabaseManager().getTeamMissionTableManager().addEntry(newTeamMission);
return newTeamMission;
}
Expand Down Expand Up @@ -549,7 +551,7 @@ public boolean teleport(Player player, Location location, Island team) {

@Override
public void handleBlockBreakOutsideTerritory(BlockBreakEvent blockEvent) {
if(isInSkyblockWorld(blockEvent.getBlock().getWorld())){
if (isInSkyblockWorld(blockEvent.getBlock().getWorld())) {
blockEvent.getPlayer().sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotBreakBlocks
.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)
));
Expand All @@ -559,7 +561,7 @@ public void handleBlockBreakOutsideTerritory(BlockBreakEvent blockEvent) {

@Override
public void handleBlockPlaceOutsideTerritory(BlockPlaceEvent blockEvent) {
if(isInSkyblockWorld(blockEvent.getBlock().getWorld())){
if (isInSkyblockWorld(blockEvent.getBlock().getWorld())) {
blockEvent.getPlayer().sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotPlaceBlocks
.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)
));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.iridium.iridiumskyblock.managers.tablemanagers;

import com.iridium.iridiumskyblock.IridiumSkyblock;
import com.iridium.iridiumskyblock.SortedList;
import com.iridium.iridiumteams.database.DatabaseObject;
import com.j256.ormlite.dao.Dao;
Expand Down Expand Up @@ -36,19 +35,26 @@ public void save() {
List<T> entryList = new ArrayList<>(entries);
for (T t : entryList) {
if (!t.isChanged()) continue;
try {
dao.createOrUpdate(t);
t.setChanged(false);
} catch (Exception exception) {
IridiumSkyblock.getInstance().getLogger().warning("Failed to save " + t.getClass().getSimpleName() + " to database: " + exception.getMessage());
}
dao.createOrUpdate(t);
t.setChanged(false);
}
dao.commit(getDatabaseConnection());
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}

public void save(T t) {
try {
if (!t.isChanged()) return;
dao.createOrUpdate(t);
dao.commit(getDatabaseConnection());
t.setChanged(false);
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}

public void addEntry(T t) {
entries.add(t);
}
Expand Down

0 comments on commit 2afc3b2

Please sign in to comment.