Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Skill Architecture -> Elevator #513

Merged
merged 7 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
init
  • Loading branch information
illyrius666 committed Dec 15, 2024
commit 776b55bb37f111cb8a85b58237bdd89d2cae25d4
1 change: 0 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"github.copilot",
"github.vscode-github-actions",
"pkief.material-icon-theme",
"qwtel.sqlite-viewer",
"usernamehw.errorlens",
"vsls-contrib.gistfs"
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/*------------------------------------------------------------------------------
- Adapt is a Skill/Integration plugin for Minecraft Bukkit Servers
- Copyright (c) 2022 Arcane Arts (Volmit Software)
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <https://www.gnu.org/licenses/>.
-----------------------------------------------------------------------------*/

package com.volmit.adapt.content.adaptation.architect;

import com.volmit.adapt.Adapt;
import com.volmit.adapt.api.adaptation.SimpleAdaptation;
import com.volmit.adapt.util.*;
import com.volmit.adapt.util.reflect.enums.Particles;
import lombok.NoArgsConstructor;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockExplodeEvent;
import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPistonRetractEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerToggleSneakEvent;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class ArchitectElevator extends SimpleAdaptation<ArchitectElevator.Config> {
private final Map<Player, Integer> blockPower;
private final Map<Player, Long> cooldowns;

public ArchitectElevator() {
super("architect-elevator");
registerConfiguration(ArchitectElevator.Config.class);
setDescription(Localizer.dLocalize("architect", "elevator", "description"));
setDisplayName(Localizer.dLocalize("architect", "elevator", "name"));
setIcon(Material.TINTED_GLASS);
setInterval(988);
setBaseCost(getConfig().baseCost);
setMaxLevel(getConfig().maxLevel);
setInitialCost(getConfig().initialCost);
setCostFactor(getConfig().costFactor);
}

public int getBlockPower(double factor) {
return (int) Math.floor(M.lerp(getConfig().minBlocks, getConfig().maxBlocks, factor));
}

@Override
public void onTick() {
for (Player i : Bukkit.getOnlinePlayers()) {
if (!hasAdaptation(i)) {
continue;
}

boolean ready = !hasCooldown(i);
int availablePower = getBlockPower(getLevelPercent(i));
blockPower.compute(i, (k, v) -> {
if ((k == null || v == null) || (ready && v != availablePower)) {
if (i == null) {
return 0;
}
final var world = i.getWorld();
final var location = i.getLocation();

SoundPlayer spw = SoundPlayer.of(world);
spw.play(location, Sound.BLOCK_BEACON_ACTIVATE, 1.0f, 10.0f);
spw.play(location, Sound.BLOCK_RESPAWN_ANCHOR_CHARGE, 1.0f, 0.81f);

return availablePower;
}
return v;
});
}
}

private boolean hasCooldown(Player i) {
if (cooldowns.containsKey(i)) {
if (M.ms() >= cooldowns.get(i)) {
cooldowns.remove(i);
}
}

return cooldowns.containsKey(i);
}

@Override
public boolean isEnabled() {
return getConfig().enabled;
}

@Override
public boolean isPermanent() {
return getConfig().permanent;
}

// TODO: adjust to be of use for this class. -Illyrius
@NoArgsConstructor
protected static class Config {
public long duration = 3000;
public int minBlocks = 9;
public int maxBlocks = 35;
public int cooldown = 5000;
boolean permanent = false;
boolean showParticles = true;
boolean enabled = true;
int baseCost = 5;
int maxLevel = 5;
int initialCost = 1;
double costFactor = 0.40;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ public ArchitectFoundation() {

@Override
public void addStats(int level, Element v) {
v.addLore(C.GREEN + Localizer.dLocalize("architect", "foundation", "lore1") + (getBlockPower(getLevelPercent(level))) + C.GRAY + " " + Localizer.dLocalize("architect", "foundation", "lore2"));
v.addLore(C.GREEN + Localizer.dLocalize("architect", "foundation", "lore1")
+ (getBlockPower(getLevelPercent(level))) + C.GRAY + " "
+ Localizer.dLocalize("architect", "foundation", "lore2"));
}

@EventHandler(priority = EventPriority.HIGHEST)
Expand Down Expand Up @@ -120,7 +122,7 @@ public void on(PlayerMoveEvent e) {
blockPower.put(p, power);
}

//prevent piston from moving blocks // Dupe fix
// prevent piston from moving blocks // Dupe fix
@EventHandler(priority = EventPriority.HIGHEST)
public void on(BlockPistonExtendEvent e) {
if (e.isCancelled()) {
Expand All @@ -134,7 +136,7 @@ public void on(BlockPistonExtendEvent e) {
});
}

//prevent piston from pulling blocks // Dupe fix
// prevent piston from pulling blocks // Dupe fix
@EventHandler(priority = EventPriority.HIGHEST)
public void on(BlockPistonRetractEvent e) {
if (e.isCancelled()) {
Expand All @@ -148,7 +150,7 @@ public void on(BlockPistonRetractEvent e) {
});
}

//prevent TNT from destroying blocks // Dupe fix
// prevent TNT from destroying blocks // Dupe fix
@EventHandler(priority = EventPriority.HIGHEST)
public void on(BlockExplodeEvent e) {
if (e.isCancelled()) {
Expand All @@ -160,15 +162,15 @@ public void on(BlockExplodeEvent e) {
}
}

//prevent block from being destroyed // Dupe fix
// prevent block from being destroyed // Dupe fix
@EventHandler(priority = EventPriority.HIGHEST)
public void on(BlockBreakEvent e) {
if (activeBlocks.contains(e.getBlock())) {
e.setCancelled(true);
}
}

//prevent Entities from destroying blocks // Dupe fix
// prevent Entities from destroying blocks // Dupe fix
@EventHandler(priority = EventPriority.HIGHEST)
public void on(EntityExplodeEvent e) {
if (e.isCancelled()) {
Expand Down Expand Up @@ -282,7 +284,6 @@ private boolean hasCooldown(Player i) {
return cooldowns.containsKey(i);
}


@Override
public boolean isEnabled() {
return getConfig().enabled;
Expand Down