This repository was archived by the owner on Feb 17, 2024. It is now read-only.
forked from CivClassic/SimpleAdminHacks
-
Notifications
You must be signed in to change notification settings - Fork 12
Add BetterRails, FasterHorses, CopperRail, and miscellaneous things #77
Open
okx-code
wants to merge
8
commits into
CivMC:master
Choose a base branch
from
okx-code:transport
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3fd3020
Add BetterRails, FasterHorses, RailDeoxidise, and miscellaneous things
okx-code edc7e08
update damage
okx-code 358a2ae
ignore cancelled (better citadel interaction)
okx-code 04f28a3
add faster speeds if exposed to the sky
okx-code af9e2cf
fix default
okx-code 863cae0
rails shouldn't oxidise naturally
okx-code 13a22b6
Fix copper oxidising not as much as it should
okx-code e2f0e60
this breaks the nice geometric series
okx-code File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
...src/main/java/com/programmerdan/minecraft/simpleadminhacks/configs/BetterRailsConfig.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
paper/src/main/java/com/programmerdan/minecraft/simpleadminhacks/hacks/BetterRails.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?