Skip to content

Commit

Permalink
add support for proper logging of CustomBlocks, bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
WakkaFlocka239 committed Dec 7, 2023
1 parent 2e82273 commit 97f6d01
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 3 deletions.
16 changes: 15 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
}

group = 'net.coreprotect'
String projectVersion = '22.2'
String projectVersion = '22.3.1'
String projectBranch = ''
version = projectVersion // `version` might be modified, we don't always want that (e.g. plugin.yml)
description = 'Provides block protection for your server.'
Expand Down Expand Up @@ -83,6 +83,20 @@ processResources {
})
}

tasks {
compileJava {
options.encoding = "UTF-8"
options.release.set(17)
options.compilerArgs.add("-parameters")
}

javadoc { options.encoding = "UTF-8" }

processResources {
filteringCharset = "UTF-8"
}
}

publishing {
publications {
mavenJava(MavenPublication) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import java.sql.PreparedStatement;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.atomic.AtomicBoolean;

import net.coreprotect.event.CoreProtectPreLogBlockEvent;
import net.coreprotect.event.CoreProtectPreLogBlockEvent.BlockAction;
import org.bukkit.Location;
import org.bukkit.Material;

Expand Down Expand Up @@ -65,6 +68,14 @@ else if (checkType == Material.PAINTING || BukkitAdapter.ADAPTER.isItemFrame(che
return;
}

CoreProtectPreLogBlockEvent blockEvent = new CoreProtectPreLogBlockEvent(user, BlockAction.BREAK, location, checkType, blockData);
if (Config.getGlobal().API_ENABLED) {
CoreProtect.getInstance().getServer().getPluginManager().callEvent(blockEvent);

if(blockEvent.isCancelled())
return;
}

BlockStatement.insert(preparedStmt, batchCount, time, userId, wid, x, y, z, type, data, meta, blockData, 0, 0);
}
catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import java.util.List;
import java.util.Locale;

import net.coreprotect.event.CoreProtectPreLogBlockEvent;
import net.coreprotect.event.CoreProtectPreLogBlockEvent.BlockAction;
import org.bukkit.Material;
import org.bukkit.block.BlockState;

Expand Down Expand Up @@ -96,6 +98,14 @@ else if (type == Material.WATER || type == Material.LAVA) {
return;
}

CoreProtectPreLogBlockEvent blockEvent = new CoreProtectPreLogBlockEvent(user, BlockAction.PLACE, block.getLocation(), type, blockData);
if (Config.getGlobal().API_ENABLED) {
CoreProtect.getInstance().getServer().getPluginManager().callEvent(blockEvent);

if(blockEvent.isCancelled())
return;
}

int internalType = Util.getBlockId(type.name(), true);
if (replacedType > 0 && Util.getType(replacedType) != Material.AIR && Util.getType(replacedType) != Material.CAVE_AIR) {
BlockStatement.insert(preparedStmt, batchCount, time, userId, wid, x, y, z, replacedType, replacedData, null, replaceBlockData, 0, 0);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package net.coreprotect.event;

import org.bukkit.Location;
import org.bukkit.Material;

public class CoreProtectPreLogBlockEvent extends CoreProtectPreLogEvent {
private boolean cancelled = false;

BlockAction action;
Location location;
Material type;
String blockData;

public CoreProtectPreLogBlockEvent(String user, BlockAction action, Location location, Material type, String blockData) {
super(user);
this.action = action;
this.location = location;
this.type = type;
this.blockData = blockData;
}

public BlockAction getAction() {
return action;
}

public Location getLocation() {
return location;
}

public Material getType() {
return type;
}

public String getBlockData() {
return blockData;
}

public enum BlockAction {
PLACE,
BREAK
}

@Override
public boolean isCancelled() {
return cancelled;
}

@Override
public void setCancelled(boolean cancel) {
cancelled = cancel;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public Collection<ItemStack> getDrops(ItemStack tool, Entity entity) {
return null;
}

@Override
//@Override
public BlockState copy() {
// TODO Auto-generated method stub
return null;
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: CoreProtect
main: net.coreprotect.CoreProtect
version: ${project.version}
branch: ${project.branch}
branch: development
api-version: 1.13
folia-supported: true
website: http://coreprotect.net
Expand Down

0 comments on commit 97f6d01

Please sign in to comment.