Skip to content

Commit

Permalink
Added Team Logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Faun471 committed Jun 25, 2024
1 parent 92bd1b9 commit 370a128
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ public void registerListeners() {
Bukkit.getPluginManager().registerEvents(new PlayerJoinListener(), this);
Bukkit.getPluginManager().registerEvents(new BlockFormListener(), this);
Bukkit.getPluginManager().registerEvents(new EnhancementUpdateListener(), this);
Bukkit.getPluginManager().registerEvents(new SettingUpdateListener(), this);
Bukkit.getPluginManager().registerEvents(new PlayerTeleportListener(), this);
Bukkit.getPluginManager().registerEvents(new PlayerPortalListener(), this);
Bukkit.getPluginManager().registerEvents(new PlayerInteractListener(), this);
Expand Down Expand Up @@ -228,6 +229,7 @@ public void saveData() {
getDatabaseManager().getTeamRewardsTableManager().save();
getDatabaseManager().getTeamSettingsTableManager().save();
getDatabaseManager().getLostItemsTableManager().save();
getDatabaseManager().getTeamLogsTableManager().save();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
import com.iridium.iridiumteams.IridiumTeams;
import com.iridium.iridiumteams.commands.Command;
import com.iridium.iridiumteams.database.IridiumUser;
import com.iridium.iridiumteams.database.TeamLog;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -66,6 +68,16 @@ public boolean execute(User user, Island island, String[] args, IridiumTeams<Isl
))
);

IridiumSkyblock.getInstance().getTeamManager().addTeamLog(new TeamLog(
island,
player.getUniqueId(),
"change_border",
1,
player.getLocation(),
LocalDateTime.now(),
color.toString()
));

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
import com.iridium.iridiumteams.bank.BankItem;
import com.iridium.iridiumteams.commands.Command;
import com.iridium.iridiumteams.database.TeamBank;
import com.iridium.iridiumteams.database.TeamLog;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -98,6 +100,16 @@ public boolean execute(User user, Island island, String[] args, IridiumTeams<Isl
}
}));

IridiumSkyblock.getInstance().getTeamManager().addTeamLog(new TeamLog(
island,
player.getUniqueId(),
"regen_island",
1,
player.getLocation(),
LocalDateTime.now(),
schematic.get()
));

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
import com.iridium.iridiumskyblock.database.Island;
import com.iridium.iridiumskyblock.database.User;
import com.iridium.iridiumteams.api.EnhancementUpdateEvent;
import com.iridium.iridiumteams.database.TeamLog;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;

import java.time.LocalDateTime;

public class EnhancementUpdateListener implements Listener {

@EventHandler
Expand All @@ -17,6 +20,16 @@ public void onEnhancementUpdateEvent(EnhancementUpdateEvent<Island, User> event)
IridiumSkyblock.getInstance().getTeamManager().getMembersOnIsland(event.getTeam()).forEach(user -> IridiumSkyblock.getInstance().getTeamManager().sendIslandBorder(user.getPlayer()))
);
}

IridiumSkyblock.getInstance().getTeamManager().addTeamLog(new TeamLog(
event.getTeam(),
event.getUser().getPlayer().getUniqueId(),
"enhancement_update",
1,
event.getUser().getPlayer().getLocation(),
LocalDateTime.now(),
event.getEnhancement()
));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.iridium.iridiumskyblock.listeners;

import com.iridium.iridiumskyblock.IridiumSkyblock;
import com.iridium.iridiumskyblock.database.Island;
import com.iridium.iridiumskyblock.database.User;
import com.iridium.iridiumteams.api.SettingUpdateEvent;
import com.iridium.iridiumteams.database.TeamLog;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;

import java.time.LocalDateTime;

public class SettingUpdateListener implements Listener {

@EventHandler
public void onSettingUpdateEvent(SettingUpdateEvent<Island, User> event) {
IridiumSkyblock.getInstance().getTeamManager().addTeamLog(new TeamLog(
event.getTeam(),
event.getUser().getPlayer().getUniqueId(),
"setting_update",
1,
event.getUser().getPlayer().getLocation(),
LocalDateTime.now(),
event.getSetting() + ": " + event.getValue()
));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
import com.iridium.iridiumskyblock.database.User;
import com.iridium.iridiumteams.database.IridiumUser;
import com.iridium.iridiumteams.database.TeamBank;
import com.iridium.iridiumteams.database.TeamLog;
import net.milkbowl.vault.economy.Economy;
import org.apache.commons.lang.WordUtils;
import org.bukkit.entity.Player;

import java.time.LocalDateTime;
import java.util.Optional;

public class BiomeManager {
Expand Down Expand Up @@ -57,6 +59,16 @@ public void buy(Player player, Biomes.BiomeItem biomeItem) {
});
IridiumSkyblock.getInstance().getBiomes().successSound.play(player);

IridiumSkyblock.getInstance().getTeamManager().addTeamLog(new TeamLog(
island.get(),
player.getUniqueId(),
"biome_change",
biomeItem.buyCost.money,
player.getLocation(),
LocalDateTime.now(),
biome.toString()
));

}

private double getBankBalance(Player player, String bankItem) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import java.io.File;
import java.sql.SQLException;
import java.util.Comparator;
import java.util.concurrent.CompletableFuture;

@Getter
Expand All @@ -32,6 +31,7 @@ public class DatabaseManager {
private IslandTableManager islandTableManager;
private LostItemsTableManager lostItemsTableManager;
private TableManager<String, TeamMissionData, Integer> teamMissionDataTableManager;
private TableManager<Integer, TeamLog, Integer> teamLogsTableManager;
private ForeignIslandTableManager<String, TeamInvite> invitesTableManager;
private ForeignIslandTableManager<String, TeamTrust> trustTableManager;
private ForeignIslandTableManager<String, TeamPermission> permissionsTableManager;
Expand Down Expand Up @@ -78,6 +78,7 @@ public void init() throws SQLException {
this.teamMissionTableManager = new ForeignIslandTableManager<>(teamMission -> getDatabaseKey(teamMission.getTeamID(), teamMission.getMissionName()), connectionSource, TeamMission.class);
this.teamRewardsTableManager = new ForeignIslandTableManager<>(teamRewards -> getDatabaseKey(teamRewards.getId()), connectionSource, TeamReward.class);
this.teamSettingsTableManager = new ForeignIslandTableManager<>(teamSetting -> getDatabaseKey(teamSetting.getTeamID(), teamSetting.getSetting()), connectionSource, TeamSetting.class);
this.teamLogsTableManager = new TableManager<>(TeamLog::getId, connectionSource, TeamLog.class);
}

private String getDatabaseKey(Object... params) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,12 +511,17 @@ private CompletableFuture<Integer> getSpawnerStackAmount(CreatureSpawner creatur

@Override
public List<TeamLog> getTeamLogs(Island island) {
return null;
return IridiumSkyblock.getInstance().getDatabaseManager().getTeamLogsTableManager().getEntries()
.stream().filter(teamLog -> teamLog.getTeamID() == island.getId()).collect(Collectors.toList());
}

@Override
public void addTeamLog(TeamLog teamLog) {
IridiumSkyblock.getInstance().getDatabaseManager().getTeamLogsTableManager().addEntry(teamLog);

Bukkit.getScheduler().runTaskAsynchronously(IridiumSkyblock.getInstance(), () -> {
IridiumSkyblock.getInstance().getDatabaseManager().getTeamLogsTableManager().save(teamLog);
});
}

@Override
Expand Down

0 comments on commit 370a128

Please sign in to comment.