Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
moom0o authored Jun 2, 2020
1 parent a1f461e commit 9a0f241
Show file tree
Hide file tree
Showing 4 changed files with 358 additions and 0 deletions.
3 changes: 3 additions & 0 deletions META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: me.moomoo.anarchyexploitfixes.Main

42 changes: 42 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
NoConsoleOutput: false
DEBUG: false

#Illegal block preventions
PreventPlacingIllegalBlocks: true
RemoveIllegalBlockOnPlace: true
RemoveIllegalBlocksOnInteract: true
RemoveIllegalBlocksOnJoin: true
RemoveIllegalBlocksOnInventoryOpen: true
RemoveIllegalBlocksOnDrop: true
RemoveIllegalBlocksOnClick: true
RemoveIllegalBlocksOnPickup: true
RemoveIllegalBlocksOnMove: true
#Remove illegal blocks on chunkload, useful if players have placed a lot of bedrock/other blocks and you want to get rid of it
RemoveALLIllegalBlocksOnCHUNKLOAD: false

#Bugfixes
PreventEndGatewayCrashExploit: true
PreventDestroyingEndPortals: true

#Dupe preventions
DisableChestsOnDonkeys: false
PreventDonkeysFromGoingThroughPortals: false

#List of banned blocks.
#WARNING: ADDING MOB SPAWNER TO THIS LIST WHILE HAVING RemoveALLIllegalBlocksOnCHUNKLOAD ENABLED WILL REMOVE ALL MOB SPAWNERS IN YOUR WORLD.
#You can also add non blocks and they should get removed aswell.
BANNED_BLOCKS:
- BEDROCK
- BARRIER
- COMMAND
- STRUCTURE_BLOCK
- MONSTER_EGG

#The item banned blocks are replaced with.
Replacement_Item: STONE



# 1b1t options
AllowBreakingBedrock: false
1b1tPlaceBedrock: false
309 changes: 309 additions & 0 deletions me/moomoo/anarchyexploitfixes/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,309 @@
package me.moomoo.anarchyexploitfixes;

import org.bukkit.*;
import org.bukkit.block.Container;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.ChestedHorse;
import org.bukkit.entity.Entity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityPortalEvent;
import org.bukkit.event.entity.EntityTeleportEvent;
import org.bukkit.event.inventory.*;
import org.bukkit.event.player.*;
import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;

