Compare commits
6 commits
81fa6440a0
...
e59b95e2ef
Author | SHA1 | Date | |
---|---|---|---|
e59b95e2ef | |||
724a36c803 | |||
6e45491508 | |||
afed2a8f78 | |||
4bf6ec5ae7 | |||
fa96487ef6 |
8 changed files with 126 additions and 22 deletions
|
@ -66,6 +66,8 @@ Sleeping doesn't skip night, but speeds it up. The more players, the faster it g
|
|||
One can instantly skip, but only a part of the night. \
|
||||
There's 5 players on the server. A night is 10 minutes long. \
|
||||
Each player can instantly skip 2 minutes of the night at any time, even if others aren't sleeping
|
||||
- Heal \
|
||||
Sleeping heals
|
||||
|
||||
### Authentication
|
||||
Players are given a unique subdomain like "\<key>.example.com" and they must use it to join \
|
||||
|
@ -92,6 +94,9 @@ Control knockback dealt by entities
|
|||
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)
|
||||
|
||||
### Swing through grass
|
||||
|
||||
|
||||
|
||||
### Utility commands
|
||||
|
||||
|
|
2
pom.xml
2
pom.xml
|
@ -167,7 +167,7 @@
|
|||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>${project.spigot.version}</version>
|
||||
<version>1.21.1-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
|
|
@ -49,6 +49,7 @@ public record TweaksConfig(
|
|||
|
||||
boolean sleepEnabled,
|
||||
boolean sleepInstant,
|
||||
double sleepHeal,
|
||||
|
||||
boolean authEnabled,
|
||||
boolean authForce,
|
||||
|
@ -60,7 +61,9 @@ public record TweaksConfig(
|
|||
Map<String, Object> knockbackModifiers,
|
||||
|
||||
boolean killswitchEnabled,
|
||||
String killswitchListen
|
||||
String killswitchListen,
|
||||
|
||||
boolean swingEnabled
|
||||
) {
|
||||
public static final int CONFIG_VERSION = 2;
|
||||
private static TweaksConfig config;
|
||||
|
@ -121,6 +124,7 @@ public record TweaksConfig(
|
|||
|
||||
boolean sleepEnabled = config.getBoolean("sleep.enabled");
|
||||
boolean sleepInstant = config.getBoolean("sleep.instant");
|
||||
double sleepHeal = config.getDouble("sleep.heal");
|
||||
|
||||
boolean authEnabled = config.getBoolean("auth.enabled");
|
||||
boolean authForce = config.getBoolean("auth.force");
|
||||
|
@ -135,6 +139,8 @@ public record TweaksConfig(
|
|||
boolean killswitchEnabled = config.getBoolean("killswitch.enabled");
|
||||
String killswitchListen = config.getString("killswitch.listen");
|
||||
|
||||
boolean swingEnabled = config.getBoolean("swing.enabled");
|
||||
|
||||
TweaksConfig.config = new TweaksConfig(
|
||||
debug, metrics, locale,
|
||||
worldborderExpand, worldborderHide,
|
||||
|
@ -146,11 +152,12 @@ public record TweaksConfig(
|
|||
pomodoroEnabled, pomodoroForce,
|
||||
updaterEnabled,
|
||||
hardcoreEnabled, hardcoreChance,
|
||||
sleepEnabled, sleepInstant,
|
||||
sleepEnabled, sleepInstant, sleepHeal,
|
||||
authEnabled, authForce, authHostname,
|
||||
redstoneEnabled, redstoneListen,
|
||||
knockbackModifiers,
|
||||
killswitchEnabled, killswitchListen
|
||||
killswitchEnabled, killswitchListen,
|
||||
swingEnabled
|
||||
);
|
||||
|
||||
return TweaksConfig.config;
|
||||
|
|
|
@ -22,6 +22,7 @@ import eu.m724.tweaks.ping.PingChecker;
|
|||
import eu.m724.tweaks.pomodoro.PomodoroManager;
|
||||
import eu.m724.tweaks.redstone.RedstoneManager;
|
||||
import eu.m724.tweaks.sleep.SleepManager;
|
||||
import eu.m724.tweaks.swing.SwingManager;
|
||||
import eu.m724.tweaks.updater.UpdaterManager;
|
||||
import eu.m724.tweaks.worldborder.WorldBorderExpander;
|
||||
import eu.m724.tweaks.worldborder.WorldBorderHider;
|
||||
|
@ -135,6 +136,11 @@ public class TweaksPlugin extends MStatsPlugin {
|
|||
new KillswitchManager(this).init(getCommand("servkill"));
|
||||
}
|
||||
|
||||
if (config.swingEnabled()) {
|
||||
DebugLogger.fine("Enabling Swing");
|
||||
new SwingManager(this).init();
|
||||
}
|
||||
|
||||
/* end modules */
|
||||
|
||||
if (config.metrics()) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2024 Minecon724
|
||||
* 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.
|
||||
*/
|
||||
|
@ -13,12 +13,13 @@ import org.bukkit.event.EventHandler;
|
|||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityKnockbackByEntityEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class KnockbackListener implements Listener {
|
||||
private final Map<EntityType, Double> modifiers = new HashMap<>();
|
||||
private final Map<EntityType, Vector> modifiers = new HashMap<>();
|
||||
|
||||
public KnockbackListener(Plugin plugin) {
|
||||
TweaksConfig.getConfig().knockbackModifiers().forEach((k, v) -> {
|
||||
|
@ -45,7 +46,7 @@ public class KnockbackListener implements Listener {
|
|||
}
|
||||
|
||||
if (mod == 1) return;
|
||||
modifiers.put(type, mod);
|
||||
modifiers.put(type, new Vector(mod, mod >= 1 ? mod : 1, mod)); // don't touch vertical
|
||||
});
|
||||
|
||||
if (!modifiers.isEmpty())
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2024 Minecon724
|
||||
* 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.
|
||||
*/
|
||||
|
@ -21,6 +21,7 @@ import java.util.Set;
|
|||
|
||||
public class SleepListener implements Listener {
|
||||
private final boolean instant = TweaksConfig.getConfig().sleepInstant();
|
||||
private final double heal = TweaksConfig.getConfig().sleepHeal() * 2; // hearts to half hearts
|
||||
|
||||
private final Set<Player> skippedCurrentNight = new HashSet<>();
|
||||
private long lastDay = 0;
|
||||
|
@ -30,7 +31,6 @@ public class SleepListener implements Listener {
|
|||
if (event.getBedEnterResult() == PlayerBedEnterEvent.BedEnterResult.OK) {
|
||||
SleepState.playersSleeping++;
|
||||
|
||||
if (instant) {
|
||||
World world = event.getPlayer().getWorld();
|
||||
|
||||
long day = world.getFullTime() / 24000;
|
||||
|
@ -38,10 +38,13 @@ public class SleepListener implements Listener {
|
|||
lastDay = day;
|
||||
|
||||
if (!skippedCurrentNight.contains(event.getPlayer())) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -53,8 +56,9 @@ public class SleepListener implements Listener {
|
|||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerBedLeave(TimeSkipEvent event) {
|
||||
if (event.getSkipReason() == TimeSkipEvent.SkipReason.NIGHT_SKIP)
|
||||
public void onTimeSkip(TimeSkipEvent event) {
|
||||
if (event.getSkipReason() == TimeSkipEvent.SkipReason.NIGHT_SKIP) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
73
src/main/java/eu/m724/tweaks/swing/SwingManager.java
Normal file
73
src/main/java/eu/m724/tweaks/swing/SwingManager.java
Normal file
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* 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 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 Set<Material> tools = new HashSet<>();
|
||||
|
||||
public SwingManager(Plugin plugin) {
|
||||
this.plugin = plugin;
|
||||
|
||||
Arrays.stream(Material.values())
|
||||
.filter(m -> m.name().contains("SWORD"))
|
||||
.forEach(tools::add);
|
||||
|
||||
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();
|
||||
var tool = player.getInventory().getItemInMainHand().getType();
|
||||
Entity entity = null;
|
||||
|
||||
if (tools.contains(tool)) { // if sword, raycast to hit farther
|
||||
var result = player.getWorld().rayTraceEntities(
|
||||
player.getEyeLocation(),
|
||||
player.getEyeLocation().getDirection(),
|
||||
player.getAttribute(Attribute.PLAYER_ENTITY_INTERACTION_RANGE).getValue(),
|
||||
e -> e != player
|
||||
);
|
||||
|
||||
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) {
|
||||
player.attack(entity);
|
||||
DebugLogger.fine("Swing " + player.getName() + " hit " + entity.getName());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -83,6 +83,9 @@ hardcore:
|
|||
|
||||
# Makes sleeping
|
||||
# And adds a nice animation
|
||||
# Percentage: playersSleepingPercentage gamerule
|
||||
# If instant: how much % of players to skip the night
|
||||
# If not: how much % make skipping full speed
|
||||
sleep:
|
||||
enabled: true
|
||||
# This gives every player a "share" of the night
|
||||
|
@ -90,9 +93,8 @@ sleep:
|
|||
# For example, if 5 players online and night is 5 minutes, one can go to sleep and skip 1 minute of the night
|
||||
# Leaving the bed and reentering it does nothing
|
||||
instant: false
|
||||
# Percentage: playersSleepingPercentage gamerule
|
||||
# If instant: how much % of players to skip the night
|
||||
# If not: how much % make skipping full speed
|
||||
# How many hearts to heal after sleeping
|
||||
heal: 2.0
|
||||
|
||||
# "Hostname" authentication
|
||||
# This makes a player need to join a unique hostname like "asd123.example.com" where "asd123" is the key
|
||||
|
@ -126,6 +128,12 @@ killswitch:
|
|||
# To disable HTTP server, set to null
|
||||
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
|
||||
|
||||
|
||||
# Finally, thank you for downloading Tweaks724, I hope you enjoy!
|
||||
|
||||
|
|
Loading…
Reference in a new issue