Compare commits

...

8 Commits

Author SHA1 Message Date
Teriuihi 91ba53208b Merge branch 'refs/heads/master' into fix_rotate 2024-08-04 22:27:32 +02:00
Teriuihi 7783101887 Add Jenkinsfile for CI pipeline
Introduce a Jenkinsfile to automate the build process using Gradle. The pipeline consists of three stages: building with Gradle, archiving artifacts, and sending build notifications to Discord. This integration enhances the CI/CD workflow by ensuring consistent builds and timely notifications.
2024-08-04 22:26:57 +02:00
Teriuihi f616ed5af0 Switch config paths to use /mnt directory
Updated file paths for configuration and message files to use the /mnt directory instead of the user's home directory.
2024-08-04 22:26:46 +02:00
Teriuihi 2bdf8b6b48 Remove temporary debug logging in RotateBlockEvent & fixed drip leaf & iron trap door rotation
The update primarily eradicates numerous debug logging lines in the RotateBlockEvent class. This cleanup improves the readability of the code and enhances performance by reducing unnecessary logging operations. The "toggleDripLeaf" and "toggleTrapDoor" methods have also been updated to verify block data.
2024-07-07 15:17:32 +02:00
Teriuihi f3f6d11547 Add logging to RotateBlockEvent
Debug logs were added to the RotateBlockEvent class. These logs will help track the flow of various states and actions, such as the current material and action type, whether the block is a trap door or a drip leaf, among others. This enhancement will assist debugging by providing more visibility into the state of the application at runtime.
2024-07-01 20:39:07 +02:00
Teriuihi a5f59c2399 Fixed ordinal check being made before incrementing
In the RotateBlockEvent class, a bug was fixed where the ordinal check was previously being done before the ordinal was incremented.
2024-06-30 20:37:24 +02:00
Teriuihi 6209b71db4 Add block interaction enhancements and git properties
Updated block interaction behavior for IRON_TRAPDOOR and BIG_DRIPLEAF_PLACEABLE to allow their state to be toggled. Added the use of git properties to build.gradle.kts, allowing insightful git information such as commit id and time to be retrieved and printed.
2024-06-30 20:28:18 +02:00
Teriuihi df875406e1 Add distance check to TeleportEvent
In addition to checking if a player is on a vehicle, the update now also checks if the distance between the player's current location and the teleport destination is more than 5 blocks. If that's the case, the teleportation is cancelled.
2024-06-28 23:23:50 +02:00
7 changed files with 68 additions and 17 deletions

20
Jenkinsfile vendored Normal file
View File

@ -0,0 +1,20 @@
pipeline {
agent any
stages {
stage('Gradle') {
steps {
sh 'bash gradlew build'
}
}
stage('Archive') {
steps {
archiveArtifacts artifacts: 'build/libs/', followSymlinks: false
}
}
stage('discord') {
steps {
discordSend description: "Build: ${BUILD_NUMBER}", showChangeset: true, result: currentBuild.currentResult, title: currentBuild.fullProjectName, webhookURL: env.discordwebhook
}
}
}
}

View File

