Skip to content

Commit

Permalink
v1.0 - CometALS
Browse files Browse the repository at this point in the history
Stop ArmorStands with Long & Laggy Names
  • Loading branch information
BuildTools committed Feb 27, 2021
0 parents commit a09f895
Show file tree
Hide file tree
Showing 9 changed files with 451 additions and 0 deletions.
113 changes: 113 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# User-specific stuff
.idea/

*.iml
*.ipr
*.iws

# IntelliJ
out/

# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*

# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db

# Dump file
*.stackdump

# Folder config file
[Dd]esktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp

# Windows shortcuts
*.lnk

target/

pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next

release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
.mvn/wrapper/maven-wrapper.jar
.flattened-pom.xml

# Common working directory
run/
104 changes: 104 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>net.ddns.xHue</groupId>
<artifactId>CometALS</artifactId>
<version>1.0</version>
<packaging>jar</packaging>

<name>CometALS</name>

<description>Stop ArmorStands with Long, Laggy Names</description>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<url>xHue.ddns.net</url>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<relocations>
<relocation>
<pattern>org.bstats</pattern>
<!-- Replace this with your package! -->
<shadedPattern>net.ddns.xhue.cometals</shadedPattern>
</relocation>
</relocations>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>

<repositories>
<repository>
<id>spigotmc-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>2.2.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.16.5-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
53 changes: 53 additions & 0 deletions src/main/java/net/ddns/xhue/cometals/ALSConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package net.ddns.xhue.cometals;

import com.google.common.base.Enums;
import com.google.common.base.Optional;

import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.logging.Logger;

public class ALSConfig {

private final Logger logger;
private FileConfiguration config;
private final JavaPlugin plugin;

/**
* Creates a Plugin config for this plugin.
*
* @param plugin
* enter <i>this</i> from your main class.
*/
public ALSConfig(final JavaPlugin plugin) {
this.plugin = plugin;
this.config = plugin.getConfig();
this.logger = plugin.getLogger();

reloadConfig();
}

/**
* Force reload the config.
*/
public void reloadConfig() {
plugin.reloadConfig();
this.config = plugin.getConfig();


}

public Logger getLogger() {
return logger;
}

public FileConfiguration getConfig() {
return config;
}

public JavaPlugin getPlugin() {
return plugin;
}
}
12 changes: 12 additions & 0 deletions src/main/java/net/ddns/xhue/cometals/ArmorStandData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package net.ddns.xhue.cometals;

public class ArmorStandData {

private Object EntityTag;

public Object getEntityTag() {
return EntityTag;
}


}
33 changes: 33 additions & 0 deletions src/main/java/net/ddns/xhue/cometals/CometALS.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package net.ddns.xhue.cometals;

import net.ddns.xhue.cometals.Utils.ColorUtils;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;

public final class CometALS extends JavaPlugin {


ColorUtils cu = new ColorUtils();
String prefix = cu.translateAll(getConfig().getString("prefix"));

@Override
public void onEnable() {

int pluginId = 10495;
Metrics metrics = new Metrics(this, pluginId);

Bukkit.getLogger().info(prefix + " " + cu.translateAll("&cCometALS has been &aenabled&c."));

ALSConfig config = new ALSConfig(this);

Bukkit.getPluginManager().registerEvents(new ExploitListener(config), this);
}

@Override
public void onDisable() {
Bukkit.getLogger().info(prefix + " " + cu.translateAll("&cCometALS has been #FF0000:disabled&c."));

// Plugin shutdown logic
}
}
74 changes: 74 additions & 0 deletions src/main/java/net/ddns/xhue/cometals/ExploitListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package net.ddns.xhue.cometals;

import com.google.gson.Gson;
import net.ddns.xhue.cometals.Utils.ColorUtils;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class ExploitListener implements Listener {

private ALSConfig config;

public ExploitListener(ALSConfig config) {
this.config = config;
}

ColorUtils cu = new ColorUtils();

@EventHandler
public void onInteract(PlayerInteractEvent e) throws NoSuchMethodException, SecurityException {

String prefix = cu.translateAll(config.getConfig().getString("prefix"));
String deniedMessage = cu.translateAll(config.getConfig().getString("deniedMessage"));


if (e.getItem() != null) {
if (e.getItem().getType() == Material.ARMOR_STAND) {
if (e.getPlayer().hasPermission(config.getConfig().getString("permission"))) {
return;
}
ItemStack i = e.getItem();
Method m = getMethod(i, "asNMSCopy", org.bukkit.inventory.ItemStack.class);
Object nmsCopy = invokeMethod(i, m, i);
Method gettag = getMethod(nmsCopy, "getTag");
Object x = invokeMethod(nmsCopy, gettag);
if (x == null)
return;
ArmorStandData data = new Gson().fromJson(x.toString(), ArmorStandData.class);
if (data.getEntityTag() != null) {
e.setCancelled(true);
e.getPlayer().sendMessage(prefix + " " + deniedMessage);
return;
}
}
}
}

public Method getMethod(Object o, String name, Class<?>... objects) {
Method m;
try {
m = o.getClass().getMethod(name, objects);
return m;
} catch (NoSuchMethodException | SecurityException e1) {
e1.printStackTrace();
}
return null;
}

public Object invokeMethod(Object o, Method m, Object... args) {
try {
return m.invoke(o, args);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
e.printStackTrace();
return null;
}
}

}

Loading

0 comments on commit a09f895

Please sign in to comment.