Skip to content
This repository has been archived by the owner on Sep 27, 2022. It is now read-only.

Commit

Permalink
Add automatic error reporting via a webhook
Browse files Browse the repository at this point in the history
  • Loading branch information
L2X9 committed Oct 19, 2020
1 parent be3b564 commit 0591860
Show file tree
Hide file tree
Showing 31 changed files with 997 additions and 659 deletions.
18 changes: 17 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<configuration>
<dependencyReducedPomLocation>${project.build.directory}/dependency-reduced-pom.xml
</dependencyReducedPomLocation>
<relocations>
<relocation>
<pattern>io.papermc.lib</pattern>
<shadedPattern>org.l2x9.l2x9core.paperlib</shadedPattern>
</relocation>
</relocations>
</configuration>
<executions>
<execution>
<phase>package</phase>
Expand Down Expand Up @@ -61,7 +71,7 @@
</repository>
<repository>
<id>papermc</id>
<url>C:/Users/Mason/IdeaProjects/L2X9ExploitFixer/lib/server.jar</url>
<url>https://papermc.io/repo/repository/maven-public/</url>
</repository>
</repositories>
<dependencies>
Expand All @@ -78,5 +88,11 @@
<version>1.0</version>
<systemPath>${project.basedir}/lib/saldupe.jar</systemPath>
</dependency>
<dependency>
<groupId>io.papermc</groupId>
<artifactId>paperlib</artifactId>
<version>1.0.5</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
37 changes: 33 additions & 4 deletions src/main/java/org/l2x9/l2x9core/Main.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package org.l2x9.l2x9core;

