Skip to content

Commit

Permalink
Merge pull request #28 from GreenSurvivors/devjoshi
Browse files Browse the repository at this point in the history
Adding recorder deactivation option
Adding missing Team Colors
  • Loading branch information
joshi1999 authored Feb 25, 2024
2 parents 0b8d6cd + 3422c0f commit 5658362
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public class Minigame implements ScriptObject {
@NotNull
private final ScoreboardData sbData = new ScoreboardData();
private final Map<MinigameStat, StatSettings> statSettings = Maps.newHashMap();
private final BooleanFlag activatePlayerRecorder = new BooleanFlag(true, "activatePlayerRecorder");

//Unsaved data
private final List<MinigamePlayer> players = new ArrayList<>();
Expand Down Expand Up @@ -180,6 +181,7 @@ private void setup(MinigameType type, Location start) {

flags.setFlag(new ArrayList<>());

addConfigFlag(activatePlayerRecorder);
addConfigFlag(allowEnderPearls);
addConfigFlag(allowFlight);
addConfigFlag(allowMPCheckpoints);
Expand Down Expand Up @@ -898,6 +900,14 @@ public void setMaxChestRandom(int maxChestRandom) {
this.maxChestRandom.setFlag(maxChestRandom);
}

public boolean getActivatePlayerRecorder() {
return activatePlayerRecorder.getFlag();
}

public void setActivatePlayerRecorder(boolean activatePlayerRecorder) {
this.activatePlayerRecorder.setFlag(activatePlayerRecorder);
}

public Collection<MgRegion> getRegenRegions() {
return regenRegions.getFlag().values();
}
Expand Down Expand Up @@ -1238,6 +1248,7 @@ public void setValue(Integer value) {
rndChstDes.add("Max. item randomization");
itemsMain.add(maxChestRandom.getMenuItem("Max. Chest Random", Material.STONE, rndChstDes, 0, null));
itemsMain.add(new MenuItemStatisticsSettings(this, "Stat Settings", Material.WRITABLE_BOOK));
itemsMain.add(activatePlayerRecorder.getMenuItem("Activate Player Block Recorder", Material.COMMAND_BLOCK));
itemsMain.add(new MenuItemNewLine());

//--------------//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,11 @@ private boolean handleBlockBreak(BlockBreakEvent event, MinigamePlayer mgPlayer)
}
}

if (mgm.getActivatePlayerRecorder()) {
recData.addBlock(event.getBlock(), mgPlayer);
}

// signs are safe. Now check for block drops
recData.addBlock(event.getBlock(), mgPlayer);
if (!mgm.canBlocksdrop()) {
event.getBlock().setType(Material.AIR);
return true;
Expand Down Expand Up @@ -140,14 +143,16 @@ private void blockPlace(BlockPlaceEvent event) {
if (recData.getWhitelistMode()) {
//white list --> blocks that are allowed to be placed
if (recData.getWBBlocks().contains(event.getBlock().getType())) {
recData.addBlock(event.getBlockReplacedState(), mgPlayer);
if (mgm.getActivatePlayerRecorder()) {
recData.addBlock(event.getBlockReplacedState(), mgPlayer);
}
} else {
event.setCancelled(true);
}
//black list --> blocks that are not allowed to be placed
} else if (recData.getWBBlocks().contains(event.getBlock().getType())) {
event.setCancelled(true);
} else {
} else if (mgm.getActivatePlayerRecorder()) {
recData.addBlock(event.getBlockReplacedState(), mgPlayer);
}
} else {
Expand All @@ -169,7 +174,7 @@ private void changeAnotherInventory(PlayerInteractEvent event) {
Minigame mgm = mgPlayer.getMinigame();
RecorderData recData = mgm.getRecorderData();

if (event.getClickedBlock().getState() instanceof InventoryHolder) {
if (event.getClickedBlock().getState() instanceof InventoryHolder && mgm.getActivatePlayerRecorder()) {
recData.addBlock(event.getClickedBlock().getLocation().getBlock(), mgPlayer);
}
}
Expand All @@ -191,11 +196,13 @@ public void igniteBlock(BlockIgniteEvent event) {
if (mgm.canBlockPlace()) {
if (recData.getWhitelistMode()) {
//white list --> blocks that are allowed to be broken
if (recData.getWBBlocks().contains(event.getBlock().getType())) {
if (recData.getWBBlocks().contains(event.getBlock().getType())
&& mgm.getActivatePlayerRecorder()) {
recData.addBlock(event.getBlock(), playerManager.getMinigamePlayer(event.getPlayer()));
}
//black list --> blocks that are not allowed to be broken
} else if (!recData.getWBBlocks().contains(event.getBlock().getType())) {
} else if (!recData.getWBBlocks().contains(event.getBlock().getType())
&& mgm.getActivatePlayerRecorder()) {
recData.addBlock(event.getBlock(), playerManager.getMinigamePlayer(event.getPlayer()));
}
} else {
Expand Down Expand Up @@ -231,12 +238,12 @@ private void hangingPlace(HangingPlaceEvent event) {

if (recData.getWhitelistMode()) {
//white list --> blocks that are allowed to be broken
if (recData.getWBBlocks().contains(usedMaterial)) {
if (recData.getWBBlocks().contains(usedMaterial) && mgm.getActivatePlayerRecorder()) {
recData.addEntity(event.getEntity(), mgPlayer, true);
return;
}
//black list --> blocks that are not allowed to be broken
} else if (!recData.getWBBlocks().contains(usedMaterial)) {
} else if (!recData.getWBBlocks().contains(usedMaterial) && mgm.getActivatePlayerRecorder()) {
recData.addEntity(event.getEntity(), mgPlayer, true);
return;
}
Expand Down Expand Up @@ -266,7 +273,7 @@ private void animalHurt(EntityDamageByEntityEvent event) {
}

if (mgPlayer != null) {
if (mgPlayer.isInMinigame()) {
if (mgPlayer.isInMinigame() && mgPlayer.getMinigame().getActivatePlayerRecorder()) {
mgPlayer.getMinigame().getRecorderData().addEntity(animal, mgPlayer, false);
}
}
Expand All @@ -289,7 +296,7 @@ private void hangingBreak(HangingBreakByEntityEvent event) {

}
if (mgPlayer != null) {
if (mgPlayer.isInMinigame()) {
if (mgPlayer.isInMinigame() && mgPlayer.getMinigame().getActivatePlayerRecorder()) {
mgPlayer.getMinigame().getRecorderData().addEntity(event.getEntity(), mgPlayer, false);
}
}
Expand All @@ -303,7 +310,7 @@ private void arrowShoot(EntityShootBowEvent event) {
if (event.getEntity() instanceof Player player) {
MinigamePlayer mgPlayer = playerManager.getMinigamePlayer(player);

if (mgPlayer.isInMinigame()) {
if (mgPlayer.isInMinigame() && mgPlayer.getMinigame().getActivatePlayerRecorder()) {
mgPlayer.getMinigame().getRecorderData().addEntity(event.getProjectile(), mgPlayer, true);
}
}
Expand All @@ -317,7 +324,7 @@ private void throwEnderPearl(ProjectileLaunchEvent event) {
if (event.getEntity().getShooter() instanceof Player player) {
MinigamePlayer mgPlayer = playerManager.getMinigamePlayer(player);

if (mgPlayer.isInMinigame()) {
if (mgPlayer.isInMinigame() && mgPlayer.getMinigame().getActivatePlayerRecorder()) {
mgPlayer.getMinigame().getRecorderData().addEntity(event.getEntity(), mgPlayer, true);
}
}
Expand All @@ -337,11 +344,12 @@ private void bucketFill(PlayerBucketFillEvent event) {
if (mgm.canBlockBreak()) {
if (recData.getWhitelistMode()) {
//white list --> blocks that are allowed to be broken
if (recData.getWBBlocks().contains(event.getBlock().getType())) {
if (recData.getWBBlocks().contains(event.getBlock().getType()) && mgm.getActivatePlayerRecorder()) {
recData.addBlock(event.getBlockClicked(), playerManager.getMinigamePlayer(event.getPlayer()));
}
//black list --> blocks that are not allowed to be broken
} else if (!recData.getWBBlocks().contains(event.getBlock().getType())) {
} else if (!recData.getWBBlocks().contains(event.getBlock().getType())
&& mgm.getActivatePlayerRecorder()) {
recData.addBlock(event.getBlockClicked(), playerManager.getMinigamePlayer(event.getPlayer()));
}
} else {
Expand All @@ -364,15 +372,16 @@ private void bucketEmpty(PlayerBucketEmptyEvent event) {
if (mgm.canBlockPlace()) {
if (recData.getWhitelistMode()) {
//white list --> blocks that are allowed to be broken
if (recData.getWBBlocks().contains(event.getBlock().getType())) {
if (recData.getWBBlocks().contains(event.getBlock().getType()) && mgm.getActivatePlayerRecorder()) {
Location loc = new Location(event.getBlockClicked().getWorld(),
event.getBlockFace().getModX() + event.getBlockClicked().getX(),
event.getBlockFace().getModY() + event.getBlockClicked().getY(),
event.getBlockFace().getModZ() + event.getBlockClicked().getZ());
recData.addBlock(loc.getBlock(), playerManager.getMinigamePlayer(event.getPlayer()));
}
//black list --> blocks that are not allowed to be broken
} else if (!recData.getWBBlocks().contains(event.getBlock().getType())) {
} else if (!recData.getWBBlocks().contains(event.getBlock().getType())
&& mgm.getActivatePlayerRecorder()) {
Location loc = new Location(event.getBlockClicked().getWorld(),
event.getBlockFace().getModX() + event.getBlockClicked().getX(),
event.getBlockFace().getModY() + event.getBlockClicked().getY(),
Expand All @@ -395,7 +404,7 @@ private void vehicleDestroy(VehicleDestroyEvent event) {
MinigamePlayer mgPlayer = playerManager.getMinigamePlayer(player);
Minigame mg = mgPlayer.getMinigame();

if (mgPlayer.isInMinigame()) {
if (mgPlayer.isInMinigame() && mg.getActivatePlayerRecorder()) {
mg.getRecorderData().addEntity(event.getVehicle(), mgPlayer, false);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
import java.lang.reflect.Type;
import java.util.*;

/**
*
*/
public class RecorderData implements Listener {
// list of blocks that need another block to not break
private static final ArrayList<Material> supportedMats = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ private Material getTeamMaterial() {
case "DARK_BLUE" -> Material.BLUE_CONCRETE;
case "DARK_GREEN" -> Material.GREEN_CONCRETE;
case "DARK_PURPLE" -> Material.PURPLE_CONCRETE;
case "DARK_GRAY" -> Material.GRAY_CONCRETE;
case "GRAY" -> Material.GRAY_WOOL;
case "ORANGE" -> Material.ORANGE_WOOL;
case "CYAN" -> Material.CYAN_WOOL;
case "LIGHT_BLUE" -> Material.LIGHT_BLUE_WOOL;
default -> Material.WHITE_WOOL;
};
}
Expand Down

0 comments on commit 5658362

Please sign in to comment.