Skip to content

Commit

Permalink
fix: приваты
Browse files Browse the repository at this point in the history
- исправлены ломание блоков в привате(в теории может сломать некоторые плагины)
  • Loading branch information
Reider745 committed Dec 18, 2023
1 parent a17a126 commit 1d26c8f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
16 changes: 5 additions & 11 deletions src/main/java/com/reider745/api/CallbackHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,11 @@ public ThreadCallbackEvent(Event event, ICallbackApply apply, boolean isPrevente

@Override
public void run() {
if (isPrevented && event.isCancelled())
return;
apply.apply();
event.setCancelled(isPrevent());
if (!event.isCancelled() || isPrevented){
apply.apply();
if(isPrevent())
event.setCancelled();
}
}
}

Expand Down Expand Up @@ -134,13 +135,6 @@ public static void apply(Event event, ICallbackApply apply, boolean isPrevented)
}
}

public static void apply(HookController controller, ICallbackApply apply) {
Thread thread = new ThreadCallbackController(controller, apply);
thread.start();
while (thread.isAlive()) {
}
}

public static void prevent() {
Thread thread = Thread.currentThread();

Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/reider745/event/EventListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@
import com.zhekasmirnov.innercore.api.NativeItemInstanceExtra;

public class EventListener implements Listener {
public static void preventedCallback(Event event, CallbackHelper.ICallbackApply apply) {
CallbackHelper.apply(event, apply, true);
}
public static void preventedCallback(Event event, CallbackHelper.ICallbackApply apply, boolean isPrevent) {
CallbackHelper.apply(event, apply, isPrevent);
}

public static void preventedCallback(Event event, CallbackHelper.ICallbackApply apply) {
CallbackHelper.apply(event, apply,false);
}

@EventHandler(priority = EventPriority.LOWEST)
public void use(PlayerInteractEvent event) {
Vector3 pos = event.getTouchVector();
Expand All @@ -55,11 +56,10 @@ public void use(PlayerInteractEvent event) {
player.getHealth() > 0, player.getId()));
}

@EventHandler(priority = EventPriority.LOWEST)
public void breakBlock(BlockBreakEvent event) {
public static void eventBreakBlock(BlockBreakEvent event, boolean isNukkitPrevent) {
Block block = event.getBlock();
preventedCallback(event, () -> NativeCallback.onBlockDestroyed((int) block.x, (int) block.y, (int) block.z,
event.getFace().getIndex(), event.getPlayer().getId()));
event.getFace().getIndex(), event.getPlayer().getId()), isNukkitPrevent);
}

@EventHandler(priority = EventPriority.LOWEST)
Expand Down
15 changes: 13 additions & 2 deletions src/main/java/com/reider745/hooks/LevelHooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.reider745.api.hooks.HookClass;
import com.reider745.api.hooks.annotation.Hooks;
import com.reider745.api.hooks.annotation.Inject;
import com.reider745.event.EventListener;
import javassist.CtClass;
import javassist.CtField;
import javassist.Modifier;
Expand Down Expand Up @@ -104,18 +105,28 @@ public static Item useBreakOn(Level level, Vector3 vector, BlockFace face, Item
boolean fastBreak = (player.lastBreak + breakTime * 1000) > Long.sum(System.currentTimeMillis(), 1000);
BlockBreakEvent ev = new BlockBreakEvent(player, target, face, item, eventDrops, player.isCreative(), fastBreak);

level.getServer().getPluginManager().callEvent(ev);//TODO Для ломания инструментов иннера, нужен вызов эвента раньше setCancelled накита

boolean isNukkitPrevent = false;
if ((player.isSurvival() || player.isAdventure()) && !target.isBreakable(item)) {
ev.setCancelled();
isNukkitPrevent = true;
} else if (!player.isOp() && level.isInSpawnRadius(target)) {
ev.setCancelled();
isNukkitPrevent = true;
} else if (!ev.getInstaBreak() && ev.isFastBreak()) {
ev.setCancelled();
isNukkitPrevent = true;
}

player.lastBreak = System.currentTimeMillis();

ev.setCancelled(false);
level.getServer().getPluginManager().callEvent(ev);

if(!ev.isCancelled()) {
EventListener.eventBreakBlock(ev, false);
if(isNukkitPrevent) ev.setCancelled();
}

if (ev.isCancelled()) {
return null;
}
Expand Down

0 comments on commit 1d26c8f

Please sign in to comment.