Skip to content

Commit

Permalink
Merge branch 'master' into ocean-generator-&-others
Browse files Browse the repository at this point in the history
  • Loading branch information
PeachesMLG authored Dec 28, 2024
2 parents 5d64c01 + a8b32b7 commit 843027a
Show file tree
Hide file tree
Showing 14 changed files with 458 additions and 79 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected].1
- uses: actions/[email protected].2
- uses: gradle/wrapper-validation-action@v3
- name: Set up JDK 17
uses: actions/setup-java@v4.4.0
uses: actions/setup-java@v4.6.0
with:
distribution: temurin
java-version: 17
Expand All @@ -25,7 +25,7 @@ jobs:
- name: Build with Gradle
run: ./gradlew build
- name: Upload artifacts
uses: "actions/upload-artifact@v4.4.1"
uses: "actions/upload-artifact@v4.5.0"
with:
name: "IridiumSkyblock"
path: "build/libs/IridiumSkyblock-*.jar"
Expand Down
12 changes: 6 additions & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
java
`maven-publish`
id("com.github.johnrengelman.shadow") version "8.1.1"
id("io.github.goooler.shadow") version "8.1.8"
id("net.minecrell.plugin-yml.bukkit") version "0.6.0"
}

Expand All @@ -22,21 +22,21 @@ repositories {

dependencies {
// Dependencies that we want to shade in
implementation("org.jetbrains:annotations:25.0.0")
implementation("org.jetbrains:annotations:26.0.1")
implementation("com.j256.ormlite:ormlite-core:6.1")
implementation("com.j256.ormlite:ormlite-jdbc:6.1")
implementation("com.iridium:IridiumTeams:2.5.9")
implementation("com.iridium:IridiumTeams:2.5.9.8")
implementation("commons-lang:commons-lang:2.6")

// Other dependencies that are not required or already available at runtime
compileOnly("org.projectlombok:lombok:1.18.34")
compileOnly("org.spigotmc:spigot-api:1.21.1-R0.1-SNAPSHOT")
compileOnly("org.projectlombok:lombok:1.18.36")
compileOnly("org.spigotmc:spigot-api:1.21.4-R0.1-SNAPSHOT")
compileOnly("com.github.MilkBowl:VaultAPI:1.7.1")
compileOnly("net.ess3:EssentialsXSpawn:2.16.1")
compileOnly("com.sk89q.worldedit:worldedit-bukkit:7.2.13-SNAPSHOT")

// Enable lombok annotation processing
annotationProcessor("org.projectlombok:lombok:1.18.34")
annotationProcessor("org.projectlombok:lombok:1.18.36")
}

bukkit {
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
3 changes: 1 addition & 2 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,276 @@
package com.iridium.iridiumskyblock.commands;

import com.iridium.iridiumcore.utils.StringUtils;
import com.iridium.iridiumskyblock.IridiumSkyblock;
import com.iridium.iridiumskyblock.database.Island;
import com.iridium.iridiumskyblock.database.User;
import com.iridium.iridiumskyblock.managers.DatabaseManager;
import com.iridium.iridiumskyblock.managers.tablemanagers.*;
import com.iridium.iridiumteams.IridiumTeams;
import com.iridium.iridiumteams.commands.Command;
import com.iridium.iridiumteams.database.*;
import com.iridium.iridiumteams.gui.ConfirmationGUI;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;

public class ClearDataCommand extends Command < Island, User > {

public ClearDataCommand() {
super(Collections.singletonList("cleardata"), "Deletes data from database", "%prefix% &7/is cleardata <table> <team> --skip-confirm", "iridiumSkyblock.clearData", 10);
}

@Override
public boolean execute(CommandSender sender, String[] args, IridiumTeams < Island, User > iridiumTeams) {
DataTable table = DataTable.ALL;
boolean skipConfirmation = false;
Optional < Island > island = Optional.empty();

if (args.length == 0 || Arrays.stream(DataTable.values()).noneMatch(dataTable -> dataTable.name().equalsIgnoreCase(args[0]))) {
sender.sendMessage(StringUtils.color(syntax.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}

switch (args.length) {
case 2: {
if (!args[1].equalsIgnoreCase("--skip-confirm")) {
island = IridiumSkyblock.getInstance().getIslandManager().getTeamViaNameOrPlayer(args[1]);
if (!island.isPresent()) {
sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().teamDoesntExistByName
.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
}
}
case 1: {
try {
if (Arrays.stream(DataTable.values()).anyMatch(dataTable -> dataTable.name().equalsIgnoreCase(args[0])))
table = DataTable.valueOf(args[0]);
} catch (IllegalArgumentException e) {
IridiumSkyblock.getInstance().getLogger().warning(e.getMessage());
return false;
}
}
}

if (Arrays.stream(args).anyMatch(argument -> argument.equalsIgnoreCase("--skip-confirm")))
skipConfirmation = true;

if (sender instanceof Player && !skipConfirmation) {
confirmDataDeletion((Player) sender, island, table);
return true;
}
deleteData(sender, island, table);

return true;
}

private void confirmDataDeletion(Player player, Optional < Island > island, DataTable table) {
String islandName = "ALL";
if (island.isPresent()) islandName = island.get().getName() + " (" + island.get().getOwner().get().getName() + ")";
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().confirmDataDeletion
.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)
.replace("%table%", table.name())
.replace("%island%", islandName)));

player.openInventory(new ConfirmationGUI < > (() -> deleteData(player, island, table), IridiumSkyblock.getInstance()).getInventory());
}

private CompletableFuture < Void > deleteData(CommandSender sender, Optional < Island > island, DataTable table) {
return CompletableFuture.runAsync(() -> {

if (!backupDatabaseFile()) return;

List < Island > islands = new ArrayList < > ();
if (!island.isPresent()) {
islands = IridiumSkyblock.getInstance().getIslandManager().getTeams();
} else islands.add(island.get());

boolean all = table == DataTable.ALL;

DatabaseManager databaseManager = IridiumSkyblock.getInstance().getDatabaseManager();

try {
switch (table) {
case ALL:
case ISLAND: {
databaseManager.getIslandTableManager().delete(islands).join();
if (!all) break;
}
case INVITE: {
ForeignIslandTableManager < String, TeamInvite > inviteTableManager = databaseManager.getInvitesTableManager();
for (Island islandEntry: islands) {
for (TeamInvite teamInvite: inviteTableManager.getEntries(islandEntry)) {
inviteTableManager.delete(teamInvite).join();
}
}
if (!all) break;
}
case TRUST: {
ForeignIslandTableManager < String, TeamTrust > trustTableManager = databaseManager.getTrustTableManager();
for (Island islandEntry: islands) {
for (TeamTrust teamTrust: trustTableManager.getEntries(islandEntry)) {
trustTableManager.delete(teamTrust).join();
}
}
if (!all) break;
}
case PERMISSION: {
ForeignIslandTableManager < String, TeamPermission > permissionTableManager = databaseManager.getPermissionsTableManager();
for (Island islandEntry: islands) {
for (TeamPermission teamPermission: permissionTableManager.getEntries(islandEntry)) {
permissionTableManager.delete(teamPermission).join();
}
}
if (!all) break;
}
case BANK: {
ForeignIslandTableManager < String, TeamBank > bankTableManager = databaseManager.getBankTableManager();
for (Island islandEntry: islands) {
for (TeamBank teamBank: bankTableManager.getEntries(islandEntry)) {
bankTableManager.delete(teamBank).join();
}
}
if (!all) break;
}
case ENHANCEMENT: {
ForeignIslandTableManager < String, TeamEnhancement > enhancementTableManager = databaseManager.getEnhancementTableManager();
for (Island islandEntry: islands) {
for (TeamEnhancement teamEnhancement: enhancementTableManager.getEntries(islandEntry)) {
enhancementTableManager.delete(teamEnhancement).join();
}
}
if (!all) break;
}
case TEAM_BLOCK: {
ForeignIslandTableManager < String, TeamBlock > blockTableManager = databaseManager.getTeamBlockTableManager();
for (Island islandEntry: islands) {
for (TeamBlock teamBlock: blockTableManager.getEntries(islandEntry)) {
blockTableManager.delete(teamBlock).join();
}
}
if (!all) break;
}
case TEAM_SPAWNER: {
ForeignIslandTableManager < String, TeamSpawners > spawnerTableManager = databaseManager.getTeamSpawnerTableManager();
for (Island islandEntry: islands) {
for (TeamSpawners teamSpawners: spawnerTableManager.getEntries(islandEntry)) {
spawnerTableManager.delete(teamSpawners).join();
}
}
if (!all) break;
}
case TEAM_WARP: {
ForeignIslandTableManager < String, TeamWarp > warpTableManager = databaseManager.getTeamWarpTableManager();
for (Island islandEntry: islands) {
for (TeamWarp teamWarp: warpTableManager.getEntries(islandEntry)) {
warpTableManager.delete(teamWarp).join();
}
}
if (!all) break;
}
case TEAM_MISSION: {
ForeignIslandTableManager < String, TeamMission > missionTableManager = databaseManager.getTeamMissionTableManager();
for (Island islandEntry: islands) {
for (TeamMission teamMission: missionTableManager.getEntries(islandEntry)) {
IridiumSkyblock.getInstance().getIslandManager().deleteTeamMission(teamMission);
IridiumSkyblock.getInstance().getIslandManager().deleteTeamMissionData(teamMission);
}
}
if (!all) break;
}

case TEAM_REWARDS: {
ForeignIslandTableManager < String, TeamReward > rewardTableManager = databaseManager.getTeamRewardsTableManager();
for (Island islandEntry: islands) {
for (TeamReward teamReward: rewardTableManager.getEntries(islandEntry)) {
rewardTableManager.delete(teamReward).join();
}
}
if (!all) break;
}
case TEAM_SETTINGS: {
ForeignIslandTableManager < String, TeamSetting > settingTableManager = databaseManager.getTeamSettingsTableManager();
for (Island islandEntry: islands) {
for (TeamSetting teamSetting: settingTableManager.getEntries(islandEntry)) {
settingTableManager.delete(teamSetting).join();
}
}
}
}
} catch (Exception e) {
IridiumSkyblock.getInstance().getLogger().warning(e.getMessage());
return;
}

sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().dataDeletion
.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
});
}

private boolean backupDatabaseFile() {
IridiumSkyblock.getInstance().getLogger().info("Creating a backup for IridiumSkyblock.db in \"backups\" folder...");

File pluginFolder = new File(IridiumSkyblock.getInstance().getDataFolder().getPath());
File file = new File(pluginFolder + File.separator + "IridiumSkyblock.db");
File backupFolder = new File(pluginFolder.getPath() + File.separator + "backups");
File backupDatabaseFile = new File(backupFolder + File.separator + file.getName());

try {
if (!backupFolder.exists()) backupFolder.mkdir();
Files.copy(file.toPath(), backupDatabaseFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
IridiumSkyblock.getInstance().getLogger().info("Success! Backup \"IridiumSkyblock.db\" created, check \"" + backupFolder.getPath() + "\".");
return true;
} catch (IOException exception) {
IridiumSkyblock.getInstance().getLogger().severe("Failed to move \"IridiumSkyblock.db\" to " + backupFolder + ": " +
exception.getMessage());
return false;
}
}

@Override
public List < String > onTabComplete(CommandSender commandSender, String[] args, IridiumTeams < Island, User > iridiumTeams) {
switch (args.length) {
case 1: {
List < String > tables = new ArrayList < > ();
for (DataTable table: DataTable.values()) {
tables.add(table.name());
}
return tables;
}
case 2: {
List < String > fullTabComplete = Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
fullTabComplete.add("--skip-confirm");
return fullTabComplete;
}
case 3:
return Collections.singletonList("--skip-confirm");
default:
return Collections.emptyList();
}
}
}

enum DataTable {
ALL,
ISLAND,
INVITE,
TRUST,
PERMISSION,
BANK,
ENHANCEMENT,
TEAM_BLOCK,
TEAM_SPAWNER,
TEAM_WARP,
TEAM_MISSION,
TEAM_REWARDS,
TEAM_SETTINGS;
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.iridium.iridiumskyblock.configs;

import com.iridium.iridiumskyblock.commands.BiomeCommand;
import com.iridium.iridiumskyblock.commands.BorderCommand;
import com.iridium.iridiumskyblock.commands.RegenCommand;
import com.iridium.iridiumskyblock.commands.VisitCommand;
import com.iridium.iridiumskyblock.commands.*;
import com.iridium.iridiumskyblock.database.Island;
import com.iridium.iridiumskyblock.database.User;

Expand All @@ -16,4 +13,5 @@ public Commands() {
public BorderCommand borderCommand = new BorderCommand();
public RegenCommand regenCommand = new RegenCommand();
public BiomeCommand biomeCommand = new BiomeCommand();
public ClearDataCommand clearDataCommand = new ClearDataCommand();
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,7 @@ public Messages() {
public String noBiomeCategory = "%prefix% &7No biome category with that name.";
public String noBiome = "%prefix% &7No biome with that name.";
public String changedBiome = "%prefix% &7%player% successfully changed your Island biome to %biome%.";
public String specifyData = "%prefix% &7Due to the nature of this destructive command, you must specify the data to be deleted (or specify \"all\").";
public String confirmDataDeletion = "%prefix% &7You are about to delete the following data: %table% | [for: %island%] in 5 seconds. &cAre you sure you want to do this? (DATA IS &4&lUNRECOVERABLE&r&c)";
public String dataDeletion = "%prefix% &cData has been deleted successfully. &7You may need to restart your server for it to take effect.";
}
Loading

0 comments on commit 843027a

Please sign in to comment.