public class Main extends JavaPlugin implements Listener {
FileConfiguration config = getConfig();
@Override
public void onEnable() {
saveDefaultConfig();
System.out.println("[ENABLED] AnarchyExploitFixes - Made by moomoo");
Bukkit.getServer().getPluginManager().registerEvents(this, this);
}
public void onDisable() {
System.out.println("[DISABLED] AnarchyExploitFixes - Made by moomoo");
}

@EventHandler
private void onPlayerBucketEvent(PlayerBucketEmptyEvent evt) {
if(getConfig().getBoolean("PreventDestroyingEndPortals")){
String playerName = evt.getPlayer().getName();
String type = evt.getBlockClicked().getType().toString();
String face = evt.getBlockFace().toString();
String world = evt.getBlockClicked().getWorld().getName();
if(getConfig().getBoolean("DEBUG")){
System.out.println("PlayerBucketEmptyEvent " + type);
}
if (type == "BEDROCK") {
if (world.equalsIgnoreCase("world_the_end")) {
if (face == "NORTH" || face == "EAST" || face == "SOUTH" || face == "WEST") {
evt.setCancelled(true);
System.out.println("Prevented " + playerName + " from destroying a portal!");
}
}
}
if (type == "ENDER_PORTAL_FRAME") {
if (face == "NORTH" || face == "EAST" || face == "SOUTH" || face == "WEST") {
evt.setCancelled(true);
System.out.println("Prevented " + playerName + " from destroying a portal!");
}
}
}
}
@EventHandler
private void onEntityPortalEvent(EntityPortalEvent evt) {
if(getConfig().getBoolean("PreventDonkeysFromGoingThroughPortals")){
Entity entity = evt.getEntity();
if(getConfig().getBoolean("DEBUG")){
System.out.println("EntityPortalEvent " + entity);
}
if(entity instanceof ChestedHorse){
if(((ChestedHorse) entity).isCarryingChest()){
evt.setCancelled(true);
if(!getConfig().getBoolean("NoConsoleOutput")){
System.out.println("Prevented a " + entity.toString() + " from going through portal");
}
}
}
}
}
@EventHandler
private void onPlayerInteractEvent(PlayerInteractEvent evt){
if(getConfig().getBoolean("RemoveIllegalBlocksOnInteract")){
if (evt.getClickedBlock() != null) {
if (evt.getClickedBlock().getState() instanceof Container) {
if(getConfig().getBoolean("DEBUG")){
System.out.println("PlayerInteractEvent " + evt.getClickedBlock().getType().toString());
}
getConfig().getList("BANNED_BLOCKS").forEach(b -> {
((Container) evt.getClickedBlock().getState()).getInventory().remove(Material.getMaterial((String) b));
});
}
}
}
}
@EventHandler
private void onPlayerJoinEvent(PlayerJoinEvent evt){
if(getConfig().getBoolean("RemoveIllegalBlocksOnJoin")){
getConfig().getList("BANNED_BLOCKS").forEach(b -> {
if(getConfig().getBoolean("DEBUG")){
System.out.println("PlayerJoinEvent");
}
evt.getPlayer().getInventory().remove(Material.getMaterial((String) b));
});
}
}
@EventHandler
private void onInventoryOpenEvent(InventoryOpenEvent evt){
if(getConfig().getBoolean("RemoveIllegalBlocksOnInventoryOpen")) {
getConfig().getList("BANNED_BLOCKS").forEach(b -> {
if(getConfig().getBoolean("DEBUG")){
System.out.println("InventoryOpenEvent");
}
evt.getPlayer().getInventory().remove(Material.getMaterial((String) b));
});
}
}
@EventHandler
private void onBlockDropItemEvent(PlayerDropItemEvent evt){
if(getConfig().getBoolean("DEBUG")){
Bukkit.broadcastMessage("§6DEBUG: " + evt.getItemDrop().getItemStack().getType().toString());
}
if(getConfig().getBoolean("RemoveIllegalBlocksOnDrop")) {
if(getConfig().getBoolean("DEBUG")){
System.out.println("PlayerDropItemEvent");
}
String item = evt.getItemDrop().getItemStack().getType().toString();
if (getConfig().getList("BANNED_BLOCKS").contains(item)) {
evt.getItemDrop().getItemStack().setType(Material.getMaterial(getConfig().getString("Replacement_Item")));
evt.getPlayer().getInventory().remove(Material.BEDROCK);
evt.setCancelled(true);
}
}
}
@EventHandler
private void onBlockDamage(BlockDamageEvent evt){
if(getConfig().getBoolean("DEBUG")){
System.out.println("BlockDamageEvent " + evt.getBlock().getType().toString());
}
if(getConfig().getBoolean("AllowBreakingBedrock")){
if(evt.getBlock().getType().toString() == "BEDROCK"){
if(evt.getBlock().getWorld().getName().equalsIgnoreCase("world_nether")){
if(evt.getBlock().getY() > 6 && evt.getBlock().getY() < 123){
evt.getBlock().setType(Material.AIR);
}
}
if(evt.getBlock().getWorld().getName().equalsIgnoreCase("world")){
if(evt.getBlock().getY() > 6){
evt.getBlock().setType(Material.AIR);
}
}

}
}
}
@EventHandler
private void onChunkLoadEvent(ChunkLoadEvent evt) {
if(getConfig().getBoolean("RemoveALLIllegalBlocksOnCHUNKLOAD")){
Chunk c = evt.getChunk();
if(!evt.isNewChunk()){
if(!c.getWorld().getName().equalsIgnoreCase("world_the_end")){
int cx = c.getX() << 4;
int cz = c.getZ() << 4;
for (int x = cx; x < cx + 16; x++) {
for (int z = cz; z < cz + 16; z++) {
for (int y = 0; y < 128; y++) {

if ((getConfig().getList("BANNED_BLOCKS").contains(c.getBlock(x, y, z).getType().toString()))) {
if(y > 5){
if(evt.getChunk().getWorld().getName().equalsIgnoreCase("world_nether")){
if(y < 123){
c.getBlock(x, y, z).setType(Material.AIR);
//System.out.println("Found bedrock at " + x + " " + y + " " + z);
}
}
if(evt.getChunk().getWorld().getName().equalsIgnoreCase("world")){
c.getBlock(x, y, z).setType(Material.AIR);
//System.out.println("Found bedrock at " + x + " " + y + " " + z);
}
}
}
}
}
}
}
}
}
}
@EventHandler
private void onInventoryInteractEvent(InventoryInteractEvent evt){
if(getConfig().getBoolean("DEBUG")){
System.out.println("InventoryInteractEvent ");
}
if(getConfig().getBoolean("RemoveIllegalBlocksOnInteract")){
ItemStack[] item = evt.getInventory().getContents();
getConfig().getList("BANNED_BLOCKS").forEach(b -> {
if(evt.getInventory().contains(Material.getMaterial((String) b))){
evt.getInventory().remove(Material.getMaterial((String) b));
evt.setCancelled(true);
}
});
}
}
@EventHandler
private void onInventoryClick(InventoryClickEvent evt){
if(getConfig().getBoolean("RemoveIllegalBlocksOnClick")){
if(evt.getCurrentItem() != null){
String item = evt.getCurrentItem().getType().toString();

if (getConfig().getList("BANNED_BLOCKS").contains(item)) {
if(getConfig().getBoolean("DEBUG")){
System.out.println("InventoryClickEvent " + item);
}
evt.getCurrentItem().setType(Material.getMaterial(getConfig().getString("Replacement_Item")));
evt.setCancelled(true);
}
}
}
}
@EventHandler
private void onInventoryPickup(InventoryPickupItemEvent evt){
if(getConfig().getBoolean("RemoveIllegalBlocksOnPickup")){
String item = evt.getItem().getType().toString();
if(getConfig().getBoolean("DEBUG")){
System.out.println("InventoryPickupItemEvent " + item);
}
if (getConfig().getList("BANNED_BLOCKS").contains(item)) {
evt.setCancelled(true);
}
}
}
@EventHandler
private void onInventoryMove(InventoryMoveItemEvent evt){
if(getConfig().getBoolean("RemoveIllegalBlocksOnMove")) {
String item = evt.getItem().getType().toString();
if (getConfig().getList("BANNED_BLOCKS").contains(item)) {
if(getConfig().getBoolean("DEBUG")){
System.out.println("InventoryMoveItemEvent " + item);
}
evt.getItem().setType(Material.getMaterial(getConfig().getString("Replacement_Item")));
evt.setCancelled(true);
}
}
}
@EventHandler
private void onBlockPlace(BlockPlaceEvent evt){
if(getConfig().getBoolean("1b1tPlaceBedrock")){
if(evt.getBlockPlaced().getType().toString().equalsIgnoreCase("BEDROCK")){
if(evt.getPlayer().getWorld().getName().equalsIgnoreCase("world_the_end")){
evt.setCancelled(true);
}
if(evt.getPlayer().getWorld().getName().equalsIgnoreCase("world")){
if(evt.getBlockPlaced().getY() < 10){
evt.setCancelled(true);
}
}
if(evt.getPlayer().getWorld().getName().equalsIgnoreCase("world_nether")){
if(evt.getBlockPlaced().getY() < 10 || evt.getBlockPlaced().getY() > 122){
evt.setCancelled(true);
}
}
}
}
if(getConfig().getBoolean("PreventPlacingIllegalBlocks")){
String block = evt.getBlockPlaced().getType().toString();
if (getConfig().getList("BANNED_BLOCKS").contains(block)) {
if(getConfig().getBoolean("RemoveIllegalBlockOnPlace")){
getConfig().getList("BANNED_BLOCKS").forEach(b -> {
if(evt.getPlayer().getInventory().contains(Material.getMaterial((String) b))){
evt.getPlayer().getInventory().remove(Material.getMaterial((String) b));
evt.setCancelled(true);
}
});
}
evt.setCancelled(true);
}
}
}
@EventHandler
private void onEntityTeleportEvent(EntityTeleportEvent evt) {
if(getConfig().getBoolean("PreventEndGatewayCrashExploit")){
if (evt.getEntity().getWorld().getName().equals("world_the_end") && !evt.getEntity().isEmpty()) {
evt.setCancelled(true);
if(!getConfig().getBoolean("NoConsoleOutput")) {
System.out.println("Prevented a entity " + "(" + evt.getEntity().getName() + ")" + " from going through end gateway at " + evt.getEntity().getLocation());
}
}
}
}
@EventHandler
private void onEntityInteract(PlayerInteractAtEntityEvent evt){
if(getConfig().getBoolean("DisableChestsOnDonkeys")){
if (evt.getRightClicked() instanceof ChestedHorse) {
evt.setCancelled(true);
(new BukkitRunnable() {
public void run() {
if (evt.getPlayer().getInventory().getItemInMainHand().getType() == Material.CHEST) {
((ChestedHorse) evt.getRightClicked()).setCarryingChest(false);
//evt.getRightClicked().getWorld().dropItemNaturally(evt.getRightClicked().getLocation(), new ItemStack(Material.CHEST));
}
((ChestedHorse) evt.getRightClicked()).setCarryingChest(false);
}
}).runTaskLater(this, 2L);
}
}
}
}
4 changes: 4 additions & 0 deletions plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name: AnarchyExploitFixes
version: 0.1
main: me.moomoo.anarchyexploitfixes.Main
description: Prevent many exploits that affect anarchy servers.

0 comments on commit 9a0f241

Please sign in to comment.