mirror of
https://github.com/BG-Software-LLC/WildLoaders.git
synced 2025-01-05 18:59:02 +01:00
Added the ability of chunk loaders load chunks inside claims that are near each other
This commit is contained in:
parent
019ae2492c
commit
d40223cede
@ -2,6 +2,7 @@ package com.bgsoftware.wildloaders.api;
|
||||
|
||||
import com.bgsoftware.wildloaders.api.managers.LoadersManager;
|
||||
import com.bgsoftware.wildloaders.api.managers.NPCManager;
|
||||
import com.bgsoftware.wildloaders.api.managers.ProvidersManager;
|
||||
|
||||
public interface WildLoaders {
|
||||
|
||||
@ -15,4 +16,9 @@ public interface WildLoaders {
|
||||
*/
|
||||
NPCManager getNPCs();
|
||||
|
||||
/**
|
||||
* Get the providers manager.
|
||||
*/
|
||||
ProvidersManager getProviders();
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,11 @@
|
||||
package com.bgsoftware.wildloaders.api.hooks;
|
||||
|
||||
import org.bukkit.Chunk;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public interface ClaimsProvider {
|
||||
|
||||
boolean hasClaimAccess(UUID player, Chunk chunk);
|
||||
|
||||
}
|
@ -34,4 +34,17 @@ public interface LoaderData {
|
||||
*/
|
||||
int getChunksRadius();
|
||||
|
||||
/**
|
||||
* Set whether or not the chunks-spread mode is enabled for this chunk loader.
|
||||
* When this mode is enabled, all the chunks inside a claim that are connected to each other will be claimed.
|
||||
* @param chunksSpread Set the status of the chunks spread mode.
|
||||
*/
|
||||
void setChunksSpread(boolean chunksSpread);
|
||||
|
||||
/**
|
||||
* Get whether or not the chunks-spread mode is enabled for this chunk loader.
|
||||
* When this mode is enabled, all the chunks inside a claim that are connected to each other will be claimed.
|
||||
*/
|
||||
boolean isChunksSpread();
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,13 @@
|
||||
package com.bgsoftware.wildloaders.api.managers;
|
||||
|
||||
import com.bgsoftware.wildloaders.api.hooks.ClaimsProvider;
|
||||
|
||||
public interface ProvidersManager {
|
||||
|
||||
/**
|
||||
* Add a claims provider to the plugin.
|
||||
* @param claimsProvider The claims provider to add.
|
||||
*/
|
||||
void addClaimsProvider(ClaimsProvider claimsProvider);
|
||||
|
||||
}
|
BIN
libs/Factions.jar
Normal file
BIN
libs/Factions.jar
Normal file
Binary file not shown.
BIN
libs/FactionsUUID.jar
Normal file
BIN
libs/FactionsUUID.jar
Normal file
Binary file not shown.
BIN
libs/FactionsX.jar
Normal file
BIN
libs/FactionsX.jar
Normal file
Binary file not shown.
BIN
libs/MassiveCore.jar
Normal file
BIN
libs/MassiveCore.jar
Normal file
Binary file not shown.
@ -6,6 +6,7 @@ import com.bgsoftware.wildloaders.command.CommandsHandler;
|
||||
import com.bgsoftware.wildloaders.handlers.DataHandler;
|
||||
import com.bgsoftware.wildloaders.handlers.LoadersHandler;
|
||||
import com.bgsoftware.wildloaders.handlers.NPCHandler;
|
||||
import com.bgsoftware.wildloaders.handlers.ProvidersHandler;
|
||||
import com.bgsoftware.wildloaders.handlers.SettingsHandler;
|
||||
import com.bgsoftware.wildloaders.listeners.BlocksListener;
|
||||
import com.bgsoftware.wildloaders.listeners.ChunksListener;
|
||||
@ -26,6 +27,7 @@ public final class WildLoadersPlugin extends JavaPlugin implements WildLoaders {
|
||||
private LoadersHandler loadersHandler;
|
||||
private NPCHandler npcHandler;
|
||||
private DataHandler dataHandler;
|
||||
private ProvidersHandler providersHandler;
|
||||
|
||||
private NMSAdapter nmsAdapter;
|
||||
|
||||
@ -55,6 +57,7 @@ public final class WildLoadersPlugin extends JavaPlugin implements WildLoaders {
|
||||
dataHandler = new DataHandler(this);
|
||||
loadersHandler = new LoadersHandler(this);
|
||||
npcHandler = new NPCHandler(this);
|
||||
providersHandler = new ProvidersHandler();
|
||||
settingsHandler = new SettingsHandler(this);
|
||||
|
||||
getServer().getPluginManager().registerEvents(new BlocksListener(this), this);
|
||||
@ -117,10 +120,16 @@ public final class WildLoadersPlugin extends JavaPlugin implements WildLoaders {
|
||||
return loadersHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NPCHandler getNPCs() {
|
||||
return npcHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProvidersHandler getProviders() {
|
||||
return providersHandler;
|
||||
}
|
||||
|
||||
public NMSAdapter getNMSAdapter() {
|
||||
return nmsAdapter;
|
||||
}
|
||||
|
@ -0,0 +1,48 @@
|
||||
package com.bgsoftware.wildloaders.handlers;
|
||||
|
||||
import com.bgsoftware.wildloaders.api.hooks.ClaimsProvider;
|
||||
import com.bgsoftware.wildloaders.api.managers.ProvidersManager;
|
||||
import com.bgsoftware.wildloaders.hooks.ClaimsProvider_FactionsUUID;
|
||||
import com.bgsoftware.wildloaders.hooks.ClaimsProvider_FactionsX;
|
||||
import com.bgsoftware.wildloaders.hooks.ClaimsProvider_MassiveFactions;
|
||||
import com.bgsoftware.wildloaders.utils.threads.Executor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class ProvidersHandler implements ProvidersManager {
|
||||
|
||||
private final List<ClaimsProvider> claimsProviders = new ArrayList<>();
|
||||
|
||||
public ProvidersHandler(){
|
||||
Executor.sync(() -> {
|
||||
if(Bukkit.getPluginManager().isPluginEnabled("Factions")){
|
||||
if(Bukkit.getPluginManager().getPlugin("Factions").getDescription().getAuthors().contains("drtshock"))
|
||||
claimsProviders.add(new ClaimsProvider_FactionsUUID());
|
||||
else
|
||||
claimsProviders.add(new ClaimsProvider_MassiveFactions());
|
||||
}
|
||||
if(Bukkit.getPluginManager().isPluginEnabled("FactionsX")){
|
||||
claimsProviders.add(new ClaimsProvider_FactionsX());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addClaimsProvider(ClaimsProvider claimsProvider) {
|
||||
claimsProviders.add(claimsProvider);
|
||||
}
|
||||
|
||||
public boolean hasChunkAccess(UUID player, Chunk chunk){
|
||||
for(ClaimsProvider claimsProvider : claimsProviders) {
|
||||
if (claimsProvider.hasClaimAccess(player, chunk))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@ -82,6 +82,9 @@ public final class SettingsHandler {
|
||||
if(loaderSection.contains("chunks-radius"))
|
||||
loaderData.setChunksRadius(loaderSection.getInt("chunks-radius"));
|
||||
|
||||
if(loaderSection.contains("chunks-spread"))
|
||||
loaderData.setChunksSpread(loaderSection.getBoolean("chunks-spread"));
|
||||
|
||||
loadersAmount++;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,23 @@
|
||||
package com.bgsoftware.wildloaders.hooks;
|
||||
|
||||
import com.bgsoftware.wildloaders.api.hooks.ClaimsProvider;
|
||||
import com.massivecraft.factions.Board;
|
||||
import com.massivecraft.factions.FLocation;
|
||||
import com.massivecraft.factions.FPlayer;
|
||||
import com.massivecraft.factions.FPlayers;
|
||||
import com.massivecraft.factions.Faction;
|
||||
import org.bukkit.Chunk;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public final class ClaimsProvider_FactionsUUID implements ClaimsProvider {
|
||||
|
||||
@Override
|
||||
public boolean hasClaimAccess(UUID player, Chunk chunk) {
|
||||
FPlayer fPlayer = FPlayers.getInstance().getById(player.toString());
|
||||
FLocation fLocation = new FLocation(chunk.getWorld().getName(), chunk.getX(), chunk.getZ());
|
||||
Faction faction = Board.getInstance().getFactionAt(fLocation);
|
||||
return !faction.isWilderness() && faction.getFPlayers().contains(fPlayer);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package com.bgsoftware.wildloaders.hooks;
|
||||
|
||||
import com.bgsoftware.wildloaders.api.hooks.ClaimsProvider;
|
||||
import net.prosavage.factionsx.manager.GridManager;
|
||||
import net.prosavage.factionsx.persist.data.FactionsKt;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public final class ClaimsProvider_FactionsX implements ClaimsProvider {
|
||||
|
||||
@Override
|
||||
public boolean hasClaimAccess(UUID player, Chunk chunk) {
|
||||
Location blockLocation = new Location(chunk.getWorld(), chunk.getX() << 4, 100, chunk.getZ() << 4);
|
||||
return GridManager.INSTANCE.getFactionAt(FactionsKt.getFLocation(blockLocation)).getFactionMembers().contains(player);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.bgsoftware.wildloaders.hooks;
|
||||
|
||||
import com.bgsoftware.wildloaders.api.hooks.ClaimsProvider;
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.entity.BoardColl;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import com.massivecraft.massivecore.ps.PS;
|
||||
import org.bukkit.Chunk;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public final class ClaimsProvider_MassiveFactions implements ClaimsProvider {
|
||||
|
||||
@Override
|
||||
public boolean hasClaimAccess(UUID player, Chunk chunk) {
|
||||
MPlayer mPlayer = MPlayer.get(player);
|
||||
Faction faction = BoardColl.get().getFactionAt(PS.valueOf(chunk));
|
||||
return !faction.getId().equals(Factions.ID_NONE) && faction.getMPlayers().contains(mPlayer);
|
||||
}
|
||||
|
||||
}
|
@ -34,7 +34,7 @@ public final class WChunkLoader implements ChunkLoader {
|
||||
this.loaderName = loaderData.getName();
|
||||
this.whoPlaced = whoPlaced;
|
||||
this.location = location.clone();
|
||||
this.loadedChunks = calculateChunks(loaderData, this.location);
|
||||
this.loadedChunks = calculateChunks(loaderData, whoPlaced, this.location);
|
||||
this.timeLeft = timeLeft;
|
||||
plugin.getNMSAdapter().createLoader(this);
|
||||
}
|
||||
@ -107,16 +107,38 @@ public final class WChunkLoader implements ChunkLoader {
|
||||
return plugin.getNMSAdapter().setTag(itemStack, "loader-time", getTimeLeft());
|
||||
}
|
||||
|
||||
private static Chunk[] calculateChunks(LoaderData loaderData, Location original){
|
||||
private static Chunk[] calculateChunks(LoaderData loaderData, UUID whoPlaced, Location original){
|
||||
List<Chunk> chunkList = new ArrayList<>();
|
||||
|
||||
int chunkX = original.getBlockX() >> 4, chunkZ = original.getBlockZ() >> 4;
|
||||
if(loaderData.isChunksSpread()){
|
||||
calculateClaimChunks(original.getChunk(), whoPlaced, chunkList);
|
||||
}
|
||||
else {
|
||||
int chunkX = original.getBlockX() >> 4, chunkZ = original.getBlockZ() >> 4;
|
||||
|
||||
for(int x = -loaderData.getChunksRadius(); x <= loaderData.getChunksRadius(); x++)
|
||||
for(int z = -loaderData.getChunksRadius(); z <= loaderData.getChunksRadius(); z++)
|
||||
chunkList.add(original.getWorld().getChunkAt(chunkX + x, chunkZ + z));
|
||||
for (int x = -loaderData.getChunksRadius(); x <= loaderData.getChunksRadius(); x++)
|
||||
for (int z = -loaderData.getChunksRadius(); z <= loaderData.getChunksRadius(); z++)
|
||||
chunkList.add(original.getWorld().getChunkAt(chunkX + x, chunkZ + z));
|
||||
}
|
||||
|
||||
return chunkList.toArray(new Chunk[0]);
|
||||
}
|
||||
|
||||
private static void calculateClaimChunks(Chunk originalChunk, UUID whoPlaced, List<Chunk> chunkList){
|
||||
if(!plugin.getProviders().hasChunkAccess(whoPlaced, originalChunk))
|
||||
return;
|
||||
|
||||
chunkList.add(originalChunk);
|
||||
|
||||
int chunkX = originalChunk.getX(), chunkZ = originalChunk.getZ();
|
||||
|
||||
for (int x = -1; x <= 1; x++) {
|
||||
for (int z = -1; z <= 1; z++) {
|
||||
if(x != 0 || z != 0) // We don't want to add the originalChunk again.
|
||||
calculateClaimChunks(originalChunk.getWorld().getChunkAt(chunkX + x, chunkZ + z), whoPlaced, chunkList);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -13,12 +13,14 @@ public final class WLoaderData implements LoaderData {
|
||||
private final ItemStack loaderItem;
|
||||
|
||||
private int chunksRadius;
|
||||
private boolean chunksSpread;
|
||||
|
||||
public WLoaderData(String name, long timeLeft, ItemStack loaderItem){
|
||||
this.name = name;
|
||||
this.timeLeft = timeLeft;
|
||||
this.loaderItem = plugin.getNMSAdapter().setTag(loaderItem, "loader-name", name);
|
||||
this.chunksRadius = 0;
|
||||
this.chunksSpread = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -46,4 +48,14 @@ public final class WLoaderData implements LoaderData {
|
||||
return chunksRadius;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChunksSpread(boolean chunksSpread) {
|
||||
this.chunksSpread = chunksSpread;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChunksSpread() {
|
||||
return chunksSpread;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user