Skip to content
This repository was archived by the owner on Feb 17, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.programmerdan.minecraft.simpleadminhacks.configs;

import com.google.common.collect.Maps;
import com.programmerdan.minecraft.simpleadminhacks.SimpleAdminHacks;
import com.programmerdan.minecraft.simpleadminhacks.framework.SimpleHackConfig;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import vg.civcraft.mc.civmodcore.utilities.CivLogger;

import java.util.*;

public final class BetterRailsConfig extends SimpleHackConfig {

private final CivLogger logger;

private Map<Material, Double> speeds;
private double baseSpeed = 8;

private Map<Material, Double> skySpeeds;
private double skySpeed = 0;

public BetterRailsConfig(SimpleAdminHacks plugin, ConfigurationSection base) {
super(plugin, base, false);
this.logger = CivLogger.getLogger(getClass());
wireup(base);
}

@Override
protected void wireup(ConfigurationSection config) {
this.baseSpeed = config.getDouble("base");

ConfigurationSection materials = config.getConfigurationSection("materials");
Set<String> keys = materials.getKeys(false);
this.speeds = Maps.newHashMapWithExpectedSize(keys.size());
for (String key : keys) {
this.speeds.put(Material.valueOf(key), materials.getDouble(key));
}

this.skySpeed = config.getDouble("skyBase");

ConfigurationSection skyMaterials = config.getConfigurationSection("skyMaterials");
Set<String> skyKeys = skyMaterials.getKeys(false);
this.skySpeeds = Maps.newHashMapWithExpectedSize(skyKeys.size());
for (String key : skyKeys) {
this.skySpeeds.put(Material.valueOf(key), skyMaterials.getDouble(key));
}
}

public Double getMaxSpeedMetresPerSecond(Material material) {
return speeds.get(material);
}

public Double getSkySpeedMetresPerSecond(Material material) {
return skySpeeds.get(material);
}

public double getBaseSpeed() {
return baseSpeed;
}

public double getSkySpeed() {
return skySpeed;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ public SimpleHack<?> loadHack(final Class<SimpleHack<?>> hackClass, final Config

public void enableAllHacks() {
for (final SimpleHack<?> hack : hacks) {
enableHack(hack);
if (hack.shouldEnable()) {
enableHack(hack);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
import com.programmerdan.minecraft.simpleadminhacks.SimpleAdminHacks;
import com.programmerdan.minecraft.simpleadminhacks.framework.SimpleHack;
import com.programmerdan.minecraft.simpleadminhacks.framework.SimpleHackConfig;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

import vg.civcraft.mc.civmodcore.commands.CommandManager;

public class CommandRegistrar extends CommandManager {
Expand All @@ -31,7 +32,7 @@ public void registerCommands() {
public void registerCompletions(final CommandCompletions<BukkitCommandCompletionContext> completions) {
super.registerCompletions(completions);
completions.registerAsyncCompletion("hacks", (context) -> {
final List<String> names = new ArrayList<>();
final Set<String> names = new TreeSet<>();
for (final SimpleHack<? extends SimpleHackConfig> hack : this.plugin.getHackManager().getHacks()) {
names.add(hack.getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
import com.programmerdan.minecraft.simpleadminhacks.SimpleAdminHacks;
import com.programmerdan.minecraft.simpleadminhacks.framework.SimpleHack;
import com.programmerdan.minecraft.simpleadminhacks.framework.SimpleHackConfig;
import java.util.List;

import java.util.*;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?


import net.md_5.bungee.api.ChatColor;
import org.bukkit.command.CommandSender;

Expand All @@ -34,11 +36,13 @@ public void viewHacksCommand(final CommandSender sender) {
if (hacks.isEmpty()) {
sender.sendMessage(" No hacks registered.");
}
else {
for (final SimpleHack<? extends SimpleHackConfig> hack : hacks) {
sender.sendMessage(" • " + ChatColor.YELLOW + hack.getName() + ": " + ChatColor.AQUA +
(hack.isEnabled() ? "enabled" : "disabled"));
}
final Map<String, SimpleHack<? extends SimpleHackConfig>> names = new TreeMap<>();
for (SimpleHack<? extends SimpleHackConfig> hack : hacks) {
names.put(hack.getName(), hack);
}
for (final SimpleHack<? extends SimpleHackConfig> hack : names.values()) {
sender.sendMessage(" • " + ChatColor.YELLOW + hack.getName() + ": " + ChatColor.AQUA +
(hack.isEnabled() ? "enabled" : "disabled"));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package com.programmerdan.minecraft.simpleadminhacks.hacks;


import com.programmerdan.minecraft.simpleadminhacks.SimpleAdminHacks;
import com.programmerdan.minecraft.simpleadminhacks.configs.BetterRailsConfig;
import com.programmerdan.minecraft.simpleadminhacks.framework.SimpleHack;
import org.bukkit.HeightMap;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Minecart;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.vehicle.VehicleEnterEvent;
import org.bukkit.event.vehicle.VehicleExitEvent;
import org.bukkit.event.vehicle.VehicleMoveEvent;

public final class BetterRails extends SimpleHack<BetterRailsConfig> implements Listener {

// A minecart goes at 8m/s but its internal speed is 0.4, this adjusts for that
private static final double METRES_PER_SECOND_TO_SPEED = 0.05;
private static final double VANILLA_SPEED = 0.4;

public BetterRails(SimpleAdminHacks plugin, final BetterRailsConfig config) {
super(plugin, config);
}

public static BetterRailsConfig generate(SimpleAdminHacks plugin, ConfigurationSection config) {
return new BetterRailsConfig(plugin, config);
}

@Override
public void onEnable() {
plugin().registerListener(this);
}

@Override
public void onDisable() {
HandlerList.unregisterAll(this);
}

@EventHandler
public void on(VehicleMoveEvent event) {
if (!(event.getVehicle() instanceof Minecart minecart)) {
return;
}

Location to = event.getTo();
Location from = event.getFrom();
if (to.getBlockX() == from.getBlockX() && to.getBlockY() == from.getBlockY() && to.getBlockZ() == from.getBlockZ()) {
return;
}

for (Entity entity : minecart.getPassengers()) {
if (entity instanceof Player) {
adjustSpeed(minecart);
return;
}
}
}

@EventHandler
public void on(VehicleEnterEvent event) {
if (!(event.getVehicle() instanceof Minecart minecart)) {
return;
}

if (event.getEntered() instanceof Player) {
adjustSpeed(minecart);
}
}

@EventHandler
public void on(VehicleExitEvent event) {
if (!(event.getVehicle() instanceof Minecart minecart)) {
return;
}

// Empty minecarts should return to their vanilla speed
minecart.setMaxSpeed(VANILLA_SPEED);
}


private void adjustSpeed(Minecart minecart) {
Material belowRail = minecart.getLocation().subtract(0, 1, 0).getBlock().getType();
Material belowRail2 = minecart.getLocation().subtract(0, 2, 0).getBlock().getType();

double speedMetresPerSecond = maxOrGet(config.getMaxSpeedMetresPerSecond(belowRail), config.getMaxSpeedMetresPerSecond(belowRail2), config.getBaseSpeed());

if (minecart.getLocation().getBlockY() == minecart.getWorld().getHighestBlockYAt(minecart.getLocation(), HeightMap.WORLD_SURFACE)) {
speedMetresPerSecond += maxOrGet(config.getSkySpeedMetresPerSecond(belowRail), config.getSkySpeedMetresPerSecond(belowRail2), config.getSkySpeed());
}


minecart.setMaxSpeed(speedMetresPerSecond * METRES_PER_SECOND_TO_SPEED);
}

private double maxOrGet(Double left, Double right, double defaultAmount) {
if (left != null && right != null) {
return Math.max(left, right);
} else if (left != null) {
return left;
} else if (right != null) {
return right;
} else {
return defaultAmount;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.bukkit.inventory.ItemStack;

public class HorseStats extends SimpleHack<HorseStatsConfig> implements Listener {
private static final double INTERNAL_TO_METRES_PER_SECOND = 42.15778758471;

public HorseStats(SimpleAdminHacks plugin, HorseStatsConfig config) {
super(plugin, config);
Expand All @@ -36,24 +37,31 @@ public void onHorseStatCheck(PlayerInteractEntityEvent event) {
AbstractHorse horse = (AbstractHorse)entity;
AttributeInstance attrHealth = horse.getAttribute(Attribute.GENERIC_MAX_HEALTH);
AttributeInstance attrSpeed = horse.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED);
event.getPlayer().sendMessage(String.format("%sHealth = %f, Speed = %f, Jump height = %f",
event.getPlayer().sendMessage(String.format("%sHealth = %f, Speed = %fm/s, Jump height = %f blocks",
ChatColor.YELLOW,
attrHealth.getBaseValue(),
attrSpeed.getBaseValue(),
horse.getJumpStrength()));
attrSpeed.getBaseValue() * INTERNAL_TO_METRES_PER_SECOND,
jumpHeightInBlocks(horse.getJumpStrength())));
event.setCancelled(true);
} else if (entity instanceof Strider) {
Strider strider = (Strider) entity;
AttributeInstance attrHealth = strider.getAttribute(Attribute.GENERIC_MAX_HEALTH);
AttributeInstance attrSpeed = strider.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED);
event.getPlayer().sendMessage(String.format("%sHealth = %f, Speed = %f",
event.getPlayer().sendMessage(String.format("%sHealth = %f, Speed = %fm/s",
ChatColor.YELLOW,
attrHealth.getBaseValue(),
attrSpeed.getBaseValue()));
attrSpeed.getBaseValue() * INTERNAL_TO_METRES_PER_SECOND));
event.setCancelled(true);
} else {
return;
}
}

private double jumpHeightInBlocks(double x) {
// This is a curve-fitted formula, so not 100% accurate
return -0.1817584952 * x * x * x + 3.689713992 * x * x + 2.128599134 * x - 0.343930367;
}

@Override
public void registerListeners() {
if (config.isEnabled()) {
Expand Down
Loading