Skip to content

Commit

Permalink
Fixed many bugs in BuildBattle plugin (#86)
Browse files Browse the repository at this point in the history
* Updated plugin.yml to prevent invalid file error on startup

* Changed version of dependency MiniGamesBox to circumvent build issues

* Fixed error in time change menu

* Fixed issue with %player% placeholder (should be lowercase)

* Bump version from 5.0.7-SNAPSHOT1 to 5.0.8

* Fixed problem in place rewards

* Cancelled BlockExplodeEvent to prevent blocks such as Respawn Anchor explode and damage the arena.

* Fixed BuildBattle menu item not working because API was used at 2 different places. Added bb menu command and used registerSpecialItem to fix.

* Disabled enderpearl throwing while in arena because it allows to teleport to other players plots or outside the arena map, even during voting stage.

* Changed back version number of MiniGamesBox to 1.3.10

* Fixed small error if non-player threw projectile.

---------

Co-authored-by: version-bump[github-action] <41898282+version-bump[github-action]@users.noreply.github.com>
  • Loading branch information
Waterman1001 and version-bump[github-action] authored Jun 28, 2024
1 parent 575040b commit 6259422
Show file tree
Hide file tree
Showing 13 changed files with 113 additions and 66 deletions.
41 changes: 32 additions & 9 deletions src/main/java/plugily/projects/buildbattle/arena/ArenaEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,8 @@ public void onEntityDamageEntity(EntityDamageByEntityEvent event) {
event.setCancelled(true);
}



@EventHandler(priority = EventPriority.HIGH)
public void onDamage(EntityDamageEvent event) {
if(event.getEntity().getType() != EntityType.PLAYER) {
Expand Down Expand Up @@ -468,6 +470,36 @@ public void onTNTExplode(EntityExplodeEvent event) {
}
}

@EventHandler
public void onOtherBlockExplode(BlockExplodeEvent event) {
Location blockLocation = event.getBlock().getLocation();

for(IPluginArena arena : plugin.getArenaRegistry().getArenas()) {
if(!(arena instanceof BaseArena)) {
continue;
}
for(Plot buildPlot : ((BaseArena) arena).getPlotManager().getPlots()) {
if(buildPlot.getCuboid() != null && buildPlot.getCuboid().isInWithMarge(blockLocation, 5)) {
event.blockList().clear();
event.setCancelled(true);
}
}
}
}

@EventHandler
public void onEnderpearlThrow(ProjectileLaunchEvent event) {
if(event.getEntity().getShooter() instanceof Player) {
BaseArena arena = plugin.getArenaRegistry().getArena((Player) event.getEntity().getShooter());
if (arena == null || arena.getArenaState() != IArenaState.IN_GAME) {
return;
}
if (event.getEntity() instanceof EnderPearl) {
event.setCancelled(true);
}
}
}

@EventHandler
public void onWaterFlowEvent(BlockFromToEvent event) {
Location toBlock = event.getToBlock().getLocation();
Expand Down Expand Up @@ -532,15 +564,6 @@ public void onArrowPickup(PlugilyPlayerPickupArrow event) {
}
}

@EventHandler
public void onInventoryClose(InventoryCloseEvent event) {
Player player = (Player) event.getPlayer();
BaseArena baseArena = plugin.getArenaRegistry().getArena(player);
if(baseArena != null && baseArena.getArenaInGameState() == BaseArena.ArenaInGameState.BUILD_TIME) {
baseArena.addMenuItem(player);
}
}

@EventHandler
public void onItemMove(InventoryClickEvent event) {
HumanEntity humanEntity = event.getWhoClicked();
Expand Down
27 changes: 0 additions & 27 deletions src/main/java/plugily/projects/buildbattle/arena/BaseArena.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,33 +217,6 @@ public void teleportToWinnerPlot() {
}
}

HandlerItem optionsMenuItem;

private HandlerItem getMenuItem() {
if(optionsMenuItem == null) {
HandlerItem optionsMenu = new HandlerItem(getPlugin().getOptionsRegistry().getMenuItem());
optionsMenu.setLeftClick(true);
optionsMenu.setRightClick(true);
optionsMenu.addInteractHandler(event -> {
event.setCancelled(true);
getPlugin().getOptionsRegistry().getOptionsGui().open(event.getPlayer());
});
optionsMenu.addInventoryClickHandler(event -> {
getPlugin().getOptionsRegistry().getOptionsGui().open(event.getWhoClicked());
});
optionsMenuItem = optionsMenu.build();
}
return optionsMenuItem;
}

public void addMenuItem(Player player) {
if(player.getInventory().contains(getMenuItem().getItemStack())) {
return;
}
player.getInventory().setItem(8, getMenuItem().getItemStack());
}


public PlotManager getPlotManager() {
return plotManager;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public void teleportToPlots() {
Bukkit.getScheduler().runTaskLater(arena.getPlugin(), () -> {
player.setAllowFlight(true);
player.setFlying(true);
}, 40);
}, 2);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public void handleCall(PluginArena arena) {

for(Player player : pluginArena.getPlayers()) {
player.closeInventory();
pluginArena.addMenuItem(player);
player.setGameMode(GameMode.CREATIVE);
}
} else {
Expand Down Expand Up @@ -103,8 +102,8 @@ public void handleCall(PluginArena arena) {
adjustStatistics(pluginArena);

pluginArena.teleportToWinnerPlot();
pluginArena.executeEndRewards();
getPlugin().getArenaManager().stopGame(false, arena);
pluginArena.executeEndRewards();
} else {
voteForNextPlot(pluginArena);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ public void handleCall(PluginArena arena) {
new TitleBuilder("IN_GAME_MESSAGES_PLOT_GTB_THEME_GUESS_TITLE").asKey().arena(pluginArena).sendArena();

Bukkit.getScheduler().runTaskLater(getPlugin(), () -> pluginArena.getCurrentBuilders().forEach(player -> player.setGameMode(GameMode.CREATIVE)), 40);
pluginArena.getCurrentBuilders().forEach(pluginArena::addMenuItem);

setArenaTimer(getPlugin().getConfig().getInt("Time-Manager." + pluginArena.getArenaType().getPrefix() + ".In-Game"));
pluginArena.setArenaInGameState(BaseArena.ArenaInGameState.BUILD_TIME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private void registerRewards() {
rewardsFactory.registerRewardType("VOTE", new RewardType("voted"));
rewardsFactory.registerRewardType("VOTE_ALL", new RewardType("voted-all"));
rewardsFactory.registerRewardType("REPORT", new RewardType("report"));
rewardsFactory.registerRewardType("PLACE", new RewardType("place"));
rewardsFactory.registerRewardType("PLACE", new RewardType("place", RewardType.ExecutorType.NUMBER, false));
}

private void registerSpecialItems() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import plugily.projects.buildbattle.commands.arguments.admin.plot.RemovePlotArgument;
import plugily.projects.buildbattle.commands.arguments.admin.plot.SelectPlotArgument;
import plugily.projects.buildbattle.commands.arguments.game.GuessArgument;
import plugily.projects.buildbattle.commands.arguments.game.MenuArgument;
import plugily.projects.minigamesbox.api.arena.IPluginArena;
import plugily.projects.minigamesbox.classic.commands.arguments.PluginArgumentsRegistry;

Expand All @@ -50,6 +51,7 @@ public ArgumentsRegistry(Main plugin) {
new AddPlotArgument(this);
new RemovePlotArgument(this);
new SelectPlotArgument(this);
new MenuArgument(this);
new GuessArgument(this);
new ThemeArgument(this);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
*
* BuildBattle - Ultimate building competition minigame
* Copyright (C) 2022 Plugily Projects - maintained by Tigerpanzer_02 and contributors
*
* 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 <http://www.gnu.org/licenses/>.
*
*/

package plugily.projects.buildbattle.commands.arguments.game;

import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import plugily.projects.buildbattle.arena.BaseArena;
import plugily.projects.buildbattle.commands.arguments.ArgumentsRegistry;
import plugily.projects.minigamesbox.api.arena.IArenaState;
import plugily.projects.minigamesbox.classic.commands.arguments.data.CommandArgument;

/**
* @author Tigerpanzer_02
* <p>
* Created at 27.12.2020
*/
public class MenuArgument {

public MenuArgument(ArgumentsRegistry registry) {
registry.mapArgument("buildbattle", new CommandArgument("menu", "", CommandArgument.ExecutorType.PLAYER) {
@Override
public void execute(CommandSender sender, String[] args) {
Player player = (Player) sender;
BaseArena arena = (BaseArena) registry.getPlugin().getArenaRegistry().getArena(player);

if(arena != null && (arena.getArenaState() == IArenaState.IN_GAME))
arena.getPlugin().getOptionsRegistry().getOptionsGui().open(player);
}
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ public void onClick(InventoryClickEvent event) {
return;
}

gui.addItem(new ItemBuilder(XMaterial.CLOCK.parseItem()).name(new MessageBuilder("MENU_OPTION_CONTENT_TIME_TYPE_WORLD").asKey().build()).lore(plot.getTime().name()).build());
//gui.addItem(new ItemBuilder(XMaterial.CLOCK.parseItem()).name(new MessageBuilder("MENU_OPTION_CONTENT_TIME_TYPE_WORLD").asKey().build()).lore(plot.getTime().name()).build());

addClockItem(gui, plot, "MENU_OPTION_CONTENT_TIME_TYPE_WORLD");
addClockItem(gui, plot, "MENU_OPTION_CONTENT_TIME_TYPE_DAY");
addClockItem(gui, plot, "MENU_OPTION_CONTENT_TIME_TYPE_NOON");
addClockItem(gui, plot, "MENU_OPTION_CONTENT_TIME_TYPE_SUNSET");
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/language.yml
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ Menu:
Noon: "Noon (6000 ticks)"
Sunset: "Sunset (12000 ticks)"
Night: "Night (13000 ticks)"
MidNight: "MidNight (18000 ticks)"
MidNight: "Midnight (18000 ticks)"
Sunrise: "Sunrise (23000 ticks)"
Changed: "%plugin_prefix% Time has been changed to %value%"
Biome:
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ api-version: 1.13
commands:
buildbattle:
description: BuildBattle Commands
usage: "\u00A76Correct usage: /bb [option]"
usage: "§6Correct usage: /bb [option]"
aliases: [ bb, buildb ]
buildbattleadmin:
description: BuildBattle Admin Commands
usage: "\u00A76Correct usage: /bba [option]"
usage: "§6Correct usage: /bba [option]"
aliases: [ bba, buildbadmin ]

permissions:
Expand Down
40 changes: 20 additions & 20 deletions src/main/resources/rewards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# BuildBattle rewards configuration
#
# Placeholders list:
# %PLAYER% - Current player name
# %player% - Current player name
# %MAPNAME% - Name of map
# %ARENA-ID% - BaseArena Identifier
# %PLACE% - Player Place (Working on category place)
Expand All @@ -17,11 +17,11 @@
# - chance(1):p:say I was very lucky! # Player has 1% chance to say "I was very lucky!"
# - p:chance(99):spawn # Player has 99% chance to teleport to spawn
# ^ YOU CAN EVEN SWAP CHANCE WITH PLAYER!
# - chance(50):eco give %PLAYER% 10 # Console has 10% chance to give player 10$
# - chance(50):eco give %player% 10 # Console has 10% chance to give player 10$
#
# You can unlock full potential of rewards using our script engine! (since 4.0.0)
# Just add example reward:
# - script:player.sendMessage("oh, hi %PLAYER%"); # It will send "oh, hi <player name>" to player! 100% plain java!
# - script:player.sendMessage("oh, hi %player%"); # It will send "oh, hi <player name>" to player! 100% plain java!
# - script:server.broadcastMessage("hello everyone"); # Broadcasts "hello everyone" to whole server
# - script:player.getInventory().addItem(new org.bukkit.inventory.ItemStack(org.bukkit.Material.DIRT));
# ^ Gives player dirt item (you must always use direct package names for not provided objects)
Expand Down Expand Up @@ -50,40 +50,40 @@ rewards:
# Commands performed when all themes are guessed in GTB
# Delete everything if you don't want to use this section
guess:
- eco give %PLAYER% 2
- eco give %player% 2
guess-all:
- eco give %PLAYER% 2
- eco give %player% 2
# Commands executed when someone vote
vote:
- eco give %PLAYER% 2
- chance(10):eco give %PLAYER% 8
- eco give %player% 2
- chance(10):eco give %player% 8
# Commands executed when all voted for a plot
vote-all:
- eco give %PLAYER% 2
- chance(10):eco give %PLAYER% 8
- eco give %player% 2
- chance(10):eco give %player% 8
# Commands executed when someone report a building
report:
- eco give %PLAYER% 2
- eco give %player% 2
- script:player.sendMessage("You reported the building");
# Commands executed on place X
place:
1:
- eco give %PLAYER% 10
- eco give %player% 10
2:
- eco give %PLAYER% 9
- eco give %player% 9
3:
- eco give %PLAYER% 8
- eco give %player% 8
4:
- eco give %PLAYER% 7
- eco give %player% 7
5:
- eco give %PLAYER% 6
- eco give %player% 6
6:
- eco give %PLAYER% 5
- eco give %player% 5
7:
- eco give %PLAYER% 4
- eco give %player% 4
8:
- eco give %PLAYER% 3
- eco give %player% 3
9:
- eco give %PLAYER% 2
- eco give %player% 2
10:
- eco give %PLAYER% 1
- eco give %player% 1
2 changes: 1 addition & 1 deletion src/main/resources/special_items.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ Back-To-Hub:
Options-Menu:
permission: ""
execute:
- ""
- "p:bb menu"
displayname: "&a&lOptions menu &7(Right Click)"
lore:
- "&7Right-click to open options menu"
Expand Down

0 comments on commit 6259422

Please sign in to comment.