Skip to content

Commit

Permalink
consider glow item frames to be item frames
Browse files Browse the repository at this point in the history
  • Loading branch information
crashdemons committed Jan 30, 2022
1 parent 37c78fd commit 2b65cd8
Show file tree
Hide file tree
Showing 3 changed files with 250 additions and 3 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.github.crashdemons</groupId>
<artifactId>WGItemFrameBreakFlags</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>0.0.3-SNAPSHOT</version>
<packaging>jar</packaging>

<name>WGItemFrameBreakFlags</name>
Expand Down Expand Up @@ -45,7 +45,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.17-R0.1-SNAPSHOT</version>
<version>1.18.1-R0.1-SNAPSHOT</version>
<!--
<exclusions>
<exclusion>
Expand Down
238 changes: 238 additions & 0 deletions pom.xml.versionsBackup
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.github.crashdemons</groupId>
<artifactId>WGItemFrameBreakFlags</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>WGItemFrameBreakFlags</name>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<repositories>
<repository>
<id>mojang</id>
<name>Mojang's Repository</name>
<url>https://libraries.minecraft.net/</url>
</repository>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>md_5-releases</id>
<url>http://repo.md-5.net/content/repositories/releases/</url>
</repository>
<repository>
<id>spigot-group-repo</id>
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
</repository>
<repository>
<id>crashdemons-repo</id>
<url>https://meme.tips/java-repos/</url>
</repository>
<repository>
<id>sk89q-repo</id>
<url>http://maven.sk89q.com/repo/</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.17-R0.1-SNAPSHOT</version>
<!--
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
-->
</dependency>
<dependency>
<groupId>com.sk89q.worldguard</groupId>
<artifactId>worldguard-bukkit</artifactId>
<version>7.0.5</version>
<exclusions>
<exclusion>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
</exclusion>
<exclusion>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
</exclusion>
</exclusions>
</dependency>


<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations-java5</artifactId>
<version>15.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<type>jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>2.0.7</version>
<type>jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>2.0.7</version>
<type>jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>3.5.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito-common</artifactId>
<version>1.7.4</version>
<scope>test</scope>
</dependency>
</dependencies>



<build>
<finalName>${project.name}-${project.version}</finalName>
<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<useIncrementalCompilation>true</useIncrementalCompilation>
<excludes>
<exclude>**/package-info.java</exclude>
</excludes>
<testExcludes>
<exclude>**/package-info.java</exclude>
</testExcludes>
<compilerArgs>
<arg>-Xlint:all</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<archive>
<manifestEntries>
<Built-By>Maven</Built-By>
<Implementation-Title>${project.name}</Implementation-Title>
<Implementation-Version>${project.version}</Implementation-Version>
<Implementation-Vendor-Id>${project.groupId}</Implementation-Vendor-Id>
<Implementation-Vendor>${project.organization.name}</Implementation-Vendor>
</manifestEntries>
</archive>
</configuration>
</plugin>


<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<includes>
<include>org.bukkit</include>
<include>org.spigotmc</include>
</includes>
</configuration>
<executions>
<execution>
<id>versions</id>
<phase>validate</phase>
<configuration>
<allowSnapshots>true</allowSnapshots>
</configuration>
<goals>
<goal>use-latest-versions</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>package</phase>
<configuration>
<target>
<copy file="${project.build.directory}/${project.build.finalName}.${project.packaging}"
tofile="${project.build.directory}/${project.name}.${project.packaging}"/>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<versionRange>[2.2,)</versionRange>
<goals>
<goal>use-latest-versions</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore/>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>

</build>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ public class WGItemFrameBreakFlagsPlugin extends JavaPlugin implements Listener
WorldGuard wg = null;

private static final String SUFFIX_DESTROY = "-destroy";
private static final EntityType[] SUPPORTED_HANGING_ENTITIES = new EntityType[]{EntityType.ITEM_FRAME,EntityType.PAINTING};
private static final EntityType[] SUPPORTED_HANGING_ENTITIES = new EntityType[]{
EntityType.ITEM_FRAME,EntityType.PAINTING, EntityType.GLOW_ITEM_FRAME
};

private static final HashMap<HangingBreakEvent.RemoveCause,HashMap<EntityType,StateFlag>> causeFlagMap = new HashMap<>();
private static final ArrayList<StateFlag> flags = new ArrayList<>();
Expand All @@ -52,6 +54,7 @@ public class WGItemFrameBreakFlagsPlugin extends JavaPlugin implements Listener
if(cause==HangingBreakEvent.RemoveCause.ENTITY) continue;//entity-item-frame-destroy already handled by WorldGuard.
HashMap<EntityType,StateFlag> entityMap = new HashMap<>();
for(EntityType hangingType : SUPPORTED_HANGING_ENTITIES){
if(hangingType==EntityType.GLOW_ITEM_FRAME) continue;
String flagName = getFlagName(cause,hangingType);
StateFlag flag = new StateFlag(flagName,true);
entityMap.put(hangingType, flag);
Expand All @@ -65,13 +68,15 @@ private static String getCauseName(HangingBreakEvent.RemoveCause cause){
return cause.name().toLowerCase().replace("_", "-");
}
private static String getEntityName(EntityType hangingType){
if(hangingType==EntityType.GLOW_ITEM_FRAME) hangingType = EntityType.ITEM_FRAME;
return hangingType.name().toLowerCase().replace("_", "-");
}
private static String getFlagName(HangingBreakEvent.RemoveCause cause, EntityType hangingType){
return getCauseName(cause)+"-"+getEntityName(hangingType)+SUFFIX_DESTROY;
}

private static StateFlag getRelevantFlag(HangingBreakEvent.RemoveCause cause, EntityType hangingType){
if(hangingType==EntityType.GLOW_ITEM_FRAME) hangingType = EntityType.ITEM_FRAME;
HashMap<EntityType,StateFlag> entityFlagMap = causeFlagMap.get(cause);
if(entityFlagMap==null) return null;
return entityFlagMap.get(hangingType);
Expand Down Expand Up @@ -182,6 +187,10 @@ public void onHangingBreak(HangingBreakEvent event) {
LocalPlayer wgPlayer = causePlayer==null? null : getWorldGuardPlugin().wrapPlayer(causePlayer);

StateFlag flag = getRelevantFlag(cause,hangingEntity.getType());
if(flag==null){
this.getLogger().warning("Unknown HangingBreakEvent combination: "+cause.name()+" "+hangingEntity.getType().name());
return;
}

com.sk89q.worldedit.util.Location wgLoc = BukkitAdapter.adapt(loc);
RegionQuery query = getWorldGuard().getPlatform().getRegionContainer().createQuery();
Expand Down

0 comments on commit 2b65cd8

Please sign in to comment.