Compare commits
6 Commits
96fce606cf
...
0399d737dc
Author | SHA1 | Date |
---|---|---|
langua | 0399d737dc | |
Intelli | 6023c21ba9 | |
Intelli | 3e3496ad12 | |
langua | 1595b18a00 | |
langua | feb36b03a2 | |
langua | 8dd263e839 |
|
@ -25,8 +25,8 @@ logRemoval(String user, BlockState blockState)
|
|||
|
||||
## Getting Started
|
||||
|
||||
Ensure you're using CoreProtect 21.0 or higher. Add it as an external jar to your plugin in your IDE.
|
||||
Alternatively, if using Maven, you can add it via the repository [https://maven.playpro.com](https://maven.playpro.com) (net.coreprotect, 21.0).
|
||||
Ensure you're using CoreProtect 23.0 or higher. Add it as an external jar to your plugin in your IDE.
|
||||
Alternatively, if using Maven, you can add it via the repository [https://maven.playpro.com](https://maven.playpro.com) (net.coreprotect, 23.0).
|
||||
|
||||
The first thing you need to do is get access to CoreProtect. You can do this by using code similar to the following:
|
||||
|
||||
|
@ -49,7 +49,7 @@ private CoreProtectAPI getCoreProtect() {
|
|||
}
|
||||
|
||||
// Check that a compatible version of the API is loaded
|
||||
if (CoreProtect.APIVersion() < 9) {
|
||||
if (CoreProtect.APIVersion() < 10) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ import net.coreprotect.config.Config;
|
|||
import net.coreprotect.config.ConfigHandler;
|
||||
import net.coreprotect.database.statement.BlockStatement;
|
||||
import net.coreprotect.database.statement.UserStatement;
|
||||
import net.coreprotect.event.CoreProtectBlockBreakPreLogEvent;
|
||||
import net.coreprotect.event.CoreProtectPreLogEvent;
|
||||
import net.coreprotect.thread.CacheHandler;
|
||||
import net.coreprotect.utility.Util;
|
||||
|
@ -53,20 +54,28 @@ public class BlockBreakLogger {
|
|||
blockData = overrideData;
|
||||
}
|
||||
|
||||
CoreProtectPreLogEvent event = new CoreProtectPreLogEvent(user);
|
||||
// call events and fetch changed username, all other properties are readonly for now
|
||||
CoreProtectPreLogEvent coreProtectPreLogEvent = new CoreProtectPreLogEvent(user);
|
||||
if (Config.getGlobal().API_ENABLED) {
|
||||
CoreProtect.getInstance().getServer().getPluginManager().callEvent(event);
|
||||
CoreProtect.getInstance().getServer().getPluginManager().callEvent(coreProtectPreLogEvent);
|
||||
}
|
||||
user = coreProtectPreLogEvent.getUser();
|
||||
|
||||
int userId = UserStatement.getId(preparedStmt, event.getUser(), true);
|
||||
CoreProtectBlockBreakPreLogEvent coreProtectBlockBreakPreLogEvent = new CoreProtectBlockBreakPreLogEvent(user, location);
|
||||
if (Config.getGlobal().API_ENABLED) {
|
||||
CoreProtect.getInstance().getServer().getPluginManager().callEvent(coreProtectBlockBreakPreLogEvent);
|
||||
}
|
||||
user = coreProtectBlockBreakPreLogEvent.getUser();
|
||||
|
||||
int userId = UserStatement.getId(preparedStmt, user, true);
|
||||
int wid = Util.getWorldId(location.getWorld().getName());
|
||||
int time = (int) (System.currentTimeMillis() / 1000L);
|
||||
int x = location.getBlockX();
|
||||
int y = location.getBlockY();
|
||||
int z = location.getBlockZ();
|
||||
CacheHandler.breakCache.put("" + x + "." + y + "." + z + "." + wid + "", new Object[] { time, event.getUser(), type });
|
||||
CacheHandler.breakCache.put("" + x + "." + y + "." + z + "." + wid + "", new Object[]{time, user, type});
|
||||
|
||||
if (event.isCancelled()) {
|
||||
if (coreProtectPreLogEvent.isCancelled() || coreProtectBlockBreakPreLogEvent.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ import net.coreprotect.config.Config;
|
|||
import net.coreprotect.config.ConfigHandler;
|
||||
import net.coreprotect.database.statement.BlockStatement;
|
||||
import net.coreprotect.database.statement.UserStatement;
|
||||
import net.coreprotect.event.CoreProtectBlockPlacePreLogEvent;
|
||||
import net.coreprotect.event.CoreProtectPreLogEvent;
|
||||
import net.coreprotect.thread.CacheHandler;
|
||||
import net.coreprotect.utility.Util;
|
||||
|
@ -83,20 +84,28 @@ public class BlockPlaceLogger {
|
|||
}
|
||||
}
|
||||
|
||||
CoreProtectPreLogEvent event = new CoreProtectPreLogEvent(user);
|
||||
// call events and fetch changed username, all other properties are readonly for now
|
||||
CoreProtectPreLogEvent coreProtectPreLogEvent = new CoreProtectPreLogEvent(user);
|
||||
if (Config.getGlobal().API_ENABLED) {
|
||||
CoreProtect.getInstance().getServer().getPluginManager().callEvent(event);
|
||||
CoreProtect.getInstance().getServer().getPluginManager().callEvent(coreProtectPreLogEvent);
|
||||
}
|
||||
user = coreProtectPreLogEvent.getUser();
|
||||
|
||||
int userId = UserStatement.getId(preparedStmt, event.getUser(), true);
|
||||
CoreProtectBlockPlacePreLogEvent coreProtectBlockPlacePreLogEvent = new CoreProtectBlockPlacePreLogEvent(user, block.getLocation(), block);
|
||||
if (Config.getGlobal().API_ENABLED) {
|
||||
CoreProtect.getInstance().getServer().getPluginManager().callEvent(coreProtectBlockPlacePreLogEvent);
|
||||
}
|
||||
user = coreProtectBlockPlacePreLogEvent.getUser();
|
||||
|
||||
int userId = UserStatement.getId(preparedStmt, user, true);
|
||||
int wid = Util.getWorldId(block.getWorld().getName());
|
||||
int time = (int) (System.currentTimeMillis() / 1000L);
|
||||
|
||||
if (event.getUser().length() > 0) {
|
||||
CacheHandler.lookupCache.put("" + x + "." + y + "." + z + "." + wid + "", new Object[] { time, event.getUser(), type });
|
||||
if (user.length() > 0) {
|
||||
CacheHandler.lookupCache.put("" + x + "." + y + "." + z + "." + wid + "", new Object[]{time, user, type});
|
||||
}
|
||||
|
||||
if (event.isCancelled()) {
|
||||
if (coreProtectPreLogEvent.isCancelled() || coreProtectBlockPlacePreLogEvent.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
package net.coreprotect.event;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
public class CoreProtectBlockBreakPreLogEvent extends Event implements Cancellable {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private String user;
|
||||
private final Location location;
|
||||
private boolean cancelled = false;
|
||||
|
||||
public CoreProtectBlockBreakPreLogEvent(String user, Location location) {
|
||||
super(true); // async
|
||||
this.user = user;
|
||||
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean b) {
|
||||
cancelled = b;
|
||||
}
|
||||
|
||||
public String getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(String newUser) {
|
||||
if (newUser == null || newUser.isEmpty()) {
|
||||
throw new IllegalArgumentException("Invalid user");
|
||||
}
|
||||
|
||||
this.user = newUser;
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
package net.coreprotect.event;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
public class CoreProtectBlockPlacePreLogEvent extends Event implements Cancellable {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private String user;
|
||||
private final Location location;
|
||||
private final BlockState blockState;
|
||||
private boolean cancelled = false;
|
||||
|
||||
public CoreProtectBlockPlacePreLogEvent(String user, Location location, BlockState blockState) {
|
||||
super(true); // async
|
||||
this.user = user;
|
||||
this.location = location;
|
||||
this.blockState = blockState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean b) {
|
||||
cancelled = b;
|
||||
}
|
||||
|
||||
public String getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(String newUser) {
|
||||
if (newUser == null || newUser.isEmpty()) {
|
||||
throw new IllegalArgumentException("Invalid user");
|
||||
}
|
||||
|
||||
this.user = newUser;
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public BlockState getBlockState() {
|
||||
return blockState;
|
||||
}
|
||||
}
|
|
@ -28,7 +28,7 @@ public final class HopperPullListener {
|
|||
}
|
||||
}
|
||||
|
||||
ItemStack[] sourceContainer = Util.getContainerState(sourceHolder.getInventory().getContents());
|
||||
ItemStack[] destinationContainer = Util.getContainerState(destinationHolder.getInventory().getContents());
|
||||
ItemStack movedItem = item.clone();
|
||||
|
||||
final long taskStarted = InventoryChangeListener.tasksStarted.incrementAndGet();
|
||||
|
@ -39,7 +39,7 @@ public final class HopperPullListener {
|
|||
}
|
||||
|
||||
boolean abort = false;
|
||||
boolean addedInventory = Util.canAddContainer(sourceContainer, movedItem, sourceHolder.getInventory().getMaxStackSize());
|
||||
boolean addedInventory = Util.canAddContainer(destinationContainer, movedItem, destinationHolder.getInventory().getMaxStackSize());
|
||||
if (!addedInventory) {
|
||||
abort = true;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue