-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #77 from Khontrom/main
Added IridiumSkyblock & UltimateClaims support
- Loading branch information
Showing
9 changed files
with
291 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/main/java/xyz/geik/farmer/integrations/iridiumskyblock/IridiumListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
59 changes: 59 additions & 0 deletions
59
src/main/java/xyz/geik/farmer/integrations/iridiumskyblock/IridiumSkyblock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/main/java/xyz/geik/farmer/integrations/ultimateclaims/UltimateClaims.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
115 changes: 115 additions & 0 deletions
115
src/main/java/xyz/geik/farmer/integrations/ultimateclaims/UltimateListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters