Compare commits
No commits in common. "81fa6440a0bde25812ea55a971875e1371dbf70c" and "32bacc96e87e0aa7d0e6af900605af1fb4cff860" have entirely different histories.
81fa6440a0
...
32bacc96e8
7 changed files with 19 additions and 53 deletions
|
@ -83,16 +83,11 @@ Issue messages that the player needs to read to keep playing, and that make an a
|
||||||
|
|
||||||
### Remote redstone
|
### Remote redstone
|
||||||
Adds a "gateway" item that are controlled over internet. \
|
Adds a "gateway" item that are controlled over internet. \
|
||||||
[RETSTONE.md for more info](/Minecon724/tweaks724/src/branch/master/docs/RETSTONE.md)
|
[RETSTONE.md for more info](/Minecon724/tweaks724/src/branch/master/RETSTONE.md)
|
||||||
|
|
||||||
### Knockback
|
### Knockback
|
||||||
Control knockback dealt by entities
|
Control knockback dealt by entities
|
||||||
|
|
||||||
### Kill switch
|
|
||||||
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)
|
|
||||||
|
|
||||||
|
|
||||||
### Utility commands
|
### Utility commands
|
||||||
|
|
||||||
- `/ping` - displays player ping \
|
- `/ping` - displays player ping \
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
Here's the documentation.
|
|
||||||
|
|
||||||
Click above on a file to read more about a topic.
|
|
2
pom.xml
2
pom.xml
|
@ -1,6 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!--
|
<!--
|
||||||
~ Copyright (C) 2025 Minecon724
|
~ Copyright (C) 2024 Minecon724
|
||||||
~ Tweaks724 is licensed under the GNU General Public License. See the LICENSE.md file
|
~ Tweaks724 is licensed under the GNU General Public License. See the LICENSE.md file
|
||||||
~ in the project root for the full license text.
|
~ in the project root for the full license text.
|
||||||
-->
|
-->
|
||||||
|
|
|
@ -45,7 +45,7 @@ public record TweaksConfig(
|
||||||
boolean updaterEnabled,
|
boolean updaterEnabled,
|
||||||
|
|
||||||
boolean hardcoreEnabled,
|
boolean hardcoreEnabled,
|
||||||
double hardcoreChance,
|
float hardcoreChance,
|
||||||
|
|
||||||
boolean sleepEnabled,
|
boolean sleepEnabled,
|
||||||
boolean sleepInstant,
|
boolean sleepInstant,
|
||||||
|
@ -117,7 +117,7 @@ public record TweaksConfig(
|
||||||
boolean updaterEnabled = config.getBoolean("updater.enabled");
|
boolean updaterEnabled = config.getBoolean("updater.enabled");
|
||||||
|
|
||||||
boolean hardcoreEnabled = config.getBoolean("hardcore.enabled");
|
boolean hardcoreEnabled = config.getBoolean("hardcore.enabled");
|
||||||
double hardcoreChance = config.getDouble("hardcore.chance");
|
float hardcoreChance = (float) config.getDouble("hardcore.chance");
|
||||||
|
|
||||||
boolean sleepEnabled = config.getBoolean("sleep.enabled");
|
boolean sleepEnabled = config.getBoolean("sleep.enabled");
|
||||||
boolean sleepInstant = config.getBoolean("sleep.instant");
|
boolean sleepInstant = config.getBoolean("sleep.instant");
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2025 Minecon724
|
* Copyright (C) 2024 Minecon724
|
||||||
* Tweaks724 is licensed under the GNU General Public License. See the LICENSE.md file
|
* Tweaks724 is licensed under the GNU General Public License. See the LICENSE.md file
|
||||||
* in the project root for the full license text.
|
* in the project root for the full license text.
|
||||||
*/
|
*/
|
||||||
|
@ -8,40 +8,14 @@ package eu.m724.tweaks.hardcore;
|
||||||
|
|
||||||
import com.comphenix.protocol.PacketType;
|
import com.comphenix.protocol.PacketType;
|
||||||
import com.comphenix.protocol.ProtocolLibrary;
|
import com.comphenix.protocol.ProtocolLibrary;
|
||||||
import com.comphenix.protocol.events.ListenerPriority;
|
import com.comphenix.protocol.events.*;
|
||||||
import com.comphenix.protocol.events.PacketAdapter;
|
|
||||||
import com.comphenix.protocol.events.PacketContainer;
|
|
||||||
import com.comphenix.protocol.events.PacketEvent;
|
|
||||||
import eu.m724.tweaks.DebugLogger;
|
|
||||||
import eu.m724.tweaks.TweaksConfig;
|
import eu.m724.tweaks.TweaksConfig;
|
||||||
import net.minecraft.world.level.levelgen.RandomSupport;
|
|
||||||
import net.minecraft.world.level.levelgen.Xoroshiro128PlusPlus;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.math.BigInteger;
|
|
||||||
|
|
||||||
// how we do it is much faster than any Random
|
|
||||||
public class HardcoreManager {
|
public class HardcoreManager {
|
||||||
private final double chance = TweaksConfig.getConfig().hardcoreChance();
|
private final float chance = TweaksConfig.getConfig().hardcoreChance();
|
||||||
|
|
||||||
private final long chanceLong = BigInteger.valueOf(Long.MIN_VALUE)
|
|
||||||
.add(
|
|
||||||
new BigDecimal(
|
|
||||||
BigInteger.valueOf(Long.MAX_VALUE).subtract(BigInteger.valueOf(Long.MIN_VALUE))
|
|
||||||
).multiply(
|
|
||||||
BigDecimal.valueOf(chance)
|
|
||||||
).toBigInteger()
|
|
||||||
).longValue();
|
|
||||||
|
|
||||||
private final Xoroshiro128PlusPlus rng = new Xoroshiro128PlusPlus(
|
|
||||||
RandomSupport.generateUniqueSeed(),
|
|
||||||
RandomSupport.generateUniqueSeed()
|
|
||||||
);
|
|
||||||
|
|
||||||
public void init(Plugin plugin) {
|
public void init(Plugin plugin) {
|
||||||
DebugLogger.fine("Chance long: " + chanceLong);
|
|
||||||
|
|
||||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(
|
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(
|
||||||
plugin,
|
plugin,
|
||||||
ListenerPriority.NORMAL,
|
ListenerPriority.NORMAL,
|
||||||
|
@ -50,8 +24,9 @@ public class HardcoreManager {
|
||||||
@Override
|
@Override
|
||||||
public void onPacketSending(PacketEvent event) {
|
public void onPacketSending(PacketEvent event) {
|
||||||
PacketContainer packet = event.getPacket();
|
PacketContainer packet = event.getPacket();
|
||||||
|
int entityId = packet.getIntegers().read(0);
|
||||||
|
|
||||||
if (rng.nextLong() < chanceLong)
|
if (chance > ((48271 * entityId) % 65537) / 65537f) // gotta be fast
|
||||||
// the "is hardcore" boolean https://wiki.vg/Protocol#Login_.28play.29
|
// the "is hardcore" boolean https://wiki.vg/Protocol#Login_.28play.29
|
||||||
packet.getBooleans().write(0, true);
|
packet.getBooleans().write(0, true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2025 Minecon724
|
* Copyright (C) 2024 Minecon724
|
||||||
* Tweaks724 is licensed under the GNU General Public License. See the LICENSE.md file
|
* Tweaks724 is licensed under the GNU General Public License. See the LICENSE.md file
|
||||||
* in the project root for the full license text.
|
* in the project root for the full license text.
|
||||||
*/
|
*/
|
||||||
|
@ -19,28 +19,26 @@ import java.util.HashSet;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.CompletionException;
|
import java.util.concurrent.CompletionException;
|
||||||
import java.util.logging.Logger;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class UpdateChecker extends BukkitRunnable {
|
public class UpdateChecker extends BukkitRunnable {
|
||||||
private final Logger logger;
|
|
||||||
private final Set<VersionedResource> resources;
|
private final Set<VersionedResource> resources;
|
||||||
|
|
||||||
static final Set<VersionedResource> availableUpdates = new HashSet<>();
|
static final Set<VersionedResource> availableUpdates = new HashSet<>();
|
||||||
static LocalTime lastChecked = null;
|
static LocalTime lastChecked = null;
|
||||||
|
|
||||||
UpdateChecker(Logger logger, Set<VersionedResource> resources) {
|
UpdateChecker(Set<VersionedResource> resources) {
|
||||||
this.logger = logger;
|
|
||||||
this.resources = resources; // TODO make a copy?
|
this.resources = resources; // TODO make a copy?
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkAll() {
|
private void checkAll() {
|
||||||
DebugLogger.fine("Checking for updates");
|
//logger.info("Checking for updates");
|
||||||
lastChecked = LocalTime.now(ZoneOffset.UTC);
|
lastChecked = LocalTime.now(ZoneOffset.UTC);
|
||||||
availableUpdates.clear();
|
availableUpdates.clear();
|
||||||
|
|
||||||
for (VersionedResource versionedResource : Set.copyOf(resources)) {
|
for (VersionedResource versionedResource : Set.copyOf(resources)) {
|
||||||
String pluginName = versionedResource.resource().plugin().getName();
|
String pluginName = versionedResource.resource().plugin().getName();
|
||||||
|
//logger.info(versionedResource.resource().resourceId() + " " + versionedResource.resource().plugin().getName());
|
||||||
int page = versionedResource.running() != null ? versionedResource.running().page() : 1;
|
int page = versionedResource.running() != null ? versionedResource.running().page() : 1;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -48,13 +46,14 @@ public class UpdateChecker extends BukkitRunnable {
|
||||||
if (!versionedResource.equals(newResource)) {
|
if (!versionedResource.equals(newResource)) {
|
||||||
resources.remove(versionedResource);
|
resources.remove(versionedResource);
|
||||||
if (newResource.running() == null) {
|
if (newResource.running() == null) {
|
||||||
logger.warning("Unable to find installed version of %s".formatted(pluginName));
|
DebugLogger.info("Unable to find installed version of %s".formatted(pluginName));
|
||||||
if (versionedResource.running() != null) {
|
if (versionedResource.running() != null) {
|
||||||
logger.warning("Did you downgrade %s? If so, clear cache".formatted(pluginName));
|
DebugLogger.info("Did you downgrade %s? If so, clear cache".formatted(pluginName));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!newResource.running().equals(newResource.latest())) {
|
if (!newResource.running().equals(newResource.latest())) {
|
||||||
availableUpdates.add(newResource);
|
availableUpdates.add(newResource);
|
||||||
|
//logger.info("Update available for %s. %d -> %d".formatted(pluginName, newResource.running().updateId(), newResource.latest().updateId()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resources.add(newResource);
|
resources.add(newResource);
|
||||||
|
@ -68,11 +67,11 @@ public class UpdateChecker extends BukkitRunnable {
|
||||||
private void alert() {
|
private void alert() {
|
||||||
int n = availableUpdates.size();
|
int n = availableUpdates.size();
|
||||||
if (n == 0) return;
|
if (n == 0) return;
|
||||||
logger.info(Language.getString("updateAvailableNotice", n));
|
DebugLogger.info(Language.getString("updateAvailableNotice", n));
|
||||||
|
|
||||||
availableUpdates.stream()
|
availableUpdates.stream()
|
||||||
.map(u -> "- %s (%s -> %s)".formatted(u.resource().name(), u.running().label(), u.latest().label()))
|
.map(u -> "- %s (%s -> %s)".formatted(u.resource().name(), u.running().label(), u.latest().label()))
|
||||||
.forEach(logger::info);
|
.forEach(DebugLogger::info);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -60,7 +60,7 @@ public class UpdaterManager {
|
||||||
)).collect(Collectors.toSet());
|
)).collect(Collectors.toSet());
|
||||||
|
|
||||||
|
|
||||||
new UpdateChecker(plugin.getLogger(), versionedResources)
|
new UpdateChecker(versionedResources)
|
||||||
.runTaskTimerAsynchronously(plugin, 600, 12 * 3600 * 20);
|
.runTaskTimerAsynchronously(plugin, 600, 12 * 3600 * 20);
|
||||||
|
|
||||||
updatesCommand.setExecutor(new UpdaterCommands());
|
updatesCommand.setExecutor(new UpdaterCommands());
|
||||||
|
|
Loading…
Reference in a new issue