Add swing module
This commit is contained in:
parent
81fa6440a0
commit
fa96487ef6
5 changed files with 118 additions and 2 deletions
|
@ -92,6 +92,9 @@ Control knockback dealt by entities
|
||||||
Quickly kills (terminates) the server on trigger, via command or HTTP request.
|
Quickly kills (terminates) the server on trigger, via command or HTTP request.
|
||||||
[KILLSWITCH.md for more info](/Minecon724/tweaks724/src/branch/master/docs/KILLSWITCH.md)
|
[KILLSWITCH.md for more info](/Minecon724/tweaks724/src/branch/master/docs/KILLSWITCH.md)
|
||||||
|
|
||||||
|
### Swing through grass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### Utility commands
|
### Utility commands
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,11 @@ public record TweaksConfig(
|
||||||
Map<String, Object> knockbackModifiers,
|
Map<String, Object> knockbackModifiers,
|
||||||
|
|
||||||
boolean killswitchEnabled,
|
boolean killswitchEnabled,
|
||||||
String killswitchListen
|
String killswitchListen,
|
||||||
|
|
||||||
|
boolean swingEnabled,
|
||||||
|
boolean swingSword,
|
||||||
|
int swingMode
|
||||||
) {
|
) {
|
||||||
public static final int CONFIG_VERSION = 2;
|
public static final int CONFIG_VERSION = 2;
|
||||||
private static TweaksConfig config;
|
private static TweaksConfig config;
|
||||||
|
@ -135,6 +139,10 @@ public record TweaksConfig(
|
||||||
boolean killswitchEnabled = config.getBoolean("killswitch.enabled");
|
boolean killswitchEnabled = config.getBoolean("killswitch.enabled");
|
||||||
String killswitchListen = config.getString("killswitch.listen");
|
String killswitchListen = config.getString("killswitch.listen");
|
||||||
|
|
||||||
|
boolean swingEnabled = config.getBoolean("swing.enabled");
|
||||||
|
boolean swingSword = config.getBoolean("swing.sword");
|
||||||
|
int swingMode = config.getInt("swing.mode");
|
||||||
|
|
||||||
TweaksConfig.config = new TweaksConfig(
|
TweaksConfig.config = new TweaksConfig(
|
||||||
debug, metrics, locale,
|
debug, metrics, locale,
|
||||||
worldborderExpand, worldborderHide,
|
worldborderExpand, worldborderHide,
|
||||||
|
@ -150,7 +158,8 @@ public record TweaksConfig(
|
||||||
authEnabled, authForce, authHostname,
|
authEnabled, authForce, authHostname,
|
||||||
redstoneEnabled, redstoneListen,
|
redstoneEnabled, redstoneListen,
|
||||||
knockbackModifiers,
|
knockbackModifiers,
|
||||||
killswitchEnabled, killswitchListen
|
killswitchEnabled, killswitchListen,
|
||||||
|
swingEnabled, swingSword, swingMode
|
||||||
);
|
);
|
||||||
|
|
||||||
return TweaksConfig.config;
|
return TweaksConfig.config;
|
||||||
|
|
|
@ -22,6 +22,7 @@ import eu.m724.tweaks.ping.PingChecker;
|
||||||
import eu.m724.tweaks.pomodoro.PomodoroManager;
|
import eu.m724.tweaks.pomodoro.PomodoroManager;
|
||||||
import eu.m724.tweaks.redstone.RedstoneManager;
|
import eu.m724.tweaks.redstone.RedstoneManager;
|
||||||
import eu.m724.tweaks.sleep.SleepManager;
|
import eu.m724.tweaks.sleep.SleepManager;
|
||||||
|
import eu.m724.tweaks.swing.SwingManager;
|
||||||
import eu.m724.tweaks.updater.UpdaterManager;
|
import eu.m724.tweaks.updater.UpdaterManager;
|
||||||
import eu.m724.tweaks.worldborder.WorldBorderExpander;
|
import eu.m724.tweaks.worldborder.WorldBorderExpander;
|
||||||
import eu.m724.tweaks.worldborder.WorldBorderHider;
|
import eu.m724.tweaks.worldborder.WorldBorderHider;
|
||||||
|
@ -135,6 +136,11 @@ public class TweaksPlugin extends MStatsPlugin {
|
||||||
new KillswitchManager(this).init(getCommand("servkill"));
|
new KillswitchManager(this).init(getCommand("servkill"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (config.swingEnabled()) {
|
||||||
|
DebugLogger.fine("Enabling Swing");
|
||||||
|
new SwingManager(this).init();
|
||||||
|
}
|
||||||
|
|
||||||
/* end modules */
|
/* end modules */
|
||||||
|
|
||||||
if (config.metrics()) {
|
if (config.metrics()) {
|
||||||
|
|
89
src/main/java/eu/m724/tweaks/swing/SwingManager.java
Normal file
89
src/main/java/eu/m724/tweaks/swing/SwingManager.java
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2025 Minecon724
|
||||||
|
* Tweaks724 is licensed under the GNU General Public License. See the LICENSE.md file
|
||||||
|
* in the project root for the full license text.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package eu.m724.tweaks.swing;
|
||||||
|
|
||||||
|
import eu.m724.tweaks.DebugLogger;
|
||||||
|
import eu.m724.tweaks.TweaksConfig;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.attribute.Attribute;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.LivingEntity;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class SwingManager implements Listener {
|
||||||
|
private final Plugin plugin;
|
||||||
|
|
||||||
|
private final int mode;
|
||||||
|
private final boolean useTools;
|
||||||
|
private Set<Material> tools = new HashSet<>();
|
||||||
|
|
||||||
|
public SwingManager(Plugin plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
|
||||||
|
this.mode = TweaksConfig.getConfig().swingMode();
|
||||||
|
|
||||||
|
if (mode != 0 && mode != 1)
|
||||||
|
throw new IllegalArgumentException("Mode " + mode + " is invalid. It must be 0 or 1.");
|
||||||
|
|
||||||
|
if (TweaksConfig.getConfig().swingSword()) {
|
||||||
|
Arrays.stream(Material.values())
|
||||||
|
.filter(m -> m.name().contains("SWORD"))
|
||||||
|
.forEach(m -> tools.add(m));
|
||||||
|
}
|
||||||
|
|
||||||
|
this.useTools = !tools.isEmpty();
|
||||||
|
DebugLogger.fine("Tools: " + tools.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void init() {
|
||||||
|
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onBreak(BlockBreakEvent event) {
|
||||||
|
var type = event.getBlock().getType();
|
||||||
|
if (type.isOccluding()) return;
|
||||||
|
|
||||||
|
var player = event.getPlayer();
|
||||||
|
|
||||||
|
if (useTools) {
|
||||||
|
var tool = player.getInventory().getItemInMainHand().getType();
|
||||||
|
if (!tools.contains(tool)) return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Entity entity = null;
|
||||||
|
|
||||||
|
if (mode == 0) {
|
||||||
|
entity = event.getBlock().getWorld()
|
||||||
|
.getNearbyEntities(event.getBlock().getLocation().add(0.5, 0.5, 0.5), 0.5, 0.5, 0.5)
|
||||||
|
.stream().filter(e -> (e instanceof LivingEntity && e != player))
|
||||||
|
.findFirst().orElse(null);
|
||||||
|
} else if (mode == 1) {
|
||||||
|
var result = player.getWorld().rayTraceEntities(
|
||||||
|
player.getEyeLocation(),
|
||||||
|
player.getEyeLocation().getDirection(),
|
||||||
|
player.getAttribute(Attribute.ENTITY_INTERACTION_RANGE).getValue(),
|
||||||
|
e -> e != player
|
||||||
|
);
|
||||||
|
|
||||||
|
if (result != null)
|
||||||
|
entity = result.getHitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entity != null) {
|
||||||
|
player.attack(entity);
|
||||||
|
DebugLogger.fine("Swing " + player.getName() + " hit " + entity.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -126,6 +126,15 @@ killswitch:
|
||||||
# To disable HTTP server, set to null
|
# To disable HTTP server, set to null
|
||||||
listen: 127.0.0.1:57932
|
listen: 127.0.0.1:57932
|
||||||
|
|
||||||
|
# Swing through grass (and alike)
|
||||||
|
swing:
|
||||||
|
enabled: true
|
||||||
|
# Only sword
|
||||||
|
sword: false
|
||||||
|
# 0 - entity inside broken block / can't attack entity behind the block
|
||||||
|
# 1 - raycasted from player / can attack entity behind the block (within normal reach)
|
||||||
|
mode: 0
|
||||||
|
|
||||||
|
|
||||||
# Finally, thank you for downloading Tweaks724, I hope you enjoy!
|
# Finally, thank you for downloading Tweaks724, I hope you enjoy!
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue