1.0.0-SNAPSHOT-U43

+ Tweaked the cage system, made it more compact and finalized how it works.
This commit is contained in:
AMinecraftDev 2018-11-11 14:35:54 +08:00
parent 1d6e032f40
commit db762912bf
5 changed files with 161 additions and 124 deletions

View File

@ -2,6 +2,8 @@ package com.songoda.epicbosses.skills.custom;
import com.google.gson.annotations.Expose;
import com.songoda.epicbosses.holder.ActiveBossHolder;
import com.songoda.epicbosses.skills.custom.cage.CageLocationData;
import com.songoda.epicbosses.skills.custom.cage.CagePlayerData;
import com.songoda.epicbosses.skills.elements.CustomCageSkillElement;
import com.songoda.epicbosses.skills.types.CustomSkill;
import com.songoda.epicbosses.utils.Debug;
@ -11,8 +13,6 @@ import lombok.Getter;
import lombok.Setter;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.entity.LivingEntity;
@ -25,12 +25,10 @@ import java.util.*;
*/
public class Cage extends CustomSkill {
@Getter private static final Map<UUID, Map<String, Queue<BlockState>>> mapOfCages = new HashMap<>(), mapOfRestoreCages = new HashMap<>();
private static final MaterialConverter MATERIAL_CONVERTER = new MaterialConverter();
@Getter private static final Map<Location, Integer> mapOfCagesOnLocation = new HashMap<>();
@Getter private static final Map<Location, BlockState> mapOfOldBlocks = new HashMap<>();
@Getter private static final List<UUID> playersInCage = new ArrayList<>();
private static final MaterialConverter MATERIAL_CONVERTER = new MaterialConverter();
@Getter private static final Map<Location, CageLocationData> cageLocationDataMap = new HashMap<>();
@Getter private static final List<UUID> playersInCage = new ArrayList<>();
@Expose @Getter @Setter private CustomCageSkillElement cage;
@ -44,22 +42,21 @@ public class Cage extends CustomSkill {
getPlayersInCage().add(uuid);
Location teleportLocation = getTeleportLocation(livingEntity);
Map<String, Queue<BlockState>> originalMap = getBlockStateMap(teleportLocation);
CagePlayerData cagePlayerData = new CagePlayerData(uuid);
cagePlayerData.setBlockStateMaps(teleportLocation);
livingEntity.teleport(teleportLocation);
getMapOfCages().put(uuid, originalMap);
getMapOfRestoreCages().put(uuid, new HashMap<>(originalMap));
ServerUtils.get().runLater(1L, () -> setCageBlocks(uuid));
ServerUtils.get().runLater(1L, () -> setCageBlocks(cagePlayerData));
ServerUtils.get().runLater(100L, () -> {
restoreCageBlocks(uuid);
restoreCageBlocks(cagePlayerData);
getPlayersInCage().remove(uuid);
});
});
}
private void restoreCageBlocks(UUID uuid) {
Map<String, Queue<BlockState>> queueMap = getMapOfRestoreCages().get(uuid);
private void restoreCageBlocks(CagePlayerData cagePlayerData) {
Map<String, Queue<BlockState>> queueMap = cagePlayerData.getMapOfRestoreCages();
restoreBlocks(queueMap.get("W"));
restoreBlocks(queueMap.get("F"));
@ -71,22 +68,27 @@ public class Cage extends CustomSkill {
if(blockState == null) return;
Location location = blockState.getLocation();
int amountOfCages = getMapOfCagesOnLocation().getOrDefault(location, 1);
CageLocationData cageLocationData = getCageLocationDataMap().getOrDefault(location, new CageLocationData(location, 1));
int amountOfCages = cageLocationData.getAmountOfCages();
if(amountOfCages == 1) {
BlockState oldState = getMapOfOldBlocks().get(location);
BlockState oldState = cageLocationData.getOldBlockState();
location.getBlock().setType(oldState.getType());
location.getBlock().setBlockData(oldState.getBlockData());
getMapOfCagesOnLocation().remove(location);
if(oldState != null) {
location.getBlock().setType(oldState.getType());
location.getBlock().setBlockData(oldState.getBlockData());
}
getCageLocationDataMap().remove(location);
} else {
getMapOfCagesOnLocation().put(location, amountOfCages-1);
cageLocationData.setAmountOfCages(amountOfCages-1);
getCageLocationDataMap().put(location, cageLocationData);
}
});
}
private void setCageBlocks(UUID uuid) {
Map<String, Queue<BlockState>> queueMap = getMapOfCages().get(uuid);
private void setCageBlocks(CagePlayerData cagePlayerData) {
Map<String, Queue<BlockState>> queueMap = cagePlayerData.getMapOfCages();
setBlocks(queueMap.get("W"), getCage().getWallType());
setBlocks(queueMap.get("F"), getCage().getFlatType());
@ -105,95 +107,20 @@ public class Cage extends CustomSkill {
if(blockState == null) return;
Location location = blockState.getLocation();
int currentAmount = getMapOfCagesOnLocation().getOrDefault(location, 0);
CageLocationData cageLocationData = getCageLocationDataMap().getOrDefault(location, new CageLocationData(location, 0));
int currentAmount = cageLocationData.getAmountOfCages();
if(!getMapOfOldBlocks().containsKey(location)) getMapOfOldBlocks().put(location, blockState);
if(currentAmount == 0 || cageLocationData.getOldBlockState() == null) cageLocationData.setOldBlockState(blockState);
blockState.getBlock().setType(material);
getMapOfCagesOnLocation().put(location, currentAmount+1);
cageLocationData.setAmountOfCages(currentAmount+1);
getCageLocationDataMap().put(location, cageLocationData);
});
}
private Map<String, Queue<BlockState>> getBlockStateMap(Location location) {
Map<String, Queue<BlockState>> map = new HashMap<>();
map.put("W", getCageWalls(location));
map.put("F", getCageFlats(location));
map.put("I", getCageInside(location));
return map;
}
private Location getTeleportLocation(LivingEntity livingEntity) {
Location currentLocation = livingEntity.getLocation();
return currentLocation.clone().add(0.5, 0, 0.5);
}
private Queue<BlockState> getCageFlats(Location playerLocation) {
World world = playerLocation.getWorld();
Queue<Location> locationQueue = new LinkedList<>();
for(int x = 1; x >= -1; x--) {
for(int z = 1; z >= -1; z--) {
Location location1 = new Location(world, x, +2, z);
Location location2 = new Location(world, x, -1, z);
locationQueue.add(location1);
locationQueue.add(location2);
}
}
locationQueue.add(new Location(world, +1, +2, -1));
locationQueue.add(new Location(world, +1, +2, +0));
return sortLocationQueue(locationQueue, playerLocation);
}
private Queue<BlockState> getCageInside(Location playerLocation) {
World world = playerLocation.getWorld();
Queue<Location> locationQueue = new LinkedList<>();
for(int y = 1; y >= 0; y--) {
Location innerLocation = new Location(world, 0, y, 0);
locationQueue.add(innerLocation);
}
return sortLocationQueue(locationQueue, playerLocation);
}
public Queue<BlockState> getCageWalls(Location playerLocation) {
World world = playerLocation.getWorld();
Queue<Location> locationQueue = new LinkedList<>();
for(int x = 1; x >= -1; x--) {
for(int z = 1; z >= -1; z--) {
Location location1 = new Location(world, x, 1, z);
Location location2 = new Location(world, x, 0, z);
locationQueue.add(location1);
locationQueue.add(location2);
}
}
return sortLocationQueue(locationQueue, playerLocation);
}
private Queue<BlockState> sortLocationQueue(Queue<Location> queue, Location playerLocation) {
Queue<BlockState> blockStateQueue = new LinkedList<>();
World world = playerLocation.getWorld();
while(!queue.isEmpty()) {
Location temp = queue.poll();
if(temp == null) continue;
Block block = world.getBlockAt(temp.add(playerLocation).clone());
blockStateQueue.add(block.getState());
}
return blockStateQueue;
}
}

