-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic implementation of AntiGriefing features
- Loading branch information
Showing
5 changed files
with
114 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/main/java/com/mythicamc/commands/BuildModeCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.mythicamc.commands; | ||
|
||
import com.mythicamc.utils.AntiGriefUtility; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandExecutor; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.UUID; | ||
|
||
public class BuildModeCommand implements CommandExecutor { | ||
@Override | ||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { | ||
if (sender instanceof Player) { | ||
Player player = (Player) sender; | ||
|
||
// Check if the player has the necessary permission | ||
if (player.hasPermission("kitpvp.admin.build")) { | ||
UUID playerId = player.getUniqueId(); | ||
|
||
// Toggle build mode for the player | ||
if (AntiGriefUtility.buildModePlayers.contains(playerId)) { | ||
AntiGriefUtility.buildModePlayers.remove(playerId); | ||
player.sendMessage("Build mode disabled."); | ||
} else { | ||
AntiGriefUtility.buildModePlayers.add(playerId); | ||
player.sendMessage("Build mode enabled."); | ||
} | ||
|
||
return true; | ||
} else { | ||
player.sendMessage("You do not have permission to use this command."); | ||
} | ||
} else { | ||
sender.sendMessage("Only players can use this command."); | ||
} | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.mythicamc.utils; | ||
|
||
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.block.BlockBreakEvent; | ||
import org.bukkit.event.block.BlockPlaceEvent; | ||
import org.bukkit.event.entity.EntityDamageEvent; | ||
import org.bukkit.event.player.PlayerDropItemEvent; | ||
import org.bukkit.event.player.PlayerInteractEvent; | ||
|
||
import java.util.HashSet; | ||
import java.util.UUID; | ||
|
||
public class AntiGriefUtility implements Listener { | ||
|
||
public static final HashSet<UUID> buildModePlayers = new HashSet<>(); | ||
|
||
@EventHandler | ||
public void onBlockBreak(BlockBreakEvent event) { | ||
Player player = event.getPlayer(); | ||
if (!buildModePlayers.contains(player.getUniqueId())) { | ||
event.setCancelled(true); | ||
} | ||
} | ||
|
||
@EventHandler | ||
public void onBlockPlace(BlockPlaceEvent event) { | ||
Player player = event.getPlayer(); | ||
if (!buildModePlayers.contains(player.getUniqueId())) { | ||
event.setCancelled(true); | ||
} | ||
} | ||
|
||
@EventHandler | ||
public void onPlayerInteract(PlayerInteractEvent event) { | ||
Player player = event.getPlayer(); | ||
if ((event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.LEFT_CLICK_BLOCK) | ||
&& !buildModePlayers.contains(player.getUniqueId())) { | ||
event.setCancelled(true); | ||
} | ||
} | ||
|
||
@EventHandler | ||
public void onEntityDamage(EntityDamageEvent event) { | ||
// Check if the entity is a player and the damage cause is falling | ||
if (event.getEntity() instanceof Player && event.getCause() == EntityDamageEvent.DamageCause.FALL) { | ||
event.setCancelled(true); // Cancel the fall damage | ||
} | ||
} | ||
|
||
@EventHandler | ||
public void onPlayerDropItem(PlayerDropItemEvent event) { | ||
event.setCancelled(true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.mythicamc.utils; | ||
|
||
public class KitSelectorGUI { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters