Skip to content
Open
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
35 changes: 35 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
on:
push:
paths:
- 'src/**'
- 'pom.xml'
pull_request:
paths:
- 'src/**'
- 'pom.xml'
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- id: vars
run: |
echo "JAVA=$(mvn help:evaluate -Dexpression=maven.compiler.release -q -DforceStdout)" >> "$GITHUB_OUTPUT"
echo "VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> "$GITHUB_OUTPUT"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

should be "VERS", not "VERSION"

- uses: actions/setup-java@v5
with:
distribution: liberica
java-version: ${{ steps.vars.outputs.JAVA }}
- run: ./src/build/scripts/TestCode.sh
- run: mvn -B package -DskipTests
- uses: actions/upload-artifact@v7
with:
name: wlib-${{ steps.vars.outputs.VERSION }}
path: target/wlib-${{ steps.vars.outputs.VERSION }}.jar
if-no-files-found: error
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@

**/.DS_Store

/dependency-reduced-pom.xml
/dependency-reduced-pom.xml

.vscode

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

.vscode should be with the existing directory ignores at the top

2 changes: 2 additions & 0 deletions src/build/scripts/TestCode.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@echo off
mvn test %*
1 change: 1 addition & 0 deletions src/build/scripts/TestCode.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mvn test $@
46 changes: 23 additions & 23 deletions src/main/java/xyz/webmc/wlib/api/command/WCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ public final void sendPermissionMessage(CommandSender sender, String alias) {
}

public final void sendUsageMessage(CommandSender sender) {
sendUsageMessage(sender, "");
this.sendUsageMessage(sender, "");
}

public final void sendPermissionMessage(CommandSender sender) {
sendPermissionMessage(sender, "");
this.sendPermissionMessage(sender, "");
}

protected final boolean checkIsPlayer(CommandSender sender) {
Expand All @@ -92,6 +92,27 @@ protected final boolean checkHasPermission(CommandSender sender, String perm) {
}
}

public static void sendUnknownCommandMessage(CommandSender sender) {
boolean bool = true;

final Class<?> clazz = MirrorSafe.getClass("org.spigotmc.SpigotConfig");
if (clazz != null) {
final String msg = MirrorSafe.getFieldValue(clazz, "unknownCommandMessage");
if (msg != null) {
sender.sendMessage(msg);
bool = false;
}
}

if (bool) {
sender.sendMessage(ChatColor.RED + "Unknown command.");
}
}

public static void sendOnlyPlayersMessage(CommandSender sender) {
sender.sendMessage(ChatColor.RED + "This command can only be used by players.");
}
Comment on lines +95 to +114

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

static methods go under instance methods


private void showStack(CommandSender sender, Throwable t) {
final String stack = ExceptionStacker.getFullStackString(t);

Expand Down Expand Up @@ -121,25 +142,4 @@ private String replaceUsedAlias(String str, String alias) {
return str;
}
}

public static void sendUnknownCommandMessage(CommandSender sender) {
boolean bool = true;

final Class<?> clazz = MirrorSafe.getClass("org.spigotmc.SpigotConfig");
if (clazz != null) {
final String msg = MirrorSafe.getFieldValue(clazz, "unknownCommandMessage");
if (msg != null) {
sender.sendMessage(msg);
bool = false;
}
}

if (bool) {
sender.sendMessage(ChatColor.RED + "Unknown command.");
}
}

public static void sendOnlyPlayersMessage(CommandSender sender) {
sender.sendMessage(ChatColor.RED + "This command can only be used by players.");
}
}
34 changes: 34 additions & 0 deletions src/main/java/xyz/webmc/wlib/api/structure/AbsoluteStructure.java
Comment thread
noone-075 marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (C) 2026 Colbster937
*
* SPDX-License-Identifier: AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* See the LICENSE file for details.
*/

package xyz.webmc.wlib.api.structure;

import xyz.webmc.wlib.api.structure.placeable.AbsolutePlaceableStructure;

import org.bukkit.Location;

public abstract class AbsoluteStructure implements BaseStructure {
public abstract AbsolutePlaceableStructure build(Location loc);

@Override
public final void place(Location loc, Object... chunks) {
if (chunks.length > 0) {
final AbsolutePlaceableStructure builder = this.build(loc);
for (Object chk: chunks){
builder.place(chk);
}
} else {
this.build(loc).place();
}
}
Comment thread
noone-075 marked this conversation as resolved.
Comment thread
noone-075 marked this conversation as resolved.
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,20 @@

package xyz.webmc.wlib.api.structure;

import xyz.webmc.wlib.api.WLIB;

import java.io.IOException;
import java.io.InputStream;

import net.sandrohc.schematic4j.exception.ParsingException;

@SuppressWarnings({ "removal" })
@Deprecated(forRemoval = true)
public abstract class AbstractBaseSchemStructure extends AbstractBaseStructure {
@Deprecated(forRemoval = true)
public AbstractBaseSchemStructure(String name, String resource) throws IOException, ParsingException {
super(name);
WLIB.warnDeprecatedUsage();

try (InputStream is = this.getClass().getResourceAsStream(resource)) {
super.loadSchematic(is);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@

package xyz.webmc.wlib.api.structure;

import xyz.webmc.wlib.api.structure.block.BlockRelative;
import xyz.webmc.wlib.api.structure.iface.TestStructure;
import xyz.webmc.wlib.api.WLIB;
import xyz.webmc.wlib.api.util.SchemUtil;
import xyz.webmc.wlib.internal.util.TestStructureUtil;

import java.io.File;
import java.io.FileInputStream;
Expand All @@ -35,45 +33,62 @@
import net.sandrohc.schematic4j.schematic.types.SchematicBlockPos;
import org.bukkit.Location;

@SuppressWarnings({ "unchecked" })
@SuppressWarnings({ "unchecked", "removal" })
@Deprecated(forRemoval = true)
public abstract class AbstractBaseStructure {
private static final Map<Class<? extends AbstractBaseStructure>, AbstractBaseStructure> INSTANCES = new HashMap<>();

private final List<BlockRelative> blocks = new ArrayList<>();
private final String name;

@Deprecated(forRemoval = true)
protected AbstractBaseStructure(String name) {
WLIB.warnDeprecatedUsage();
this.name = name;
}

@Deprecated(forRemoval = true)
public final void place(Location loc) {
WLIB.warnDeprecatedUsage();
final Location offset = loc.clone().add(this.getOffsetX(), this.getOffsetY(), this.getOffsetZ());
for (BlockRelative blk : blocks) {
blk.place(offset);
}
}

@Deprecated(forRemoval = true)
public final String getName() {
WLIB.warnDeprecatedUsage();
return this.name;
}

@Deprecated(forRemoval = true)
public int getOffsetX() {
WLIB.warnDeprecatedUsage();
return 0;
}

@Deprecated(forRemoval = true)
public int getOffsetY() {
WLIB.warnDeprecatedUsage();
return 0;
}

@Deprecated(forRemoval = true)
public int getOffsetZ() {
WLIB.warnDeprecatedUsage();
return 0;
}

@Deprecated(forRemoval = true)
protected final void addBlock(BlockRelative blk) {
WLIB.warnDeprecatedUsage();
this.blocks.add(blk);
}

@Deprecated(forRemoval = true)
protected final void loadSchematic(InputStream is) throws IOException, ParsingException {
WLIB.warnDeprecatedUsage();
try (is) {
final Schematic schematic = SchemUtil.readSchematic(is);

Expand Down Expand Up @@ -111,19 +126,20 @@ protected final void loadSchematic(InputStream is) throws IOException, ParsingEx
}
}

@Deprecated(forRemoval = true)
protected final void loadSchematic(File file) throws IOException, ParsingException {
WLIB.warnDeprecatedUsage();
loadSchematic(new FileInputStream(file));
}

public static <T extends AbstractBaseStructure> T getInstance(Class<T> clazz, Object... params) {
@Deprecated(forRemoval = true)
public static final <T extends AbstractBaseStructure> T getInstance(Class<T> clazz, Object... params) {
WLIB.warnDeprecatedUsage();
AbstractBaseStructure structure = INSTANCES.get(clazz);

if (structure == null) {
structure = MirrorSafe.invokeConstructor(clazz, params);
INSTANCES.put(clazz, structure);
if (structure instanceof TestStructure) {
TestStructureUtil.register(structure);
}
}

return (T) structure;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@
* See the LICENSE file for details.
*/

package xyz.webmc.wlib.api.structure.iface;
package xyz.webmc.wlib.api.structure;

public interface TestStructure {
import org.bukkit.Location;

public interface BaseStructure {
void place(Location loc, Object... chunks);

default String getName() {
return this.getClass().getSimpleName();
}
}
Loading