Skip to content

Commit

Permalink
Merge pull request #219 from TiagoFar78/soundDetectorParticles
Browse files Browse the repository at this point in the history
Sound detector particles
  • Loading branch information
iquelli authored May 29, 2024
2 parents badfa6e + dd0d890 commit a71fc3c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
4 changes: 2 additions & 2 deletions TestServer/plugins/TF_PrisonEscape/config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PrisionersRatio: 0.99
PoliceRatio: 0.1
PrisionersRatio: 0.27
PoliceRatio: 0.73
MinPlayers: 1
MaxPlayers: 11
SecondsInSolitary: 30
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package net.tiagofar78.prisonescape.game.prisonbuilding;

import net.tiagofar78.prisonescape.PrisonEscape;
import net.tiagofar78.prisonescape.bukkit.BukkitWorldEditor;
import net.tiagofar78.prisonescape.game.Guard;
import net.tiagofar78.prisonescape.game.PrisonEscapeGame;
import net.tiagofar78.prisonescape.game.PrisonEscapePlayer;
import net.tiagofar78.prisonescape.managers.ConfigManager;
import net.tiagofar78.prisonescape.managers.GameManager;

import org.bukkit.Bukkit;
import org.bukkit.Color;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.World;

import java.util.ArrayList;
Expand All @@ -18,17 +22,21 @@ public class SoundDetector {

private static final int MAX_VALUE = 10;
private static final int MIN_VALUE = 1;
private static final int CIRCLE_SEGMENTS = 32;

private int _index;
private boolean _isWorking;
private PrisonEscapeLocation _location;
private List<PrisonEscapePlayer> _playersInRange;

public SoundDetector(int index, PrisonEscapeLocation location) {
_index = index;
_isWorking = true;
_location = location;
_playersInRange = new ArrayList<>();

createOnWorld();
createPerimeterParticles();

PrisonEscapeGame game = GameManager.getGame();
List<Guard> guards = game.getGuardsTeam().getMembers();
Expand Down Expand Up @@ -65,6 +73,7 @@ private double distance(PrisonEscapeLocation loc1, PrisonEscapeLocation loc2) {
}

public void delete() {
_isWorking = false;
deleteFromWorld();
}

Expand All @@ -75,6 +84,40 @@ private void createOnWorld() {
location.getBlock().setType(Material.LIGHTNING_ROD);
}

private void createPerimeterParticles() {
World world = BukkitWorldEditor.getWorld();

double centerX = _location.getX() + 0.5;
double centerY = _location.getY();
double centerZ = _location.getZ() + 0.5;
double radius = ConfigManager.getInstance().getSoundDetectorRange();

loopCreateParticles(world, centerX, centerY, centerZ, radius);
}

private void loopCreateParticles(World world, double centerX, double centerY, double centerZ, double radius) {
if (!_isWorking) {
return;
}

for (int i = 0; i < CIRCLE_SEGMENTS; i++) {
double angle = i * Math.PI * 2 / CIRCLE_SEGMENTS;

double x = centerX + Math.sin(angle) * radius;
double z = centerZ + Math.cos(angle) * radius;
world.spawnParticle(Particle.REDSTONE, x, centerY, z, 1, new Particle.DustOptions(Color.YELLOW, 1));
}

Bukkit.getScheduler().runTaskLater(PrisonEscape.getPrisonEscape(), new Runnable() {

@Override
public void run() {
loopCreateParticles(world, centerX, centerY, centerZ, radius);
}

}, 10);
}

private void deleteFromWorld() {
World world = BukkitWorldEditor.getWorld();
Location location = new Location(world, _location.getX(), _location.getY(), _location.getZ());
Expand Down

0 comments on commit a71fc3c

Please sign in to comment.