This commit is contained in:
parent
724a36c803
commit
e59b95e2ef
4 changed files with 17 additions and 40 deletions
|
@ -63,9 +63,7 @@ public record TweaksConfig(
|
|||
boolean killswitchEnabled,
|
||||
String killswitchListen,
|
||||
|
||||
boolean swingEnabled,
|
||||
boolean swingSword,
|
||||
int swingMode
|
||||
boolean swingEnabled
|
||||
) {
|
||||
public static final int CONFIG_VERSION = 2;
|
||||
private static TweaksConfig config;
|
||||
|
@ -142,8 +140,6 @@ public record TweaksConfig(
|
|||
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(
|
||||
debug, metrics, locale,
|
||||
|
@ -161,7 +157,7 @@ public record TweaksConfig(
|
|||
redstoneEnabled, redstoneListen,
|
||||
knockbackModifiers,
|
||||
killswitchEnabled, killswitchListen,
|
||||
swingEnabled, swingSword, swingMode
|
||||
swingEnabled
|
||||
);
|
||||
|
||||
return TweaksConfig.config;
|
||||
|
|
|
@ -38,13 +38,13 @@ public class SleepListener implements Listener {
|
|||
lastDay = day;
|
||||
|
||||
if (!skippedCurrentNight.contains(event.getPlayer())) {
|
||||
event.getPlayer().setHealth(event.getPlayer().getHealth() + heal);
|
||||
|
||||
if (instant) {
|
||||
double onePlayerRatio = 1 / (event.getPlayer().getServer().getOnlinePlayers().size() * (world.getGameRuleValue(GameRule.PLAYERS_SLEEPING_PERCENTAGE) / 100.0));
|
||||
world.setTime(Math.min(world.getTime() + (long) (10917 * onePlayerRatio), 23459));
|
||||
skippedCurrentNight.add(event.getPlayer());
|
||||
}
|
||||
|
||||
event.getPlayer().setHealth(event.getPlayer().getHealth() + heal);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
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;
|
||||
|
@ -24,25 +23,15 @@ 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<>();
|
||||
private final Set<Material> tools = new HashSet<>();
|
||||
|
||||
public SwingManager(Plugin plugin) {
|
||||
this.plugin = plugin;
|
||||
|
||||
this.mode = TweaksConfig.getConfig().swingMode();
|
||||
Arrays.stream(Material.values())
|
||||
.filter(m -> m.name().contains("SWORD"))
|
||||
.forEach(tools::add);
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
|
@ -56,20 +45,10 @@ public class SwingManager implements Listener {
|
|||
if (type.isOccluding()) return;
|
||||
|
||||
var player = event.getPlayer();
|
||||
|
||||
if (useTools) {
|
||||
var tool = player.getInventory().getItemInMainHand().getType();
|
||||
if (!tools.contains(tool)) return;
|
||||
}
|
||||
|
||||
var tool = player.getInventory().getItemInMainHand().getType();
|
||||
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) {
|
||||
if (tools.contains(tool)) { // if sword, raycast to hit farther
|
||||
var result = player.getWorld().rayTraceEntities(
|
||||
player.getEyeLocation(),
|
||||
player.getEyeLocation().getDirection(),
|
||||
|
@ -79,6 +58,11 @@ public class SwingManager implements Listener {
|
|||
|
||||
if (result != null)
|
||||
entity = result.getHitEntity();
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
|
||||
if (entity != null) {
|
||||
|
|
|
@ -129,13 +129,10 @@ killswitch:
|
|||
listen: 127.0.0.1:57932
|
||||
|
||||
# Swing through grass (and alike)
|
||||
# If using sword, you can also hit behind the grass
|
||||
# If not, you can only hit the entity in the grass
|
||||
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!
|
||||
|
|
Loading…
Reference in a new issue