@ -1,6 +1,7 @@
plugins {
id("java")
id("maven-publish")
id("com.gorylenko.gradle-git-properties") version "2.3.1"
}
group = "com.alttd"
@ -15,6 +16,10 @@ java {
}
}
gitProperties {
keys = listOf("git.commit.id", "git.commit.time")
}
tasks {
withType<JavaCompile> {
options.encoding = Charsets.UTF_8.name()

View File

@ -11,6 +11,10 @@ import com.alttd.playerutils.util.Logger;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public final class PlayerUtils extends JavaPlugin {
private Logger logger;
@ -22,6 +26,20 @@ public final class PlayerUtils extends JavaPlugin {
registerCommands();
registerEvents();
reloadConfigs();
printVersion();
}
private void printVersion() {
Properties gitProps = new Properties();
try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream("git.properties")) {
gitProps.load(inputStream);
} catch (IOException e) {
logger.severe("Unable to load git.properties, unknown version");
return;
}
logger.info("Git commit ID: %s".formatted(gitProps.getProperty("git.commit.id")));
logger.info("Git commit time: %s".formatted(gitProps.getProperty("git.commit.time")));
}
@Override
@ -37,7 +55,7 @@ public final class PlayerUtils extends JavaPlugin {
pluginManager.registerEvents(new XpBottleEvent(this, logger), this);
pluginManager.registerEvents(new TeleportEvent(), this);
RotateBlockEvent rotateBlockEvent = new RotateBlockEvent();
RotateBlockEvent rotateBlockEvent = new RotateBlockEvent(logger);
pluginManager.registerEvents(rotateBlockEvent, this);
playerUtilsCommand.addSubCommand(new RotateBlock(rotateBlockEvent));
}

View File

@ -11,8 +11,8 @@ public class Config extends AbstractConfig{
Config(Logger logger) {
super(
new File(System.getProperty("user.home") + File.separator
+ "share" + File.separator
new File(File.separator
+ "mnt" + File.separator
+ "configs" + File.separator
+ "PlayerUtils"),
"config.yml", logger);

View File

@ -11,8 +11,8 @@ public class Messages extends AbstractConfig {
Messages(Logger logger) {
super(
new File(System.getProperty("user.home") + File.separator
+ "share" + File.separator
new File(File.separator
+ "mnt" + File.separator
+ "configs" + File.separator
+ "PlayerUtils"),
"messages.yml", logger);

View File

@ -1,5 +1,6 @@
package com.alttd.playerutils.event_listeners;
import com.alttd.playerutils.util.Logger;
import org.bukkit.Axis;
import org.bukkit.Bukkit;
import org.bukkit.Material;
@ -23,8 +24,13 @@ import java.util.stream.Collectors;
public class RotateBlockEvent implements Listener {
private final HashSet<UUID> rotateEnabled = new HashSet<>();
private final Logger logger;
private static final List<BlockFace> VALID_FOUR_STATES = List.of(BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST);
public RotateBlockEvent(Logger logger) {
this.logger = logger;
}
public synchronized boolean toggleRotate(UUID uuid) {
if (rotateEnabled.contains(uuid)) {
@ -55,7 +61,14 @@ public class RotateBlockEvent implements Listener {
return;
Material type = block.getType();
if (Tag.STAIRS.isTagged(type)) {
logger.debug(String.format("Material %s with action %s", type, event.getAction().isLeftClick() ? "left click" : "right click"));
if (type.equals(Material.IRON_TRAPDOOR) && event.getAction().isLeftClick()) {
event.setCancelled(true);
toggleTrapDoor(block, player);
} else if (type.equals(Material.BIG_DRIPLEAF) && event.getAction().isLeftClick()) {
event.setCancelled(true);
toggleDripLeaf(block, player);
} else if (Tag.STAIRS.isTagged(type)) {
event.setCancelled(true);
rotateStairs(block, player);
} else if (Tag.WALLS.isTagged(type)) {
@ -67,12 +80,6 @@ public class RotateBlockEvent implements Listener {
} else if(Tag.RAILS.isTagged(type)) {
event.setCancelled(true);
toggleRails(block, player);
} else if (type.equals(Material.IRON_TRAPDOOR) && event.getAction().isLeftClick()) {
event.setCancelled(true);
toggleTrapDoor(block, player);
} else if (Tag.BIG_DRIPLEAF_PLACEABLE.isTagged(type) && event.getAction().isLeftClick()) {
event.setCancelled(true);
toggleDripLeaf(block, player);
} else if (block.getBlockData() instanceof Directional directional) {
event.setCancelled(true);
rotateDirectionalBlock(block, directional, player);
@ -83,7 +90,7 @@ public class RotateBlockEvent implements Listener {
}
private void toggleDripLeaf(Block block, Player player) {
if (!(block instanceof BigDripleaf bigDripleaf)) {
if (!(block.getBlockData() instanceof BigDripleaf bigDripleaf)) {
return;
}
@ -94,10 +101,8 @@ public class RotateBlockEvent implements Listener {
BigDripleaf.Tilt[] values = BigDripleaf.Tilt.values();
int ordinal = bigDripleaf.getTilt().ordinal();
if (ordinal == values.length) {
if (++ordinal == values.length) {
ordinal = 0;
} else {
ordinal++;
}
bigDripleaf.setTilt(values[ordinal]);
@ -105,7 +110,7 @@ public class RotateBlockEvent implements Listener {
}
private void toggleTrapDoor(Block block, Player player) {
if (!(block instanceof TrapDoor trapDoor)) {
if (!(block.getBlockData() instanceof TrapDoor trapDoor)) {
return;
}
@ -114,6 +119,7 @@ public class RotateBlockEvent implements Listener {
}
trapDoor.setOpen(!trapDoor.isOpen());
block.setBlockAndForget(trapDoor);
}
private void toggleRails(Block block, Player player) {

View File

@ -18,6 +18,8 @@ public class TeleportEvent implements Listener {
Player player = event.getPlayer();
if (player.getVehicle() == null)
return;
if (event.getTo().distance(event.getFrom()) < 5)
return;
event.setCancelled(true);
player.sendRichMessage("<red>Teleporting was cancelled. You can not be sitting, or mounted while teleporting.");
}