Merge pull request #30 from Protonull/civ14

ShipOutOfLuck :: add hack to disable certain boat use cases
This commit is contained in:
Maxopoly authored and GitHub committed 2020-08-11 15:32:53 +02:00
commit 4c7fa938d0
6 files changed
+284 -72

No files matched your search

@@ -0,0 +1,80 @@
package com.programmerdan.minecraft.simpleadminhacks.configs;
import com.programmerdan.minecraft.simpleadminhacks.SimpleAdminHacks;
import com.programmerdan.minecraft.simpleadminhacks.SimpleHackConfig;
import org.bukkit.configuration.ConfigurationSection;
public class PhantomMenaceConfig extends SimpleHackConfig {
private int timeSinceRestCap;
private boolean nightSpawn;
private boolean stormSpawn;
private boolean persistentChance;
public PhantomMenaceConfig(SimpleAdminHacks plugin, ConfigurationSection base) {
super(plugin, base);
}
@Override
protected void wireup(ConfigurationSection config) {
// Parse the cap for TIME_SINCE_REST
this.timeSinceRestCap = config.getInt("timeSinceRestCap", 80_000);
if (this.timeSinceRestCap == -1) {
plugin().info("[PhantomMenace] TIME_SINCE_REST will not be capped.");
}
else if (this.timeSinceRestCap < -1) {
plugin().warning("[PhantomMenace] TIME_SINCE_REST invalid value, defaulting.");
this.timeSinceRestCap = 80_000;
}
else if (this.timeSinceRestCap < 72_000) {
plugin().warning("[PhantomMenace] TIME_SINCE_REST capped below spawning value.");
}
else {
plugin().info("[PhantomMenace] TIME_SINCE_REST capped to: " + this.timeSinceRestCap);
}
// Parse phantom spawning at night
this.nightSpawn = config.getBoolean("nightSpawn", true);
if (this.nightSpawn) {
plugin().info("[PhantomMenace] Phantoms are now allowed to spawn during the night.");
}
else {
plugin().info("[PhantomMenace] Phantoms are no longer allowed to spawn during the night.");
}
// Parse phantom spawning during storms
this.stormSpawn = config.getBoolean("stormSpawn", true);
if (this.stormSpawn) {
plugin().info("[PhantomMenace] Phantoms are now allowed to spawn during storms.");
}
else {
plugin().info("[PhantomMenace] Phantoms are no longer allowed to spawn during storms.");
}
// Parse phantom spawning during storms
this.persistentChance = config.getBoolean("persistentChance", false);
if (this.persistentChance) {
plugin().info("[PhantomMenace] TIME_SINCE_REST is persistent.");
}
else {
plugin().info("[PhantomMenace] TIME_SINCE_REST is not persistent.");
}
}
public int getTimeSinceRestCap() {
return this.timeSinceRestCap;
}
public boolean canNightSpawn() {
return this.nightSpawn;
}
public boolean canStormSpawn() {
return this.stormSpawn;
}
public boolean isChangePersistent() {
return this.persistentChance;
}
}
@@ -1,66 +0,0 @@
package com.programmerdan.minecraft.simpleadminhacks.configs;
import com.programmerdan.minecraft.simpleadminhacks.SimpleAdminHacks;
import com.programmerdan.minecraft.simpleadminhacks.SimpleHackConfig;
import org.bukkit.configuration.ConfigurationSection;
public class PhantomOfTheOperaConfig extends SimpleHackConfig {
private int timeSinceRestCap;
private boolean nightSpawn;
private boolean stormSpawn;
public PhantomOfTheOperaConfig(SimpleAdminHacks plugin, ConfigurationSection base) {
super(plugin, base);
}
@Override
protected void wireup(ConfigurationSection config) {
// Parse the cap for TIME_SINCE_REST
this.timeSinceRestCap = config.getInt("timeSinceRestCap", 80_000);
if (this.timeSinceRestCap == -1) {
plugin().info("[PhantomOfTheOpera] TIME_SINCE_REST will not be capped.");
}
else if (this.timeSinceRestCap < -1) {
plugin().warning("[PhantomOfTheOpera] TIME_SINCE_REST invalid value, defaulting.");
this.timeSinceRestCap = 80_000;
}
else if (this.timeSinceRestCap < 72_000) {
plugin().warning("[PhantomOfTheOpera] TIME_SINCE_REST capped below spawning value.");
}
else {
plugin().info("[PhantomOfTheOpera] TIME_SINCE_REST capped to: " + this.timeSinceRestCap);
}
// Parse phantom spawning at night
this.nightSpawn = config.getBoolean("nightSpawn", true);
if (this.nightSpawn) {
plugin().info("[PhantomOfTheOpera] Phantoms are now allowed to spawn during the night.");
}
else {
plugin().info("[PhantomOfTheOpera] Phantoms are no longer allowed to spawn during the night.");
}
// Parse phantom spawning during storms
this.stormSpawn = config.getBoolean("stormSpawn", true);
if (this.stormSpawn) {
plugin().info("[PhantomOfTheOpera] Phantoms are now allowed to spawn during storms.");
}
else {
plugin().info("[PhantomOfTheOpera] Phantoms are no longer allowed to spawn during storms.");
}
}
public int getTimeSinceRestCap() {
return timeSinceRestCap;
}
public boolean canNightSpawn() {
return nightSpawn;
}
public boolean canStormSpawn() {
return stormSpawn;
}
}
@@ -0,0 +1,53 @@
package com.programmerdan.minecraft.simpleadminhacks.configs;
import com.google.common.base.Strings;
import com.programmerdan.minecraft.simpleadminhacks.SimpleAdminHacks;
import com.programmerdan.minecraft.simpleadminhacks.SimpleHackConfig;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import vg.civcraft.mc.civmodcore.api.MaterialAPI;
public class ShipOutOfLuckConfig extends SimpleHackConfig {
private static final Set<Material> BOAT_BREAKERS = new HashSet<>();
public ShipOutOfLuckConfig(SimpleAdminHacks plugin, ConfigurationSection base) {
super(plugin, base);
}
@Override
protected void wireup(ConfigurationSection config) {
BOAT_BREAKERS.clear();
plugin().info("Parsing scuttle materials:");
for (String scuttle : config.getStringList("boatBreakers")) {
if (Strings.isNullOrEmpty(scuttle)) {
plugin().warning("\tScuttle entry was null or empty D:");
continue;
}
Material found = MaterialAPI.getMaterial(scuttle);
if (found == null) {
plugin().warning("\tScuttle entry could not be matched D: [" + scuttle + "]");
continue;
}
if (BOAT_BREAKERS.contains(found)) {
plugin().warning("\tScuttle entry is duplicated: [" + scuttle + "]");
continue;
}
BOAT_BREAKERS.add(found);
plugin().info("\tScuttle recognised: " + found.name());
}
plugin().info("Parsed " + BOAT_BREAKERS.size() + " scuttles.");
}
public Set<Material> getBoatBreakers() {
return Collections.unmodifiableSet(BOAT_BREAKERS);
}
public boolean isBoatBreaker(Material type) {
return type != null && BOAT_BREAKERS.contains(type);
}
}
@@ -2,7 +2,7 @@ package com.programmerdan.minecraft.simpleadminhacks.hacks;
import com.programmerdan.minecraft.simpleadminhacks.SimpleAdminHacks;
import com.programmerdan.minecraft.simpleadminhacks.SimpleHack;
import com.programmerdan.minecraft.simpleadminhacks.configs.PhantomOfTheOperaConfig;
import com.programmerdan.minecraft.simpleadminhacks.configs.PhantomMenaceConfig;
import org.bukkit.ChatColor;
import org.bukkit.Statistic;
import org.bukkit.World;
@@ -14,9 +14,9 @@ import org.bukkit.event.Listener;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.player.PlayerStatisticIncrementEvent;
public class PhantomOfTheOpera extends SimpleHack<PhantomOfTheOperaConfig> implements Listener {
public class PhantomMenace extends SimpleHack<PhantomMenaceConfig> implements Listener {
public PhantomOfTheOpera(SimpleAdminHacks plugin, PhantomOfTheOperaConfig config) {
public PhantomMenace(SimpleAdminHacks plugin, PhantomMenaceConfig config) {
super(plugin, config);
}
@@ -117,8 +117,8 @@ public class PhantomOfTheOpera extends SimpleHack<PhantomOfTheOperaConfig> imple
@Override
public void dataCleanup() { }
public static PhantomOfTheOperaConfig generate(SimpleAdminHacks plugin, ConfigurationSection config) {
return new PhantomOfTheOperaConfig(plugin, config);
public static PhantomMenaceConfig generate(SimpleAdminHacks plugin, ConfigurationSection config) {
return new PhantomMenaceConfig(plugin, config);
}
}
@@ -0,0 +1,137 @@
package com.programmerdan.minecraft.simpleadminhacks.hacks;
import com.programmerdan.minecraft.simpleadminhacks.SimpleAdminHacks;
import com.programmerdan.minecraft.simpleadminhacks.SimpleHack;
import com.programmerdan.minecraft.simpleadminhacks.configs.ShipOutOfLuckConfig;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Tag;
import org.bukkit.block.Block;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Vehicle;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.vehicle.VehicleMoveEvent;
import org.bukkit.inventory.ItemStack;
import vg.civcraft.mc.civmodcore.api.ItemAPI;
public class ShipOutOfLuck extends SimpleHack<ShipOutOfLuckConfig> implements Listener {
public ShipOutOfLuck(SimpleAdminHacks plugin, ShipOutOfLuckConfig config) {
super(plugin, config);
}
@Override
public String status() {
StringBuilder builder = new StringBuilder(getClass().getSimpleName());
builder.append(" is ").append(isEnabled() ? "enabled" : "disabled").append(".").append("\n");
Set<Material> scuttleList = this.config.getBoatBreakers();
if (scuttleList.isEmpty()) {
builder.append("No scuttle blocks.");
}
else {
builder.append(" Scuttle blocks:\n");
builder.append(scuttleList.stream()
.map(effect -> " • " + effect.name())
.collect(Collectors.joining("\n")));
}
return builder.toString();
}
// ------------------------------------------------------------
// Listeners
// ------------------------------------------------------------
@Override
public void registerListeners() {
this.plugin().registerListener(this);
}
@Override
public void unregisterListeners() {
HandlerList.unregisterAll(this);
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void preventBoatPlacements(PlayerInteractEvent event) {
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
return;
}
Block placedOn = Objects.requireNonNull(event.getClickedBlock());
ItemStack placed = event.getItem();
if (!this.config.isBoatBreaker(placedOn.getType())
|| !ItemAPI.isValidItem(placed)
|| !Tag.ITEMS_BOATS.isTagged(placed.getType())) {
return;
}
event.setCancelled(true);
plugin().debug("Prevented boat placement on [" + placedOn.getType().name() + "] by [" +
event.getPlayer().getName() + "] at [" + placedOn.getLocation() + "]");
//return;
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void preventBoatUsage(VehicleMoveEvent event) {
Vehicle vehicle = event.getVehicle();
if (vehicle.getType() != EntityType.BOAT) {
return;
}
List<Entity> passengers = vehicle.getPassengers();
if (passengers.isEmpty()) {
return;
}
Location destination = event.getTo();
if (event.getVehicle().isOnGround()) {
// If the boat is on top of a block, then we need to look below the boat
destination.add(0, -1, 0);
}
if (destination.getY() < 0 || destination.getY() >= destination.getWorld().getMaxHeight()) {
return;
}
Block currentBlock = destination.getBlock();
if (!this.config.isBoatBreaker(currentBlock.getType())) {
return;
}
event.getVehicle().eject();
plugin().debug("Ejected [" + passengers.stream().map(CommandSender::getName)
.collect(Collectors.joining(", ")) + "] from boat at [" + destination + "] because they " +
"sailed over [" + currentBlock.getType().name() + "]");
//return;
}
// ------------------------------------------------------------
// Commands
// ------------------------------------------------------------
@Override
public void registerCommands() { }
@Override
public void unregisterCommands() { }
// ------------------------------------------------------------
// Setup
// ------------------------------------------------------------
@Override
public void dataBootstrap() { }
@Override
public void dataCleanup() { }
public static ShipOutOfLuckConfig generate(SimpleAdminHacks plugin, ConfigurationSection config) {
return new ShipOutOfLuckConfig(plugin, config);
}
}
+9 -1
View File
@@ -260,7 +260,7 @@ hacks:
enabled: true
breakDenyDuration: 3000
laggLenciency: 1.2
PhantomOfTheOpera:
PhantomMenace:
enabled: true
# Players have a statistic called TIME_SINCE_REST. If a player's value is above 72k (3 days minecraft time) then
# they will start spawning phantoms. Setting the cap to below 72k will effectively disable phantoms. Setting the
@@ -289,3 +289,11 @@ hacks:
- BAD_OMEN
- SLOW_DIGGING
- SLOW_FALLING
ShipOutOfLuck:
enabled: true
# The list of Material's that boats cannot be placed on and will eject passengers
boatBreakers:
- ICE
- PACKED_ICE
- FROSTED_ICE
- BLUE_ICE