Skip to content

Commit

Permalink
Add Building and Ender to PCI
Browse files Browse the repository at this point in the history
  • Loading branch information
Flo56958 committed Dec 14, 2024
1 parent d5fdfae commit 87982a0
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 13 deletions.
32 changes: 25 additions & 7 deletions src/main/java/de/flo56958/minetinker/modifiers/types/Building.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import de.flo56958.minetinker.MineTinker;
import de.flo56958.minetinker.api.events.MTPlayerInteractEvent;
import de.flo56958.minetinker.data.ToolType;
import de.flo56958.minetinker.modifiers.Modifier;
import de.flo56958.minetinker.modifiers.PlayerConfigurableModifier;
import de.flo56958.minetinker.utils.ConfigurationManager;
import de.flo56958.minetinker.utils.data.DataHandler;
import de.flo56958.minetinker.utils.playerconfig.PlayerConfigurationManager;
import de.flo56958.minetinker.utils.playerconfig.PlayerConfigurationOption;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.block.Block;
Expand All @@ -22,16 +24,17 @@
import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

public class Building extends Modifier implements Listener {
public class Building extends PlayerConfigurableModifier implements Listener {

private static Building instance;
private boolean useDurability;
private boolean giveExpOnUse;
private int expAmount;
private boolean solvePlayerOverlap;

private Building() {
super(MineTinker.getPlugin());
Expand Down Expand Up @@ -69,7 +72,6 @@ public void reload() {
config.addDefault("ModifierItemMaterial", Material.GRASS_BLOCK.name());
config.addDefault("UseDurability", true);
config.addDefault("GiveExpOnUse", true);
config.addDefault("SolvePlayerOverlap", true);
config.addDefault("ExpAmount", 1);

config.addDefault("EnchantCost", 15);
Expand All @@ -86,18 +88,19 @@ public void reload() {
this.useDurability = config.getBoolean("UseDurability", true);
this.giveExpOnUse = config.getBoolean("GiveExpOnUse", true);
this.expAmount = config.getInt("ExpAmount", 1);
this.solvePlayerOverlap = config.getBoolean("SolvePlayerOverlap", true);
}

@EventHandler(ignoreCancelled = true)
public void onPlace(@NotNull final MTPlayerInteractEvent event) {
if (event.getEvent().getAction() != Action.RIGHT_CLICK_BLOCK) return;

final Player player = event.getPlayer();
if (!player.hasPermission(getUsePermission())) return;

final ItemStack tool = event.getTool();
if (!modManager.hasMod(tool, this)) return;

if (event.getEvent().getAction() != Action.RIGHT_CLICK_BLOCK) return;
if (!PlayerConfigurationManager.getInstance().getBoolean(player, ENABLED)) return;

final Block block = event.getEvent().getClickedBlock();
if (block == null) return;
Expand Down Expand Up @@ -132,7 +135,7 @@ public void onPlace(@NotNull final MTPlayerInteractEvent event) {
if (this.giveExpOnUse)
modManager.addExp(player, tool, this.expAmount, true);

if (this.solvePlayerOverlap) {
if (PlayerConfigurationManager.getInstance().getBoolean(player, SOLVE_PLAYER_OVERLAP)) {
// Teleport player one block up if he is inside the block
final BoundingBox blockBB = toFill.getBoundingBox();
final BoundingBox playerBB = player.getBoundingBox();
Expand All @@ -150,4 +153,19 @@ public void onPlace(@NotNull final MTPlayerInteractEvent event) {
event.getEvent().setUseInteractedBlock(Event.Result.DENY); // prevent vanilla behavior by cancelling the event
toPlace.setAmount(toPlace.getAmount() - (isDoubleSlab ? 2 : 1));
}

private final PlayerConfigurationOption ENABLED =
new PlayerConfigurationOption(this, "enabled", PlayerConfigurationOption.Type.BOOLEAN,
"enabled", true);

private final PlayerConfigurationOption SOLVE_PLAYER_OVERLAP =
new PlayerConfigurationOption(this, "solve-player-overlap", PlayerConfigurationOption.Type.BOOLEAN,
"solve-player-overlap", true);

@Override
public List<PlayerConfigurationOption> getPCIOptions() {
final ArrayList<PlayerConfigurationOption> playerConfigurationOptions = new ArrayList<>(List.of(ENABLED, SOLVE_PLAYER_OVERLAP));
playerConfigurationOptions.sort(Comparator.comparing(PlayerConfigurationOption::displayName));
return playerConfigurationOptions;
}
}
21 changes: 15 additions & 6 deletions src/main/java/de/flo56958/minetinker/modifiers/types/Ender.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
import de.flo56958.minetinker.api.events.MTProjectileHitEvent;
import de.flo56958.minetinker.api.events.MTProjectileLaunchEvent;
import de.flo56958.minetinker.data.ToolType;
import de.flo56958.minetinker.modifiers.Modifier;
import de.flo56958.minetinker.modifiers.PlayerConfigurableModifier;
import de.flo56958.minetinker.utils.ChatWriter;
import de.flo56958.minetinker.utils.ConfigurationManager;
import de.flo56958.minetinker.utils.LanguageManager;
import de.flo56958.minetinker.utils.data.DataHandler;
import de.flo56958.minetinker.utils.playerconfig.PlayerConfigurationManager;
import de.flo56958.minetinker.utils.playerconfig.PlayerConfigurationOption;
import org.bukkit.*;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.*;
Expand All @@ -28,15 +30,14 @@
import java.io.File;
import java.util.*;

public class Ender extends Modifier implements Listener {
public class Ender extends PlayerConfigurableModifier implements Listener {

private static Ender instance;
private boolean hasSound;
private boolean hasParticles;
private boolean giveNauseaOnUse;
private int nauseaDuration;
private boolean giveBlindnessOnUse;
private boolean requireSneaking;
private int blindnessDuration;

private Ender() {
Expand Down Expand Up @@ -107,7 +108,6 @@ public void reload() {
this.nauseaDuration = config.getInt("NauseaDuration", 5) * 20;
this.giveBlindnessOnUse = config.getBoolean("GiveBlindnessOnUse", true);
this.blindnessDuration = config.getInt("BlindnessDuration", 3) * 20;
this.requireSneaking = config.getBoolean("RequireSneaking", true);
}

@EventHandler(ignoreCancelled = true)
Expand All @@ -119,7 +119,7 @@ public void effect(EntityShootBowEvent event) {
ItemStack tool = event.getBow();
if (!player.hasPermission(getUsePermission())) return;
if (!modManager.hasMod(tool, this)) return;
if (this.requireSneaking && !player.isSneaking()) return;
if (PlayerConfigurationManager.getInstance().getBoolean(player, REQUIRE_SNEAKING) && !player.isSneaking()) return;

arrow.setMetadata(this.getKey(),
new FixedMetadataValue(this.getSource(), 0));
Expand All @@ -136,7 +136,7 @@ public void effect(final MTProjectileLaunchEvent event) {

if (!player.hasPermission(getUsePermission())) return;
if (!modManager.hasMod(tool, this)) return;
if (this.requireSneaking && !player.isSneaking()) return;
if (PlayerConfigurationManager.getInstance().getBoolean(player, REQUIRE_SNEAKING) && !player.isSneaking()) return;

trident.setMetadata(this.getKey(),
new FixedMetadataValue(this.getSource(), 0));
Expand Down Expand Up @@ -304,4 +304,13 @@ private void spawnParticles(Player player, Location oldLoc) {
cloud2.getLocation().setPitch(90);
}
}

private final PlayerConfigurationOption REQUIRE_SNEAKING =
new PlayerConfigurationOption(this, "require-sneaking", PlayerConfigurationOption.Type.BOOLEAN,
"require-sneaking", true);

@Override
public List<PlayerConfigurationOption> getPCIOptions() {
return List.of(REQUIRE_SNEAKING);
}
}

0 comments on commit 87982a0

Please sign in to comment.