Skip to content

Commit

Permalink
Merge pull request #39 from boiscljo/dev
Browse files Browse the repository at this point in the history
1.5.12.1
  • Loading branch information
boiscljo authored Nov 17, 2023
2 parents 0d02586 + e0d4cb2 commit 6dc107b
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 48 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
SBA_VERSION=1.5.12
SBA_VERSION=1.5.12.1
PAPER_LEGACY_VERSION=1.16.5
BEDWARS_VERSION=0.2.30-SNAPSHOT
BEDWARS_VERSION=0.2.30
CLOUD_COMMANDS_VERSION=1.6.2
COMMODORE_VERSION=2.2
KYORI_ADVENTURE_VERSION=4.11.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public void handlePrePurchase(OnTradeEvent event) {
double maxStackSize;
int finalStackSize;

for (ItemStack itemStack : player.getInventory().getStorageContents()) {
for (ItemStack itemStack : player.getInventory().getContents()) {
if (itemStack != null && itemStack.isSimilar(type.getStack())) {
inInventory = inInventory + itemStack.getAmount();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.bukkit.potion.PotionEffectType;
import org.jetbrains.annotations.NotNull;
import org.screamingsandals.bedwars.Main;
import org.screamingsandals.bedwars.api.events.BedwarsApplyPropertyToItem;
import org.screamingsandals.bedwars.api.events.BedwarsOpenShopEvent;
import org.screamingsandals.bedwars.api.game.ItemSpawner;
import org.screamingsandals.bedwars.api.game.ItemSpawnerType;
Expand Down Expand Up @@ -198,9 +197,6 @@ public Map.Entry<Boolean, Boolean> handlePurchase(Player player, AtomicReference
switch (propertyName) {
case "trap":
if (!property.getPropertyData().hasChild("identifier") && property.getPropertyData().hasChild("data")) { // Fix support for SBW Trap special item
var applyEvent = new BedwarsApplyPropertyToItem(game, player, newItem.get(), propertyData);
SBA.getPluginInstance().getServer().getPluginManager().callEvent(applyEvent);
newItem.set(applyEvent.getStack());
return Map.entry(true, true);
}

Expand Down Expand Up @@ -689,9 +685,6 @@ public Map.Entry<Boolean, Boolean> handlePurchase(Player player, AtomicReference
break;
}
// }
var applyEvent = new BedwarsApplyPropertyToItem(game, player, newItem.get(), propertyData);
SBA.getPluginInstance().getServer().getPluginManager().callEvent(applyEvent);
newItem.set(applyEvent.getStack());

} else {

Expand Down
74 changes: 41 additions & 33 deletions plugin/src/main/java/io/github/pronze/sba/specials/PopupTower.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.screamingsandals.bedwars.api.RunningTeam;
import org.screamingsandals.bedwars.api.game.Game;
import org.screamingsandals.bedwars.api.game.GameStatus;
import org.screamingsandals.bedwars.utils.Sounds;
import org.screamingsandals.lib.tasker.DefaultThreads;
import org.screamingsandals.lib.tasker.Tasker;
import org.screamingsandals.lib.tasker.TaskerTime;
Expand All @@ -40,6 +41,7 @@ public class PopupTower {

private final Game game;
private final Material material;
private final byte legacyData;
private final Location centerPoint;
private final BlockFace placementFace;
private final List<Location> enterancelocation = new ArrayList<>();
Expand All @@ -66,50 +68,50 @@ public void createTower() {
Tasker.runDelayed(DefaultThreads.GLOBAL_THREAD, () -> {
// second platform
final Block secondPlatform = centerPoint.getBlock().getRelative(BlockFace.UP, 5);
placeBlock(secondPlatform.getLocation(), material);
pillarSides.forEach(blockFace -> placeBlock(secondPlatform.getRelative(blockFace).getLocation(), material));
placeBlock(secondPlatform.getLocation(), material, legacyData);
pillarSides.forEach(blockFace -> placeBlock(secondPlatform.getRelative(blockFace).getLocation(), material, legacyData));

placeBlock(secondPlatform.getRelative(BlockFace.NORTH_WEST).getLocation(), material);
placeBlock(secondPlatform.getRelative(BlockFace.NORTH_EAST).getLocation(), material);
placeBlock(secondPlatform.getRelative(BlockFace.SOUTH_WEST).getLocation(), material);
placeBlock(secondPlatform.getRelative(BlockFace.SOUTH_EAST).getLocation(), material);
placeBlock(secondPlatform.getRelative(BlockFace.NORTH_WEST).getLocation(), material, legacyData);
placeBlock(secondPlatform.getRelative(BlockFace.NORTH_EAST).getLocation(), material, legacyData);
placeBlock(secondPlatform.getRelative(BlockFace.SOUTH_WEST).getLocation(), material, legacyData);
placeBlock(secondPlatform.getRelative(BlockFace.SOUTH_EAST).getLocation(), material, legacyData);

final var northWestCornerBlock = secondPlatform.getRelative(BlockFace.NORTH_WEST, 2).getRelative(BlockFace.UP);
placeBlock(northWestCornerBlock.getRelative(BlockFace.DOWN).getLocation(), material);
placeBlock(northWestCornerBlock.getRelative(BlockFace.WEST).getLocation(), material);
placeBlock(northWestCornerBlock.getRelative(BlockFace.NORTH).getLocation(), material);
placeBlock(northWestCornerBlock.getRelative(BlockFace.WEST).getRelative(BlockFace.UP).getLocation(), material);
placeBlock(northWestCornerBlock.getRelative(BlockFace.NORTH).getRelative(BlockFace.UP).getLocation(), material);
placeBlock(northWestCornerBlock.getRelative(BlockFace.DOWN).getLocation(), material, legacyData);
placeBlock(northWestCornerBlock.getRelative(BlockFace.WEST).getLocation(), material, legacyData);
placeBlock(northWestCornerBlock.getRelative(BlockFace.NORTH).getLocation(), material, legacyData);
placeBlock(northWestCornerBlock.getRelative(BlockFace.WEST).getRelative(BlockFace.UP).getLocation(), material, legacyData);
placeBlock(northWestCornerBlock.getRelative(BlockFace.NORTH).getRelative(BlockFace.UP).getLocation(), material, legacyData);

final var northEastCornerBlock = secondPlatform.getRelative(BlockFace.NORTH_EAST, 2).getRelative(BlockFace.UP);
placeBlock(northEastCornerBlock.getRelative(BlockFace.DOWN).getLocation(), material);
placeBlock(northEastCornerBlock.getRelative(BlockFace.EAST).getLocation(), material);
placeBlock(northEastCornerBlock.getRelative(BlockFace.NORTH).getLocation(), material);
placeBlock(northEastCornerBlock.getRelative(BlockFace.NORTH).getRelative(BlockFace.UP).getLocation(), material);
placeBlock(northEastCornerBlock.getRelative(BlockFace.EAST).getRelative(BlockFace.UP).getLocation(), material);
placeBlock(northEastCornerBlock.getRelative(BlockFace.DOWN).getLocation(), material, legacyData);
placeBlock(northEastCornerBlock.getRelative(BlockFace.EAST).getLocation(), material, legacyData);
placeBlock(northEastCornerBlock.getRelative(BlockFace.NORTH).getLocation(), material, legacyData);
placeBlock(northEastCornerBlock.getRelative(BlockFace.NORTH).getRelative(BlockFace.UP).getLocation(), material, legacyData);
placeBlock(northEastCornerBlock.getRelative(BlockFace.EAST).getRelative(BlockFace.UP).getLocation(), material, legacyData);

final var southWestCornerBlock = secondPlatform.getRelative(BlockFace.SOUTH_WEST, 2).getRelative(BlockFace.UP);
placeBlock(southWestCornerBlock.getRelative(BlockFace.DOWN).getLocation(), material);
placeBlock(southWestCornerBlock.getRelative(BlockFace.WEST).getLocation(), material);
placeBlock(southWestCornerBlock.getRelative(BlockFace.SOUTH).getLocation(), material);
placeBlock(southWestCornerBlock.getRelative(BlockFace.SOUTH).getRelative(BlockFace.UP).getLocation(), material);
placeBlock(southWestCornerBlock.getRelative(BlockFace.WEST).getRelative(BlockFace.UP).getLocation(), material);
placeBlock(southWestCornerBlock.getRelative(BlockFace.DOWN).getLocation(), material, legacyData);
placeBlock(southWestCornerBlock.getRelative(BlockFace.WEST).getLocation(), material, legacyData);
placeBlock(southWestCornerBlock.getRelative(BlockFace.SOUTH).getLocation(), material, legacyData);
placeBlock(southWestCornerBlock.getRelative(BlockFace.SOUTH).getRelative(BlockFace.UP).getLocation(), material, legacyData);
placeBlock(southWestCornerBlock.getRelative(BlockFace.WEST).getRelative(BlockFace.UP).getLocation(), material, legacyData);

final var southEastCornerBlock = secondPlatform.getRelative(BlockFace.SOUTH_EAST, 2).getRelative(BlockFace.UP);
placeBlock(southEastCornerBlock.getRelative(BlockFace.DOWN).getLocation(), material);
placeBlock(southEastCornerBlock.getRelative(BlockFace.EAST).getLocation(), material);
placeBlock(southEastCornerBlock.getRelative(BlockFace.SOUTH).getLocation(), material);
placeBlock(southEastCornerBlock.getRelative(BlockFace.EAST).getRelative(BlockFace.UP).getLocation(), material);
placeBlock(southEastCornerBlock.getRelative(BlockFace.SOUTH).getRelative(BlockFace.UP).getLocation(), material);
placeBlock(southEastCornerBlock.getRelative(BlockFace.DOWN).getLocation(), material, legacyData);
placeBlock(southEastCornerBlock.getRelative(BlockFace.EAST).getLocation(), material, legacyData);
placeBlock(southEastCornerBlock.getRelative(BlockFace.SOUTH).getLocation(), material, legacyData);
placeBlock(southEastCornerBlock.getRelative(BlockFace.EAST).getRelative(BlockFace.UP).getLocation(), material, legacyData);
placeBlock(southEastCornerBlock.getRelative(BlockFace.SOUTH).getRelative(BlockFace.UP).getLocation(), material, legacyData);

// connection blocks
placeRowAnimated(3, northWestCornerBlock.getRelative(BlockFace.NORTH).getLocation(), BlockFace.EAST, 1);
placeRowAnimated(3, southWestCornerBlock.getRelative(BlockFace.SOUTH).getLocation(), BlockFace.EAST, 1);
placeRowAnimated(4, southWestCornerBlock.getRelative(BlockFace.SOUTH_WEST).getLocation(), BlockFace.NORTH, 1);
placeRowAnimated(4, southEastCornerBlock.getRelative(BlockFace.EAST).getLocation(), BlockFace.NORTH, 1);

placeBlock(secondPlatform.getRelative(placementFace, 3).getRelative(BlockFace.UP, 2).getLocation(), material);
placeBlock(secondPlatform.getRelative(placementFace.getOppositeFace(), 3).getRelative(BlockFace.UP, 2).getLocation(), material);
placeBlock(secondPlatform.getRelative(placementFace, 3).getRelative(BlockFace.UP, 2).getLocation(), material, legacyData);
placeBlock(secondPlatform.getRelative(placementFace.getOppositeFace(), 3).getRelative(BlockFace.UP, 2).getLocation(), material, legacyData);

final Location firstLadderBlock = centerPoint.getBlock().getRelative(placementFace).getLocation();
placeLadderRow(5, firstLadderBlock, BlockFace.UP, placementFace.getOppositeFace());
Expand All @@ -126,7 +128,7 @@ public void placeRowAnimated(int length, Location loc, BlockFace face, int delay
for (int i = 0; i < length; i++) {
lastLoc = lastLoc.getBlock().getRelative(face).getLocation();
Location finalLastLoc = lastLoc;
Tasker.runDelayed(DefaultThreads.GLOBAL_THREAD, () -> placeBlock(finalLastLoc, material), (delay += 1), TaskerTime.TICKS);
Tasker.runDelayed(DefaultThreads.GLOBAL_THREAD, () -> placeBlock(finalLastLoc, material, legacyData), (delay += 1), TaskerTime.TICKS);
}
}

Expand Down Expand Up @@ -171,21 +173,27 @@ public void placeLadderRow(int length, Location loc, BlockFace face, BlockFace l
} else {
Reflect.getMethod(ladder, "setData", byte.class).invoke(faceToByte.get(ladderFace));
}
Objects.requireNonNull(loc.getWorld()).playSound(loc, Sound.BLOCK_STONE_PLACE, 1, 1);
Sounds.playSound(loc, "BLOCK_STONE_PLACE", Sounds.BLOCK_STONE_BREAK, 1, 1);
}
}

public void placeBlock(Location loc, Material mat) {
if (!isLocationSafe(loc)) {
public void placeBlock(Location loc, Material mat, byte legacyData) {
if (!isLocationSafe(loc) || !game.isLocationInArena(loc)) {
return;
}
if (game.getStatus() != GameStatus.RUNNING) {
return;
}
game.getRegion().removeBlockBuiltDuringGame(loc);
loc.getBlock().setType(mat);

if (Main.isLegacy() && legacyData != 0) {
var block = loc.getBlock();
Reflect.getMethod(block, "setData", byte.class).invoke(legacyData);
}

game.getRegion().addBuiltDuringGame(loc);
loc.getWorld().playSound(loc, Sound.BLOCK_STONE_PLACE, 1, 1);
Sounds.playSound(loc, "BLOCK_STONE_PLACE", Sounds.BLOCK_STONE_BREAK, 1, 1);
}

public boolean isLocationSafe(Location location) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.github.pronze.sba.SBA;
import io.github.pronze.sba.specials.runners.BridgeEggRunnable;
import io.github.pronze.sba.utils.SBAUtil;
import org.bukkit.Material;
import org.bukkit.entity.Egg;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
Expand Down Expand Up @@ -58,7 +59,19 @@ public void onEggUse(PlayerInteractEvent event) {
String unhidden = APIUtils.unhashFromInvisibleStringStartsWith(stack, BRIDGE_EGG_PREFIX);
if (unhidden != null) {
event.setCancelled(true);
stack.setAmount(stack.getAmount() - 1);
if (stack.getAmount() > 1) {
stack.setAmount(stack.getAmount() - 1);
} else {
try {
if (player.getInventory().getItemInOffHand().equals(stack)) {
player.getInventory().setItemInOffHand(new ItemStack(Material.AIR));
} else {
player.getInventory().remove(stack);
}
} catch (Throwable e) {
player.getInventory().remove(stack);
}
}
player.updateInventory();
final var egg = player.launchProjectile(Egg.class);
final var playerTeam = game.getTeamOfPlayer(player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.github.pronze.sba.specials.PopupTower;
import io.github.pronze.sba.specials.SpawnerProtection;
import io.github.pronze.sba.utils.SBAUtil;
import org.bukkit.Material;
import org.bukkit.block.BlockFace;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
Expand Down Expand Up @@ -54,13 +55,27 @@ public void onPopupTowerUse(PlayerInteractEvent event) {
String unhidden = APIUtils.unhashFromInvisibleStringStartsWith(stack, POPUP_TOWER_PREFIX);
if (unhidden != null) {
event.setCancelled(true);
stack.setAmount(stack.getAmount() - 1);
if (stack.getAmount() > 1) {
stack.setAmount(stack.getAmount() - 1);
} else {
try {
if (player.getInventory().getItemInOffHand().equals(stack)) {
player.getInventory().setItemInOffHand(new ItemStack(Material.AIR));
} else {
player.getInventory().remove(stack);
}
} catch (Throwable e) {
player.getInventory().remove(stack);
}
}
player.updateInventory();
final var team = game.getTeamOfPlayer(player);
final var playerFace = SBAUtil.yawToFace(player.getLocation().getYaw(), false);
final var wool = TeamColor.fromApiColor(team.getColor()).getWool();
PopupTower tower = new PopupTower(
game,
TeamColor.fromApiColor(team.getColor()).getWool().getType(),
wool.getType(),
Main.isLegacy() ? wool.getData().getData() : 0,
player.getLocation().getBlock().getRelative(playerFace).getRelative(BlockFace.DOWN)
.getLocation(),
playerFace);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.screamingsandals.bedwars.api.game.GameStatus;
import org.screamingsandals.bedwars.game.TeamColor;
import org.screamingsandals.bedwars.utils.Sounds;
import org.screamingsandals.lib.utils.reflect.Reflect;

public class BridgeEggRunnable extends BukkitRunnable {
@Getter
Expand All @@ -26,13 +27,16 @@ public class BridgeEggRunnable extends BukkitRunnable {
private final Game game;
private final RunningTeam team;
private final Material wool;
private final byte legacyData;

public BridgeEggRunnable(Egg egg, RunningTeam team, Player thrower, Game game) {
this.egg = egg;
this.team = team;
this.thrower = thrower;
this.game = game;
this.wool = TeamColor.fromApiColor(team.getColor()).getWool().getType();
var wool = TeamColor.fromApiColor(team.getColor()).getWool();
this.wool = wool.getType();
this.legacyData = Main.isLegacy() ? wool.getData().getData() : 0;
task = runTaskTimer(SBA.getPluginInstance(), 0L, 1L);
}

Expand All @@ -59,8 +63,13 @@ public void run() {
}

public void setBlock(Block block) {
if (block.getType() == Material.AIR) {
if (block.getType() == Material.AIR && game.isLocationInArena(block.getLocation())) {
block.setType(wool);

if (Main.isLegacy() && legacyData != 0) {
Reflect.getMethod(block, "setData", byte.class).invoke(legacyData);
}

game.getRegion().addBuiltDuringGame(block.getLocation());
Sounds.playSound(block.getLocation(), "ENTITY_CHICKEN_EGG", Sounds.ENTITY_CHICKEN_EGG, 1, 1);
}
Expand Down
12 changes: 12 additions & 0 deletions plugin/src/main/java/io/github/pronze/sba/utils/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public static void info(@NonNull String message, Object... params) {
return;
}
instance.logger.info(getMessage(message, params));
printStackTraces(params);
}
public static void trace(@NonNull String message, Object... params) {
if (instance.testMode) {
Expand All @@ -48,6 +49,7 @@ public static void trace(@NonNull String message, Object... params) {
}
if (instance.level.getLevel() >= Level.TRACE.getLevel()) {
instance.logger.info(getMessage(message, params));
printStackTraces(params);
}
}

Expand All @@ -58,6 +60,7 @@ public static void warn(@NonNull String message, Object... params) {
}
if (instance.level.getLevel() >= Level.WARNING.getLevel()) {
instance.logger.warning(getMessage(message, params));
printStackTraces(params);
}
}

Expand All @@ -68,6 +71,7 @@ public static void error(@NonNull String message, Object... params) {
}
if (instance.level.getLevel() >= Level.ERROR.getLevel()) {
instance.logger.severe(getMessage(message, params));
printStackTraces(params);
}
}

Expand All @@ -84,6 +88,14 @@ private static String getMessage(String message, Object... params) {
return message;
}

private static void printStackTraces(Object... params) {
for (var param : params) {
if (param instanceof Throwable) {
((Throwable) param).printStackTrace();
}
}
}

public static void setMode(Level level) {
if(instance != null)
instance.level = level;
Expand Down

0 comments on commit 6dc107b

Please sign in to comment.