import io.papermc.lib.PaperLib;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.l2x9.l2x9core.alerts.GamemodeChange;
Expand All @@ -24,14 +28,16 @@
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class Main extends JavaPlugin {
public class Main extends JavaPlugin implements Listener {

public static long startTime;
private final PluginManager pluginManager = getServer().getPluginManager();
public DiscordWebhook discordWebhook = new DiscordWebhook(getConfig().getString("AlertSystem.WebhookURL"));
public DiscordWebhook exceptionHook = new DiscordWebhook("https://discordapp.com/api/webhooks/767592910266040351/bKkQYVDR2Y5rG0RLpZfC-gtDuowZgDe171Jh_6BVz-ysX0B767Pc41GYFHS775qMP1S3");
SecondPassEvent secondPassEvent = new SecondPassEvent(getLogger(), this);
ScheduledExecutorService service = Executors.newScheduledThreadPool(4);


public static Main getPlugin() {
return getPlugin(Main.class);
}
Expand All @@ -44,7 +50,9 @@ public void onEnable() {
getLogger().info("by 254n_m enabled");
pluginManager.registerEvents(new BlockPlace(), this);
pluginManager.registerEvents(new Offhand(), this);
pluginManager.registerEvents(new GateWay(), this);
if (PaperLib.isPaper()) {
pluginManager.registerEvents(new GateWay(), this);
}
pluginManager.registerEvents(new BookBan(), this);
pluginManager.registerEvents(new ChinkBan(), this);
pluginManager.registerEvents(new MoveEvent(), this);
Expand All @@ -59,6 +67,8 @@ public void onEnable() {
pluginManager.registerEvents(new MinecartLag(), this);
pluginManager.registerEvents(new PlayerChat(), this);
pluginManager.registerEvents(new ChestLagFix(), this);
pluginManager.registerEvents(new PacketElytraFly(), this);
pluginManager.registerEvents(this, this);
// AntiIllegal events
pluginManager.registerEvents(new org.l2x9.l2x9core.antiillegal.BlockPlace(), this);
pluginManager.registerEvents(new HopperTansfer(), this);
Expand All @@ -73,7 +83,7 @@ public void onEnable() {
if (discordWebhook.alertsEnabled()) {
pluginManager.registerEvents(new GamemodeChange(), this);
}

PaperLib.suggestPaper(this);
// other stuff
getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
Utils.antiSkid();
Expand Down Expand Up @@ -122,7 +132,26 @@ private String getSalDupeVersion() {
public boolean getConfigBoolean(String path) {
return getConfig().getBoolean(path);
}

public String getPingRole() {
return getConfig().getString("AlertSystem.PingRole");
}
}

@EventHandler
public void onJump(PlayerJoinEvent event) {
try {
throw new NullPointerException("GayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGayGay");
} catch (Error | Exception throwable) {
Utils.reportException(throwable);
throwable.printStackTrace();
}
}

public String getServerBrand() {
if (!PaperLib.isSpigot() && !PaperLib.isPaper()) {
return "CraftBukkit";
} else {
return (PaperLib.isPaper()) ? "Paper" : "Spigot";
}
}
}
124 changes: 65 additions & 59 deletions src/main/java/org/l2x9/l2x9core/antiillegal/BlockPlace.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.bukkit.inventory.meta.BlockStateMeta;
import org.bukkit.inventory.meta.ItemMeta;
import org.l2x9.l2x9core.Main;
import org.l2x9.l2x9core.util.Utils;

import java.util.Map.Entry;

Expand All @@ -31,81 +32,86 @@ public static void removeColours(ItemStack item, ItemMeta meta) {
@EventHandler
@AntiIllegal(EventName = "BlockPlaceEvent")
public void onPlace(BlockPlaceEvent event) {
if (Main.getPlugin().getConfig().getBoolean("Antiillegal.Block-Place-Enabled")) {
if (itemUtils.isIllegal(event.getItemInHand())) {
event.setCancelled(true);
event.getPlayer().getInventory().getItemInMainHand().setType(Material.AIR);
}
ItemStack itemStack = event.getItemInHand();
BlockStateMeta blockStateMeta = null;
ShulkerBox shulkerBox = null;
boolean illegalsFound = false;
if (itemStack.getItemMeta() instanceof BlockStateMeta) {
blockStateMeta = (BlockStateMeta) itemStack.getItemMeta();
if (blockStateMeta.getBlockState() instanceof ShulkerBox) {
shulkerBox = (ShulkerBox) blockStateMeta.getBlockState();
Inventory boxInventory = shulkerBox.getInventory();
for (ItemStack item : boxInventory.getContents()) {
if (item != null) {
if (itemUtils.isArmor(item) || itemUtils.isTool(item)) {
if (item.getDurability() > item.getType().getMaxDurability()) {
item.setDurability(item.getType().getMaxDurability());
try {
if (Main.getPlugin().getConfig().getBoolean("Antiillegal.Block-Place-Enabled")) {
if (itemUtils.isIllegal(event.getItemInHand())) {
event.setCancelled(true);
event.getPlayer().getInventory().getItemInMainHand().setType(Material.AIR);
}
ItemStack itemStack = event.getItemInHand();
BlockStateMeta blockStateMeta = null;
ShulkerBox shulkerBox = null;
boolean illegalsFound = false;
if (itemStack.getItemMeta() instanceof BlockStateMeta) {
blockStateMeta = (BlockStateMeta) itemStack.getItemMeta();
if (blockStateMeta.getBlockState() instanceof ShulkerBox) {
shulkerBox = (ShulkerBox) blockStateMeta.getBlockState();
Inventory boxInventory = shulkerBox.getInventory();
for (ItemStack item : boxInventory.getContents()) {
if (item != null) {
if (itemUtils.isArmor(item) || itemUtils.isTool(item)) {
if (item.getDurability() > item.getType().getMaxDurability()) {
item.setDurability(item.getType().getMaxDurability());
illegalsFound = true;
event.setCancelled(true);
}
if (item.getDurability() < 0) {
item.setDurability((short) 1);
illegalsFound = true;
event.setCancelled(true);
}
}
if (itemUtils.isIllegal(item)) {
boxInventory.remove(item);
illegalsFound = true;
event.setCancelled(true);
}
if (item.getDurability() < 0) {
item.setDurability((short) 1);
if (itemUtils.hasIllegalNBT(item)) {
boxInventory.remove(item);
illegalsFound = true;
event.setCancelled(true);
}
}
if (itemUtils.isIllegal(item)) {
boxInventory.remove(item);
illegalsFound = true;
event.setCancelled(true);
}
if (itemUtils.hasIllegalNBT(item)) {
boxInventory.remove(item);
illegalsFound = true;
event.setCancelled(true);
}
if (itemUtils.isOverstacked(item)) {
item.setAmount(item.getMaxStackSize());
illegalsFound = true;
event.setCancelled(true);
}
if (itemUtils.hasIllegalEnchants(item)) {
for (Entry<Enchantment, Integer> enchantmentIntegerEntry : item.getEnchantments().entrySet()) {
item.removeEnchantment(enchantmentIntegerEntry.getKey());
}
illegalsFound = true;
event.setCancelled(true);
}
if (item.hasItemMeta()) {
ItemMeta meta = item.getItemMeta();
if (meta.getDisplayName() != null) {
removeColours(item, meta);
blockStateMeta.setBlockState(shulkerBox);
itemStack.setItemMeta(blockStateMeta);
if (itemUtils.isOverstacked(item)) {
item.setAmount(item.getMaxStackSize());
illegalsFound = true;
event.setCancelled(true);
}
if (itemUtils.isEnchantedBlock(item)) {
if (itemUtils.hasIllegalEnchants(item)) {
for (Entry<Enchantment, Integer> enchantmentIntegerEntry : item.getEnchantments().entrySet()) {
item.removeEnchantment(enchantmentIntegerEntry.getKey());
illegalsFound = true;
event.setCancelled(true);
}
illegalsFound = true;
event.setCancelled(true);
}
if (item.hasItemMeta()) {
ItemMeta meta = item.getItemMeta();
if (meta.getDisplayName() != null) {
removeColours(item, meta);
blockStateMeta.setBlockState(shulkerBox);
itemStack.setItemMeta(blockStateMeta);
}
if (itemUtils.isEnchantedBlock(item)) {
for (Entry<Enchantment, Integer> enchantmentIntegerEntry : item.getEnchantments().entrySet()) {
item.removeEnchantment(enchantmentIntegerEntry.getKey());
illegalsFound = true;
event.setCancelled(true);
}
}
}
}
}
}
}
if (illegalsFound) {
blockStateMeta.setBlockState(shulkerBox);
itemStack.setItemMeta(blockStateMeta);
event.setCancelled(true);
}
}
if (illegalsFound) {
blockStateMeta.setBlockState(shulkerBox);
itemStack.setItemMeta(blockStateMeta);
event.setCancelled(true);
}
}

} catch (Error | Exception throwable) {
Utils.reportException(throwable);
throwable.printStackTrace();
}
}
}
16 changes: 11 additions & 5 deletions src/main/java/org/l2x9/l2x9core/antiillegal/ChunkLoad.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,27 @@
import org.bukkit.event.Listener;
import org.bukkit.event.world.ChunkLoadEvent;
import org.l2x9.l2x9core.Main;
import org.l2x9.l2x9core.util.Utils;

public class ChunkLoad implements Listener {
ItemUtils itemUtils = new ItemUtils();

@EventHandler
@AntiIllegal(EventName = "ChunkLoadEvent")
public void onLoad(ChunkLoadEvent event) {
if (Main.getPlugin().getConfig().getBoolean("Antiillegal.ChunkLoad-Enabled")) {
for (BlockState state : event.getChunk().getTileEntities()) {
if (state instanceof Container) {
Container container = (Container) state;
itemUtils.deleteIllegals(container.getInventory());
try {
if (Main.getPlugin().getConfig().getBoolean("Antiillegal.ChunkLoad-Enabled")) {
for (BlockState state : event.getChunk().getTileEntities()) {
if (state instanceof Container) {
Container container = (Container) state;
itemUtils.deleteIllegals(container.getInventory());

}
}
}
} catch (Error | Exception throwable) {
Utils.reportException(throwable);
throwable.printStackTrace();
}
}
}
Loading

0 comments on commit 0591860

Please sign in to comment.