Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Team logs #872

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,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 @@ -230,6 +231,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,12 +11,14 @@
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.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 @@ -97,6 +99,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 @@ -31,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 @@ -77,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 @@ -509,6 +509,21 @@ private CompletableFuture<Integer> getSpawnerStackAmount(CreatureSpawner creatur
return completableFuture;
}

@Override
public List<TeamLog> getTeamLogs(Island island) {
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
public CompletableFuture<Void> recalculateTeam(Island island) {
Map<XMaterial, Integer> teamBlocks = new HashMap<>();
Expand Down