View File

@ -1,21 +0,0 @@
package com.songoda.epicbosses.skills.custom.cage;
import lombok.Getter;
import org.bukkit.block.BlockState;
import java.util.HashMap;
import java.util.Map;
import java.util.Queue;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 10-Nov-18
*/
public class CageData {
@Getter private Map<String, Queue<BlockState>> mapOfCages = new HashMap<>(), mapOfRestoreCages = new HashMap<>();
}

View File

@ -0,0 +1,30 @@
package com.songoda.epicbosses.skills.custom.cage;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.Location;
import org.bukkit.block.BlockState;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 11-Nov-18
*/
public class CageLocationData {
@Getter @Setter private BlockState oldBlockState;
@Getter @Setter private int amountOfCages = 0;
@Getter private final Location location;
public CageLocationData(Location location, int amountOfCages) {
this(location);
this.amountOfCages = amountOfCages;
}
public CageLocationData(Location location) {
this.location = location;
}
}

View File

@ -0,0 +1,101 @@
package com.songoda.epicbosses.skills.custom.cage;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import java.util.*;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 10-Nov-18
*/
public class CagePlayerData {
@Getter private final Map<String, Queue<BlockState>> mapOfCages = new HashMap<>(), mapOfRestoreCages = new HashMap<>();
@Getter private final UUID uuid;
public CagePlayerData(UUID uuid) {
this.uuid = uuid;
}
public void setBlockStateMaps(Location location) {
getMapOfCages().put("W", getCageWalls(location));
getMapOfCages().put("F", getCageFlats(location));
getMapOfCages().put("I", getCageInside(location));
getMapOfRestoreCages().putAll(getMapOfCages());
}
private Queue<BlockState> getCageFlats(Location playerLocation) {
World world = playerLocation.getWorld();
Queue<Location> locationQueue = new LinkedList<>();
for(int x = 1; x >= -1; x--) {
for(int z = 1; z >= -1; z--) {
Location location1 = new Location(world, x, +2, z);
Location location2 = new Location(world, x, -1, z);
locationQueue.add(location1);
locationQueue.add(location2);
}
}
locationQueue.add(new Location(world, +1, +2, -1));
locationQueue.add(new Location(world, +1, +2, +0));
return sortLocationQueue(locationQueue, playerLocation);
}
private Queue<BlockState> getCageInside(Location playerLocation) {
World world = playerLocation.getWorld();
Queue<Location> locationQueue = new LinkedList<>();
for(int y = 1; y >= 0; y--) {
Location innerLocation = new Location(world, 0, y, 0);
locationQueue.add(innerLocation);
}
return sortLocationQueue(locationQueue, playerLocation);
}
public Queue<BlockState> getCageWalls(Location playerLocation) {
World world = playerLocation.getWorld();
Queue<Location> locationQueue = new LinkedList<>();
for(int x = 1; x >= -1; x--) {
for(int z = 1; z >= -1; z--) {
Location location1 = new Location(world, x, 1, z);
Location location2 = new Location(world, x, 0, z);
locationQueue.add(location1);
locationQueue.add(location2);
}
}
return sortLocationQueue(locationQueue, playerLocation);
}
private Queue<BlockState> sortLocationQueue(Queue<Location> queue, Location playerLocation) {
Queue<BlockState> blockStateQueue = new LinkedList<>();
World world = playerLocation.getWorld();
while(!queue.isEmpty()) {
Location temp = queue.poll();
if(temp == null) continue;
Block block = world.getBlockAt(temp.add(playerLocation).clone());
blockStateQueue.add(block.getState());
}
return blockStateQueue;
}
}

View File

@ -19,7 +19,7 @@
</modules>
<properties>
<plugin.version>1.0.0-SNAPSHOT-U42</plugin.version>
<plugin.version>1.0.0-SNAPSHOT-U43</plugin.version>
<plugin.name>EpicBosses</plugin.name>
<plugin.main>com.songoda.epicbosses.CustomBosses</plugin.main>
<plugin.author>AMinecraftDev</plugin.author>