Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

---
<!-- Git and GitHub -->
- [ ] The main commit(s) reference the Fibery ticket via a `TASK-NNNN` prefix in the commit message subject
- [ ] Include a human-readable description of what the pull request is trying to accomplish
- [ ] The CI build passes
---
Expand All @@ -19,8 +18,6 @@
---
<!-- Documentation -->
- [ ] Classes and public methods have documentation (that doesn't just repeat the technical subject in English)
- [ ] Logging is implemented to monitor feature usage and troubleshoot problems in production
- [ ] These ReWiki pages are affected by this change and will be adapted:
<!-- END Global settings -->
---
<!-- Support matrix -->
Expand Down
16 changes: 12 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ on:

jobs:
build:
uses: ResilientGroup/MavenSetup/.github/workflows/build.yml@1.9.0
with:
javadoc-project-name: PowerCamera
secrets: inherit
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: '21'
distribution: 'temurin'
cache: maven
- name: Build with Maven
run: mvn -B package --file pom.xml
12 changes: 9 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@

<properties>
<!-- project version -->
<revision>0.9.0</revision>
<revision>0.9.1</revision>
<changelist>-SNAPSHOT</changelist>
</properties>

<repositories>
<repository>
<id>svenar-repo</id>
<url>https://repo.svenar.nl/</url>
</repository>
<repository>
<id>reload-repo</id>
<url>https://nexus.reloadkube.managedservices.resilient-teched.com/repository/reload/</url>
Expand All @@ -44,12 +48,14 @@
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.20.4-R0.1-20241030.192207-176</version>
<version>1.21.5-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<build>
<defaultGoal>clean compile package</defaultGoal>
<finalName>${project.name}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
9 changes: 2 additions & 7 deletions src/main/java/nl/svenar/powercamera/PowerCamera.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class PowerCamera extends JavaPlugin {

public static final String WEBSITE_URL = "https://svenar.nl/powercamera";

public static final List<String> DONATION_URLS = Arrays.asList("https://ko-fi.com/svenar", "https://patreon.com/svenar");
public static final String DONATION_URL = "https://ko-fi.com/svenar";

// public Map<UUID, String> playerSelectedCamera = new HashMap<>(); // Selected camera name
// public Map<UUID, CameraMode> playerCameraMode = new HashMap<>(); // When the player is viewing the camera (/pc start & /pc preview)
Expand Down Expand Up @@ -76,7 +76,7 @@ public void onEnable() {
setupConfig();

getLogger().info("Enabled " + getPluginDescriptionFile().getName() + " v" + getPluginDescriptionFile().getVersion());
getLogger().info("If you'd like to donate, please visit " + DONATION_URLS.get(0) + " or " + DONATION_URLS.get(1));
getLogger().info("If you'd like to donate, please visit " + DONATION_URL);

int pluginId = 9107;
@SuppressWarnings("unused")
Expand Down Expand Up @@ -145,11 +145,6 @@ private void setupConfig() {
}

newPoints.add(point);
// if (point.contains(":")) {
// newPoints.add(point);
// } else {
// newPoints.add("location:" + point);
// }
}
configCameras.getConfig().set("cameras." + cameraName + ".points", newPoints);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
package nl.svenar.powercamera.commands.subcommand;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.command.BlockCommandSender;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import nl.svenar.powercamera.CameraHandler;
import nl.svenar.powercamera.PowerCamera;
import nl.svenar.powercamera.commands.PowerCameraCommand;
import nl.svenar.powercamera.commands.structure.CommandExecutionContext;
import nl.svenar.powercamera.data.CameraMode;
import nl.svenar.powercamera.data.PlayerCameraData;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

@SuppressWarnings({"PMD.AvoidLiteralsInIfCondition", "PMD.CommentRequired", "PMD.LocalVariableCouldBeFinal", "PMD.MethodArgumentCouldBeFinal"})
@SuppressWarnings({ "PMD.AvoidLiteralsInIfCondition", "PMD.CommentRequired", "PMD.LocalVariableCouldBeFinal",
"PMD.MethodArgumentCouldBeFinal" })
public class SubcommandStartOther extends PowerCameraCommand {

public SubcommandStartOther(PowerCamera plugin, String commandName) {
Expand All @@ -22,7 +30,8 @@ public SubcommandStartOther(PowerCamera plugin, String commandName) {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
if (args.length != 2) {
sendMessage(sender, ChatColor.DARK_RED + "Usage: /" + commandLabel + " startother <playername> <cameraname>");
sendMessage(sender,
ChatColor.DARK_RED + "Usage: /" + commandLabel + " startother <playername> <cameraname>");
return false;
}

Expand All @@ -34,27 +43,77 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel,
return false;
}

Player targetPlayer = Bukkit.getPlayer(targetName);
List<Player> targetPlayers = getPlayersFromSelector(sender, targetName);

if (targetPlayer == null) {
sendMessage(sender, ChatColor.DARK_RED + "Player '" + targetName + "' not found or is offline!");
if (targetPlayers.isEmpty()) {
sendMessage(sender, ChatColor.DARK_RED + "No matching players found for selector '" + targetName + "'");
return false;
}

PlayerCameraData cameraData = plugin.getPlayerData().get(targetPlayer);
for (Player targetPlayer : targetPlayers) {
PlayerCameraData cameraData = plugin.getPlayerData().get(targetPlayer);

if (cameraData.getCameraMode() != CameraMode.NONE) {
sendMessage(sender, ChatColor.DARK_RED + "Player '" + targetPlayer.getName() + "' already has a camera active!");
return false;
}
if (cameraData.getCameraMode() != CameraMode.NONE) {
sendMessage(sender,
ChatColor.DARK_RED + "Player '" + targetPlayer.getName() + "' already has a camera active!");
continue;
}

if (this.plugin.getConfigCameras().cameraExists(cameraName)) {
cameraData.setCameraHandler(new CameraHandler(plugin, targetPlayer, cameraName).generatePath().start());
sender.sendMessage(plugin.getPluginChatPrefix() + ChatColor.GREEN + "Playing '" + cameraName + "' on player: " + targetPlayer.getName());
} else {
sendMessage(sender, ChatColor.RED + "Camera '" + cameraName + "' not found!");
if (this.plugin.getConfigCameras().cameraExists(cameraName)) {
cameraData.setCameraHandler(new CameraHandler(plugin, targetPlayer, cameraName).generatePath().start());
sender.sendMessage(plugin.getPluginChatPrefix() + ChatColor.GREEN + "Playing '" + cameraName
+ "' on player: " + targetPlayer.getName());
} else {
sendMessage(sender, ChatColor.RED + "Camera '" + cameraName + "' not found!");
break;
Copy link

Copilot AI Jun 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of 'break' in the loop when a camera is not found might prematurely end processing of other valid target players. Consider using 'continue' to ensure all players are evaluated.

Suggested change
break;
continue;

Copilot uses AI. Check for mistakes.
}
}

return false;
}

private List<Player> getPlayersFromSelector(CommandSender sender, String selector) {
selector = selector.replace("@", "").toLowerCase();

if (selector.equals("a")) {
// All online players
return new ArrayList<>(Bukkit.getOnlinePlayers());
}

if (selector.equals("r")) {
// Random online player
List<Player> players = new ArrayList<>(Bukkit.getOnlinePlayers());
if (!players.isEmpty()) {
return List.of(players.get(new Random().nextInt(players.size())));
Copy link

Copilot AI Jun 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creating a new Random instance each time this method is called might be less efficient; consider caching a Random instance at the class level.

Suggested change
return List.of(players.get(new Random().nextInt(players.size())));
return List.of(players.get(RANDOM.nextInt(players.size())));

Copilot uses AI. Check for mistakes.
}
return List.of();
}

if (selector.equals("p")) {
// Nearest player to the command block or sender
if (sender instanceof BlockCommandSender blockSender) {
Location blockLocation = blockSender.getBlock().getLocation();
double closestDistance = Double.MAX_VALUE;
Player closestPlayer = null;

for (Player player : Bukkit.getOnlinePlayers()) {
double distance = player.getLocation().distanceSquared(blockLocation);
if (distance < closestDistance) {
closestDistance = distance;
closestPlayer = player;
}
}

return closestPlayer != null ? List.of(closestPlayer) : List.of();
}

if (sender instanceof Player player) {
return List.of(player);
}
}

Player namedPlayer = Bukkit.getPlayer(selector);
return namedPlayer != null ? List.of(namedPlayer) : List.of();
}

}