Skip to content

Commit

Permalink
Bump Version + Use new API for LockTeamChest
Browse files Browse the repository at this point in the history
  • Loading branch information
MetallicGoat committed May 21, 2024
1 parent 874fbf8 commit 0dab7a2
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 52 deletions.
Binary file removed libs/public/BedwarsAPI-5.3.3.jar
Binary file not shown.
Binary file added libs/public/BedwarsAPI-5.4.5.jar
Binary file not shown.
20 changes: 10 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>me.metallicgoat</groupId>
<artifactId>MBedwarsTweaks</artifactId>
<version>4.1.0</version>
<version>4.1.2</version>

<repositories>
<repository>
Expand Down Expand Up @@ -36,11 +36,18 @@
<version>2.11.3</version>
<scope>provided</scope>
</dependency>
<!-- <dependency>-->
<!-- <groupId>de.marcely.bedwars</groupId>-->
<!-- <artifactId>API</artifactId>-->
<!-- <version>5.4.4</version>-->
<!-- <scope>provided</scope>-->
<!-- </dependency>-->
<dependency>
<groupId>de.marcely.bedwars</groupId>
<artifactId>API</artifactId>
<version>5.4.4</version>
<scope>provided</scope>
<version>5.4.5</version>
<scope>system</scope>
<systemPath>${basedir}/libs/public/BedwarsAPI-5.4.5.jar</systemPath>
</dependency>
<dependency>
<groupId>me.metallicgoat.hotbarmanageraddon</groupId>
Expand All @@ -56,13 +63,6 @@
<scope>system</scope>
<systemPath>${basedir}/libs/public/PrestigeAddonAPI-1.2.0.jar</systemPath>
</dependency>
<!-- <dependency>-->
<!-- <groupId>de.marcely.bedwars</groupId>-->
<!-- <artifactId>API</artifactId>-->
<!-- <version>5.3.3</version>-->
<!-- <scope>system</scope>-->
<!-- <systemPath>${basedir}/libs/public/BedwarsAPI-5.3.3.jar</systemPath>-->
<!-- </dependency>-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

public class MBedwarsTweaksPlugin extends JavaPlugin {

public static final int MIN_MBEDWARS_API_VER = 100;
public static final String MIN_MBEDWARS_VER_NAME = "5.4";
public static final int MIN_MBEDWARS_API_VER = 104;
public static final String MIN_MBEDWARS_VER_NAME = "5.4.5";

@Getter
private static MBedwarsTweaksPlugin instance;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,42 @@
package me.metallicgoat.tweaksaddon.tweaks.misc;

import de.marcely.bedwars.api.BedwarsAPI;
import de.marcely.bedwars.api.arena.Arena;
import de.marcely.bedwars.api.arena.ArenaStatus;
import de.marcely.bedwars.api.arena.Team;
import de.marcely.bedwars.api.event.player.PlayerOpenArenaChestEvent;
import de.marcely.bedwars.api.message.Message;
import de.marcely.bedwars.tools.location.XYZYP;
import me.metallicgoat.tweaksaddon.config.MainConfig;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;

public class LockTeamChest implements Listener {

private static Team getChestTeam(Arena arena, Block chest) {
@EventHandler
public void playerOpenArenaChest(PlayerOpenArenaChestEvent event) {
// Dont mess with TeamChests, handled by MBedwars
if (!MainConfig.lock_team_chest_enabled || event.isTeamChest())
return;

final Arena arena = event.getArena();
final Player player = event.getPlayer();
final Team playerTeam = event.getTeam();
final Team chestTeam = getChestTeam(arena, event.getChestBlock());

if (chestTeam != null && !arena.getPlayersInTeam(chestTeam).isEmpty() && chestTeam != playerTeam) {
final String failOpen = Message.build(MainConfig.lock_team_chest_fail_open)
.placeholder("team-name", chestTeam.getDisplayName())
.placeholder("team", chestTeam.getDisplayName())
.done();

player.sendMessage(failOpen);
event.setCancelled(true);
}
}

private Team getChestTeam(Arena arena, Block chest) {
if (arena.getGameWorld() == chest.getWorld()) {
for (Team team : arena.getEnabledTeams()) {
final XYZYP spawn = arena.getTeamSpawn(team);
Expand All @@ -32,39 +50,7 @@ private static Team getChestTeam(Arena arena, Block chest) {
}
}
}
return null;
}

@EventHandler
public void onChestOpen(PlayerInteractEvent e) {
if (!MainConfig.lock_team_chest_enabled)
return;

final Player player = e.getPlayer();
final Arena arena = BedwarsAPI.getGameAPI().getArenaByPlayer(player);
final Block block = e.getClickedBlock();

// Check if player is opening chest in an arena
if (arena == null ||
arena.getStatus() != ArenaStatus.RUNNING ||
block == null ||
e.getAction() != Action.RIGHT_CLICK_BLOCK)
return;

if (block.getType() == Material.CHEST) {
final Team playerTeam = arena.getPlayerTeam(player);
final Team chestTeam = getChestTeam(arena, block);

if (chestTeam != null && !arena.getPlayersInTeam(chestTeam).isEmpty() && chestTeam != playerTeam) {

final String failOpen = Message.build(MainConfig.lock_team_chest_fail_open)
.placeholder("team-name", chestTeam.getDisplayName())
.placeholder("team", chestTeam.getDisplayName())
.done();

player.sendMessage(failOpen);
e.setCancelled(true);
}
}
return null;
}
}
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: MBedwarsTweaks
version: 4.1.0
version: 4.1.2
author: MetallicGoat
main: me.metallicgoat.tweaksaddon.MBedwarsTweaksPlugin
description: Adds some extra customizability to MBedwars
Expand Down

0 comments on commit 0dab7a2

Please sign in to comment.