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,
|
boolean killswitchEnabled,
|
||||||
String killswitchListen,
|
String killswitchListen,
|
||||||
|
|
||||||
boolean swingEnabled,
|
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;
|
||||||
|
@ -142,8 +140,6 @@ public record TweaksConfig(
|
||||||
String killswitchListen = config.getString("killswitch.listen");
|
String killswitchListen = config.getString("killswitch.listen");
|
||||||
|
|
||||||
boolean swingEnabled = config.getBoolean("swing.enabled");
|
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,
|
||||||
|
@ -161,7 +157,7 @@ public record TweaksConfig(
|
||||||
redstoneEnabled, redstoneListen,
|
redstoneEnabled, redstoneListen,
|
||||||
knockbackModifiers,
|
knockbackModifiers,
|
||||||
killswitchEnabled, killswitchListen,
|
killswitchEnabled, killswitchListen,
|
||||||
swingEnabled, swingSword, swingMode
|
swingEnabled
|
||||||
);
|
);
|
||||||
|
|
||||||
return TweaksConfig.config;
|
return TweaksConfig.config;
|
||||||
|
|
|
@ -38,13 +38,13 @@ public class SleepListener implements Listener {
|
||||||
lastDay = day;
|
lastDay = day;
|
||||||
|
|
||||||
if (!skippedCurrentNight.contains(event.getPlayer())) {
|
if (!skippedCurrentNight.contains(event.getPlayer())) {
|
||||||
event.getPlayer().setHealth(event.getPlayer().getHealth() + heal);
|
|
||||||
|
|
||||||
if (instant) {
|
if (instant) {
|
||||||
double onePlayerRatio = 1 / (event.getPlayer().getServer().getOnlinePlayers().size() * (world.getGameRuleValue(GameRule.PLAYERS_SLEEPING_PERCENTAGE) / 100.0));
|
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));
|
world.setTime(Math.min(world.getTime() + (long) (10917 * onePlayerRatio), 23459));
|
||||||
skippedCurrentNight.add(event.getPlayer());
|
skippedCurrentNight.add(event.getPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
event.getPlayer().setHealth(event.getPlayer().getHealth() + heal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
package eu.m724.tweaks.swing;
|
package eu.m724.tweaks.swing;
|
||||||
|
|
||||||
import eu.m724.tweaks.DebugLogger;
|
import eu.m724.tweaks.DebugLogger;
|
||||||
import eu.m724.tweaks.TweaksConfig;
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.attribute.Attribute;
|
import org.bukkit.attribute.Attribute;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
|
@ -24,25 +23,15 @@ import java.util.Set;
|
||||||
public class SwingManager implements Listener {
|
public class SwingManager implements Listener {
|
||||||
private final Plugin plugin;
|
private final Plugin plugin;
|
||||||
|
|
||||||
private final int mode;
|
private final Set<Material> tools = new HashSet<>();
|
||||||
private final boolean useTools;
|
|
||||||
private Set<Material> tools = new HashSet<>();
|
|
||||||
|
|
||||||
public SwingManager(Plugin plugin) {
|
public SwingManager(Plugin plugin) {
|
||||||
this.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())
|
Arrays.stream(Material.values())
|
||||||
.filter(m -> m.name().contains("SWORD"))
|
.filter(m -> m.name().contains("SWORD"))
|
||||||
.forEach(m -> tools.add(m));
|
.forEach(tools::add);
|
||||||
}
|
|
||||||
|
|
||||||
this.useTools = !tools.isEmpty();
|
|
||||||
DebugLogger.fine("Tools: " + tools.size());
|
DebugLogger.fine("Tools: " + tools.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,20 +45,10 @@ public class SwingManager implements Listener {
|
||||||
if (type.isOccluding()) return;
|
if (type.isOccluding()) return;
|
||||||
|
|
||||||
var player = event.getPlayer();
|
var player = event.getPlayer();
|
||||||
|
|
||||||
if (useTools) {
|
|
||||||
var tool = player.getInventory().getItemInMainHand().getType();
|
var tool = player.getInventory().getItemInMainHand().getType();
|
||||||
if (!tools.contains(tool)) return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Entity entity = null;
|
Entity entity = null;
|
||||||
|
|
||||||
if (mode == 0) {
|
if (tools.contains(tool)) { // if sword, raycast to hit farther
|
||||||
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(
|
var result = player.getWorld().rayTraceEntities(
|
||||||
player.getEyeLocation(),
|
player.getEyeLocation(),
|
||||||
player.getEyeLocation().getDirection(),
|
player.getEyeLocation().getDirection(),
|
||||||
|
@ -79,6 +58,11 @@ public class SwingManager implements Listener {
|
||||||
|
|
||||||
if (result != null)
|
if (result != null)
|
||||||
entity = result.getHitEntity();
|
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) {
|
if (entity != null) {
|
||||||
|
|
|
@ -129,13 +129,10 @@ killswitch:
|
||||||
listen: 127.0.0.1:57932
|
listen: 127.0.0.1:57932
|
||||||
|
|
||||||
# Swing through grass (and alike)
|
# 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:
|
swing:
|
||||||
enabled: true
|
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