Skip to content

Commit

Permalink
add multitask module
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Aug 9, 2024
1 parent 621ae98 commit ba25088
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package me.xginko.aef.modules.combat;

import com.cryptomorin.xseries.XEntityType;
import io.papermc.paper.event.player.PrePlayerAttackEntityEvent;
import me.xginko.aef.modules.AEFModule;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;

public class MultiTask extends AEFModule implements Listener {

public MultiTask() {
super("combat.multi-task-patch");
}

@Override
public void enable() {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}

@Override
public boolean shouldEnable() {
return config.getBoolean(configPath + ".enable", false);
}

@Override
public void disable() {
HandlerList.unregisterAll(this);
}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onPrePlayerAttackEntity(PrePlayerAttackEntityEvent event) {
if (event.getPlayer().hasActiveItem()) {
event.setCancelled(true);
}
}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
if (event.getDamager().getType() == XEntityType.PLAYER.get()) {
if (((LivingEntity) event.getDamager()).hasActiveItem()) {
event.setCancelled(true);
}
}
}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onPlayerInteract(PlayerInteractEvent event) {
if (event.getPlayer().hasActiveItem()) {
event.setCancelled(true);
}
}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onBlockPlace(BlockPlaceEvent event) {
if (event.getPlayer().hasActiveItem()) {
event.setCancelled(true);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package me.xginko.aef.modules.combat;

import com.cryptomorin.xseries.XEntityType;
import me.xginko.aef.modules.AEFModule;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;

public class MultiTask extends AEFModule implements Listener {

public MultiTask() {
super("combat.multi-task-patch");
}

@Override
public void enable() {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}

@Override
public boolean shouldEnable() {
return config.getBoolean(configPath + ".enable", false);
}

@Override
public void disable() {
HandlerList.unregisterAll(this);
}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
if (event.getDamager().getType() == XEntityType.PLAYER.get()) {
if (((LivingEntity) event.getDamager()).getActiveItem() != null) {
event.setCancelled(true);
}
}
}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onPlayerInteract(PlayerInteractEvent event) {
if (event.getPlayer().getActiveItem() != null) {
event.setCancelled(true);
}
}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onBlockPlace(BlockPlaceEvent event) {
if (event.getPlayer().getActiveItem() != null) {
event.setCancelled(true);
}
}
}

0 comments on commit ba25088

Please sign in to comment.