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

Fixed ChunkManager.sendMapChunk #87

Merged
merged 9 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
18 changes: 17 additions & 1 deletion .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,22 @@ deploy webhooks to print changelog successfully

That's all, matcher will stop when detects next line started with `###` match

### 5.0.9 Release (09.07.2024)
* Updated to minigamesbox 1.3.11
* Fixed ChunkManager.sendMapChunk
* Fixed error in time change menu
* Fixed issue with %player% placeholder (should be lowercase)
* Fixed problem in place rewards
* Fixed small error if non-player threw projectile.
* Added Cancel of BlockExplodeEvent to prevent blocks such as Respawn Anchor explode and damage the arena
* Added Disabled enderpearl throwing while in arena because it allows to teleport to other players plots or outside the arena map, even during voting stage.

### 5.0.8 Release (25.06.2024)
* Updated to minigamesbox 1.3.9

### 5.0.7 Release (18.06.2024)
* API update

### 5.0.6 Release (24.04.2024)
* Updated to minigamesbox 1.3.8

Expand Down Expand Up @@ -630,4 +646,4 @@ it will have BEDROCK value if absent

### 3.0.0 Release (14.05.2018 - 01.06.2018)

* Add everything here
* Add everything here
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ repositories {
}

dependencies {
implementation("plugily.projects:MiniGamesBox-Classic:1.3.10") { isTransitive = false }
implementation("plugily.projects:MiniGamesBox-Classic:1.3.11") { isTransitive = false }
compileOnly("org.spigotmc:spigot-api:1.20.4-R0.1-SNAPSHOT")
compileOnly("io.papermc.paper:paper-api:1.20.4-R0.1-SNAPSHOT")
compileOnly("net.citizensnpcs:citizensapi:2.0.31-SNAPSHOT")
compileOnly("org.jetbrains:annotations:24.0.1")
}

group = "plugily.projects"
version = "5.0.8"
version = "5.0.8-SNAPSHOT2"
description = "BuildBattle"

java {
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -37,65 +37,60 @@ public class ChunkManager {

private static Class<?> packetPlayOutMapChunk, chunkClass;
private static Constructor<?> mapChunkConstructor;
private static Method chunkHandleMethod;

static {
if(ServerVersion.Version.isCurrentLower(ServerVersion.Version.v1_18_R1)) {
if (ServerVersion.Version.isCurrentLower(ServerVersion.Version.v1_18_R1)) {
packetPlayOutMapChunk = PacketUtils.classByName("net.minecraft.network.protocol.game", "PacketPlayOutMapChunk");
chunkClass = PacketUtils.classByName("net.minecraft.world.level.chunk", "Chunk");

try {
chunkHandleMethod = Chunk.class.getMethod("getHandle");
} catch(NoSuchMethodException exc) {
}

if(ServerVersion.Version.isCurrentEqualOrHigher(ServerVersion.Version.v1_17_R1)) {
if (ServerVersion.Version.isCurrentEqualOrHigher(ServerVersion.Version.v1_17_R1)) {
try {
mapChunkConstructor = packetPlayOutMapChunk.getConstructor(PacketUtils.classByName("net.minecraft.world.level.chunk", "LevelChunk"));
} catch(NoSuchMethodException e) {
} catch (NoSuchMethodException e) {
try {
mapChunkConstructor = packetPlayOutMapChunk.getConstructor(chunkClass);
} catch(NoSuchMethodException ex) {
ex.printStackTrace();
} catch (NoSuchMethodException ex) {
throw new RuntimeException(ex);
}
}
}
}
}

public static void sendMapChunk(Player player, Chunk chunk) {
if(ServerVersion.Version.isCurrentEqualOrHigher(ServerVersion.Version.v1_18_R1)) {
if (ServerVersion.Version.isCurrentEqualOrHigher(ServerVersion.Version.v1_18_R1)) {
return; // Should just use World#refreshChunk instead
}

try {
if(ServerVersion.Version.isCurrentEqualOrHigher(ServerVersion.Version.v1_17_R1)) {
Method chunkHandleMethod = chunk.getClass().getMethod("getHandle");
if (ServerVersion.Version.isCurrentEqualOrHigher(ServerVersion.Version.v1_17_R1)) {
PacketUtils.sendPacket(player, mapChunkConstructor.newInstance(chunkHandleMethod.invoke(chunk)));
return;
}

if(ServerVersion.Version.isCurrentEqualOrHigher(ServerVersion.Version.v1_16_R1)) {
if(mapChunkConstructor == null)
if (ServerVersion.Version.isCurrentEqualOrHigher(ServerVersion.Version.v1_16_R1)) {
if (mapChunkConstructor == null)
mapChunkConstructor = packetPlayOutMapChunk.getConstructor(chunkClass, int.class, boolean.class);

PacketUtils.sendPacket(player, mapChunkConstructor.newInstance(chunkHandleMethod.invoke(chunk), 65535, false));
return;
}

if(ServerVersion.Version.isCurrentEqualOrLower(ServerVersion.Version.v1_10_R2)) {
if(mapChunkConstructor == null)
if (ServerVersion.Version.isCurrentEqualOrLower(ServerVersion.Version.v1_10_R2)) {
if (mapChunkConstructor == null)
mapChunkConstructor = packetPlayOutMapChunk.getConstructor(chunkClass, boolean.class, int.class);

PacketUtils.sendPacket(player, mapChunkConstructor.newInstance(chunkHandleMethod.invoke(chunk), true, 65535));
return;
}

if(mapChunkConstructor == null)
if (mapChunkConstructor == null)
mapChunkConstructor = packetPlayOutMapChunk.getConstructor(chunkClass, int.class);

PacketUtils.sendPacket(player, mapChunkConstructor.newInstance(chunkHandleMethod.invoke(chunk), 65535));
} catch(ReflectiveOperationException exception) {
exception.printStackTrace();
} catch (ReflectiveOperationException exception) {
throw new RuntimeException(exception);
}
}

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
Loading
Loading