Skip to content

Commit

Permalink
Merge pull request #77 from Khontrom/main
Browse files Browse the repository at this point in the history
Added IridiumSkyblock & UltimateClaims support
  • Loading branch information
poyrazinan authored Aug 9, 2024
2 parents 68d2b52 + 2b9d5b1 commit 6e77407
Show file tree
Hide file tree
Showing 9 changed files with 291 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,8 @@ public class Main extends JavaPlugin {
* [GriefPrevention](https://www.spigotmc.org/resources/griefprevention.1884/)
* [SuperiorSkyblock2](https://github.com/BG-Software-LLC/SuperiorSkyblock2)
* [TownyAdvanced](https://www.spigotmc.org/resources/towny-advanced.72694/)
* [IridiumSkyblock](https://www.spigotmc.org/resources/iridium-skyblock-1-13-1-20-%E2%AD%90now-with-ai%E2%AD%90.62480/)
* [UltimateClaims](https://songoda.com/product/ultimateclaims-14)

## Contributing

Expand Down
19 changes: 19 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,20 @@
<version>2.11.6</version>
<scope>provided</scope>
</dependency>
<!-- IridiumSkyblock -->
<dependency>
<groupId>com.iridium</groupId>
<artifactId>IridiumSkyblock</artifactId>
<version>4.0.9.1</version>
<scope>provided</scope>
</dependency>
<!-- UltimateClaims -->
<dependency>
<groupId>com.craftaro</groupId>
<artifactId>UltimateClaims</artifactId>
<version>2.2.1</version>
<scope>provided</scope>
</dependency>
</dependencies>

<!-- Repos -->
Expand Down Expand Up @@ -165,6 +179,11 @@
<id>rosewood-repo</id>
<url>https://repo.rosewooddev.io/repository/public/</url>
</repository>
<!-- IridiumSkyblock -->
<repository>
<id>iridiumdevelopment</id>
<url>https://nexus.iridiumdevelopment.net/repository/maven-releases/</url>
</repository>
</repositories>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static class Settings extends OkaeriConfig {
private boolean ignorePlayerDrop = false;

@Comment("Allowed worlds. You can also use worlds like 'island_*' to allow all worlds that contains 'island_' prefix.")
private List<String> allowedWorlds = Arrays.asList("ASkyBlock", "Island", "SuperiorWorld", "bskyblock_world", "island_normal_world", "island_*");
private List<String> allowedWorlds = Arrays.asList("ASkyBlock", "Island", "SuperiorWorld", "bskyblock_world", "island_normal_world","IridiumSkyblock","island_*");

@Comment("Unlocks * character for world name seeker feature")
private boolean AllowedWorldsStarCharFeature = false;
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/xyz/geik/farmer/integrations/Integrations.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
import xyz.geik.farmer.integrations.bentobox.Bento;
import xyz.geik.farmer.integrations.fabledskyblock.FabledSkyblock;
import xyz.geik.farmer.integrations.grief.GriefPrevent;
import xyz.geik.farmer.integrations.iridiumskyblock.IridiumSkyblock;
import xyz.geik.farmer.integrations.lands.Lands;
import xyz.geik.farmer.integrations.superior.SuperiorSkyblock;
import xyz.geik.farmer.integrations.townyadvanced.TownyAdvanced;
import xyz.geik.farmer.integrations.ultimateclaims.UltimateClaims;

import java.util.UUID;

Expand Down Expand Up @@ -79,6 +81,10 @@ else if (Bukkit.getPluginManager().isPluginEnabled("Towny"))
Main.setIntegration(new TownyAdvanced());
else if (Bukkit.getPluginManager().isPluginEnabled("Lands"))
Main.setIntegration(new Lands());
else if (Bukkit.getPluginManager().isPluginEnabled("IridiumSkyblock"))
Main.setIntegration(new IridiumSkyblock());
else if (Bukkit.getPluginManager().isPluginEnabled("UltimateClaims"))
Main.setIntegration(new UltimateClaims());
}
}.runTaskLater(Main.getInstance(), 1);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package xyz.geik.farmer.integrations.iridiumskyblock;


import com.iridium.iridiumskyblock.api.IslandDeleteEvent;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import xyz.geik.farmer.api.FarmerAPI;

/**
* IridiumSkyblock listener class
*
* @author Khontrom
*/
public class IridiumListener implements Listener {

/**
* Constructor of class
*/
public IridiumListener() {}

/**
* Remove farmer on island delete
* @param event listener event of delete
*/
@EventHandler
public void islandDeleteEvent(IslandDeleteEvent event){
String regionID = String.valueOf(event.getIsland().getId());
FarmerAPI.getFarmerManager().removeFarmer(regionID);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package xyz.geik.farmer.integrations.iridiumskyblock;

import com.iridium.iridiumskyblock.api.IridiumSkyblockAPI;
import com.iridium.iridiumskyblock.database.Island;
import com.iridium.iridiumskyblock.database.User;
import org.bukkit.Location;
import xyz.geik.farmer.integrations.Integrations;

import java.util.Objects;
import java.util.Optional;
import java.util.UUID;

/**
* IridiumSkyblock integration interface class
*
* @author Khontrom
*/
public class IridiumSkyblock extends Integrations {

public IridiumSkyblock() { super(new IridiumListener());}

/**
* Gets OwnerUUID by RegionID
*
* @param regionID id of region
* @return UUID of owner
*/
@Override
public UUID getOwnerUUID(String regionID) {
Optional<Island> island = Objects.requireNonNull(IridiumSkyblockAPI.getInstance()).getIslandById(Integer.parseInt(regionID));
Optional<User> user = island.map(Island::getOwner).orElse(null);
return Objects.requireNonNull(user).map(User::getUuid).orElse(null);
}
/**
* Gets Owner UUID by Location
*
* @param location location of region
* @return UUID of player
*/
@Override
public UUID getOwnerUUID(Location location) {
Optional<Island> island = Objects.requireNonNull(IridiumSkyblockAPI.getInstance()).getIslandViaLocation(location);
Optional<User> user = island.map(Island::getOwner).orElse(null);
return Objects.requireNonNull(user).map(User::getUuid).orElse(null);
}

/**
* Gets RegionId by Location
*
* @param location of region
* @return String of region id
*/
@Override
public String getRegionID(Location location) {
Optional<Island> island = Objects.requireNonNull(IridiumSkyblockAPI.getInstance()).getIslandViaLocation(location);
Integer id = island.map(Island::getId).orElse(null);
return id == null ? null : String.valueOf(id);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package xyz.geik.farmer.integrations.ultimateclaims;

import com.craftaro.ultimateclaims.claim.Claim;
import org.bukkit.Location;
import xyz.geik.farmer.api.FarmerAPI;
import xyz.geik.farmer.integrations.Integrations;
import xyz.geik.farmer.model.user.FarmerPerm;

import java.util.Optional;
import java.util.UUID;

/**
* UltimateClaims integration interface class
*
* @author Khontrom
*/
public class UltimateClaims extends Integrations {

public UltimateClaims() { super(new UltimateListener()); }

/**
* Gets OwnerUUID by RegionID
*
* @param regionID id of region
* @return UUID of owner
*/
@Override
public UUID getOwnerUUID(String regionID) {
return com.craftaro.ultimateclaims.UltimateClaims.getInstance()
.getClaimManager().getRegisteredClaims()
.stream().filter(claim -> regionID.equals(String.valueOf(claim.getId())))
.findFirst().get().getOwner().getUniqueId();
}

/**
* Gets Owner UUID by Location
*
* @param location location of region
* @return UUID of player
*/
@Override
public UUID getOwnerUUID(Location location) {
return com.craftaro.ultimateclaims.UltimateClaims.getInstance().getClaimManager().getClaim(location.getChunk()).getOwner().getUniqueId();
}

/**
* Gets RegionId by Location
*
* @param location of region
* @return String of region id
*/
@Override
public String getRegionID(Location location) {
return String.valueOf(com.craftaro.ultimateclaims.UltimateClaims.getInstance().getClaimManager().getClaim(location.getChunk()).getId());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package xyz.geik.farmer.integrations.ultimateclaims;

import com.craftaro.ultimateclaims.api.events.*;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import xyz.geik.farmer.Main;
import xyz.geik.farmer.api.FarmerAPI;
import xyz.geik.farmer.api.managers.FarmerManager;
import xyz.geik.farmer.model.Farmer;
import xyz.geik.farmer.model.user.FarmerPerm;
import xyz.geik.glib.chat.ChatUtils;

import java.util.UUID;

/**
* UltimateClaims listener class
*
* @author Khontrom
*/
public class UltimateListener implements Listener {

/**
* Constructor of class
*/
public UltimateListener(){}

/**
* Automatically create farmer
* when claim is created
*
* @param event of event
*/
@EventHandler
public void claimCreateEvent(ClaimCreateEvent event){
String claimId = String.valueOf(event.getClaim().getId());
if (Main.getConfigFile().getSettings().isAutoCreateFarmer()) {
Farmer farmer = new Farmer(claimId, 0);
ChatUtils.sendMessage(event.getClaim().getOwner().getPlayer().getPlayer(),
Main.getLangFile().getMessages().getBoughtFarmer());
}
}

/**
* Adds user to farmer
* @param event of event
*/
@EventHandler
public void claimJoinEvent(ClaimMemberAddEvent event){
String claimId = String.valueOf(event.getClaim().getId());
if (!FarmerManager.getFarmers().containsKey(claimId)) return;
UUID member = event.getPlayer().getUniqueId();
Farmer farmer = FarmerManager.getFarmers().get(claimId);
if (farmer.getUsers().stream().noneMatch(user -> user.getUuid().equals(member)))
farmer.addUser(member, Bukkit.getOfflinePlayer(member).getName(), FarmerPerm.COOP);
}

/**
* Removes user from farmer if added when leave
* @param event of event
*/
@EventHandler
public void claimLeaveEvent(ClaimMemberLeaveEvent event){
banAndLeaveEvent(String.valueOf(event.getClaim().getId()),event.getPlayer().getUniqueId());
}

/**
* Removes user from farmer if added when banned
* @param event of event
*/
@EventHandler
public void claimBanEvent(ClaimPlayerBanEvent event){
banAndLeaveEvent(String.valueOf(event.getClaim().getId()),event.getBannedPlayer().getUniqueId());

}

/**
* Transfers farmer when claim transfer
*
* @param event transfer claim event
*/
@EventHandler
public void claimTransferEvent(ClaimTransferOwnershipEvent event){
FarmerAPI.getFarmerManager()
.changeOwner(event.getOldOwner().getUniqueId(), event.getNewOwner().getUniqueId(), String.valueOf(event.getClaim().getId()));
}

/**
* Remove farmer on claim deletion
* @param event of event
*/
@EventHandler
public void claimDeleteEvent(ClaimDeleteEvent event){
FarmerAPI.getFarmerManager().removeFarmer(String.valueOf(event.getClaim().getId()));
}



/**
* Remove function of ban and leave event
*
* @param claimId id of claim
* @param member member of claim
*/
private void banAndLeaveEvent(String claimId, UUID member) {
if (!FarmerManager.getFarmers().containsKey(claimId))
return;
Farmer farmer = FarmerManager.getFarmers().get(claimId);
// Removes player if added to farmer
if (farmer.getUsers().stream().anyMatch(user -> user.getUuid().equals(member)))
farmer.removeUser(farmer.getUsers().stream().filter(user -> user.getUuid().equals(member)).findFirst().get());
}


}
4 changes: 2 additions & 2 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: Farmer
author: Geik, Amowny, WaterArchery, hyperion, rudde, mehmet-27
author: Geik, Amowny, WaterArchery, hyperion, rudde, mehmet-27, Khontrom
main: xyz.geik.farmer.Main
version: v6-b106
api-version: 1.13
depend: [PlaceholderAPI]
softdepend: [Vault, RoyaleEconomy, PlayerPoints, GrinGotts, ElementalGems, ASkyBlock, BentoBox, SuperiorSkyblock2, GriefPrevention, FabledSkyBlock, Lands]
softdepend: [Vault, RoyaleEconomy, PlayerPoints, GrinGotts, ElementalGems, ASkyBlock, BentoBox, SuperiorSkyblock2, GriefPrevention, FabledSkyBlock, Lands, IridiumSkyblock, UltimateClaims]
loadbefore: [AutoPickup]
commands:
farmer:
Expand Down

0 comments on commit 6e77407

Please sign in to comment.