Fix join sign placing in 1.13+; resolves #501

This commit is contained in:
Daniel Saukel 2018-12-22 20:04:40 +01:00
parent 2828f27502
commit bc459caac1
4 changed files with 48 additions and 53 deletions

15
pom.xml
View File

@ -2,13 +2,16 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>de.erethon</groupId> <groupId>de.erethon</groupId>
<artifactId>dungeonsxl</artifactId> <artifactId>dungeonsxl</artifactId>
<version>0.17.4</version> <version>0.17.5-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>DungeonsXL</name> <name>DungeonsXL</name>
<url>https://dre2n.github.io</url> <url>https://dre2n.github.io</url>
<description>Create custom dungeons and adventure maps with ease!</description> <description>Create custom dungeons and adventure maps with ease!</description>
<properties> <properties>
<buildNo></buildNo> <buildNo></buildNo>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties> </properties>
<build> <build>
<finalName>${project.artifactId}-${project.version}${buildNo}</finalName> <finalName>${project.artifactId}-${project.version}${buildNo}</finalName>
@ -24,18 +27,10 @@
</resource> </resource>
</resources> </resources>
<plugins> <plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId> <artifactId>maven-shade-plugin</artifactId>
<version>3.1.1</version> <version>3.2.1</version>
<executions> <executions>
<execution> <execution>
<phase>package</phase> <phase>package</phase>

View File

@ -216,27 +216,10 @@ public class GameSign extends JoinSign {
return tryToCreate(plugin, event.getBlock(), identifier, maxGroupsPerGame, startIfElementsAtLeast); return tryToCreate(plugin, event.getBlock(), identifier, maxGroupsPerGame, startIfElementsAtLeast);
} }
public static GameSign tryToCreate(DungeonsXL plugin, Block startSign, String identifier, int maxGroupsPerGame, int startIfElementsAtLeast) { public static GameSign tryToCreate(DungeonsXL plugin, Block startSign, String identifier, int maxElements, int startIfElementsAtLeast) {
World world = startSign.getWorld(); onCreation(plugin, startSign, identifier, maxElements, startIfElementsAtLeast);
BlockFace facing = ((Attachable) startSign.getState().getData()).getAttachedFace().getOppositeFace(); GameSign sign = new GameSign(plugin, plugin.getGlobalProtectionCache().generateId(GameSign.class, startSign.getWorld()), startSign, identifier,
int x = startSign.getX(), y = startSign.getY(), z = startSign.getZ(); maxElements, startIfElementsAtLeast);
int verticalSigns = (int) Math.ceil((float) (1 + maxGroupsPerGame) / 4);
while (verticalSigns > 1) {
Block block = world.getBlockAt(x, y - verticalSigns + 1, z);
block.setType(VanillaItem.WALL_SIGN.getMaterial(), false);
org.bukkit.material.Sign signData = new org.bukkit.material.Sign(VanillaItem.WALL_SIGN.getMaterial());
signData.setFacingDirection(facing);
org.bukkit.block.Sign sign = (org.bukkit.block.Sign) block.getState();
sign.setData(signData);
sign.update(true, false);
verticalSigns--;
}
GameSign sign = new GameSign(plugin, plugin.getGlobalProtectionCache().generateId(GameSign.class, world), startSign, identifier, maxGroupsPerGame, startIfElementsAtLeast);
LWCUtil.removeProtection(startSign);
return sign; return sign;
} }

View File

@ -19,6 +19,7 @@ package de.erethon.dungeonsxl.global;
import de.erethon.caliburn.category.Category; import de.erethon.caliburn.category.Category;
import de.erethon.caliburn.item.VanillaItem; import de.erethon.caliburn.item.VanillaItem;
import de.erethon.commons.chat.MessageUtil; import de.erethon.commons.chat.MessageUtil;
import de.erethon.commons.compatibility.Version;
import de.erethon.commons.misc.NumberUtil; import de.erethon.commons.misc.NumberUtil;
import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.config.DMessage;
@ -27,7 +28,9 @@ import de.erethon.dungeonsxl.util.LWCUtil;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
import org.bukkit.block.data.Directional;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -212,28 +215,10 @@ public class GroupSign extends JoinSign {
return tryToCreate(plugin, event.getBlock(), identifier, maxPlayersPerGroup, startIfElementsAtLeast, groupName); return tryToCreate(plugin, event.getBlock(), identifier, maxPlayersPerGroup, startIfElementsAtLeast, groupName);
} }
public static GroupSign tryToCreate(DungeonsXL plugin, Block startSign, String identifier, int maxPlayersPerGroup, int startIfElementsAtLeast, String groupName) { public static GroupSign tryToCreate(DungeonsXL plugin, Block startSign, String identifier, int maxElements, int startIfElementsAtLeast, String groupName) {
World world = startSign.getWorld(); onCreation(plugin, startSign, identifier, maxElements, startIfElementsAtLeast);
BlockFace facing = ((Attachable) startSign.getState().getData()).getAttachedFace().getOppositeFace(); GroupSign sign = new GroupSign(plugin, plugin.getGlobalProtectionCache().generateId(GroupSign.class, startSign.getWorld()), startSign, identifier,
int x = startSign.getX(), y = startSign.getY(), z = startSign.getZ(); maxElements, startIfElementsAtLeast, groupName);
int verticalSigns = (int) Math.ceil((float) (1 + maxPlayersPerGroup) / 4);
while (verticalSigns > 1) {
Block block = world.getBlockAt(x, y - verticalSigns + 1, z);
block.setType(VanillaItem.WALL_SIGN.getMaterial(), false);
org.bukkit.material.Sign signData = new org.bukkit.material.Sign(VanillaItem.WALL_SIGN.getMaterial());
signData.setFacingDirection(facing);
org.bukkit.block.Sign sign = (org.bukkit.block.Sign) block.getState();
sign.setData(signData);
sign.update(true, false);
verticalSigns--;
}
GroupSign sign = new GroupSign(plugin, plugin.getGlobalProtectionCache().generateId(GroupSign.class, world), startSign, identifier, maxPlayersPerGroup,
startIfElementsAtLeast, groupName);
LWCUtil.removeProtection(startSign);
return sign; return sign;
} }

View File

@ -16,17 +16,22 @@
*/ */
package de.erethon.dungeonsxl.global; package de.erethon.dungeonsxl.global;
import de.erethon.caliburn.item.VanillaItem;
import de.erethon.commons.misc.BlockUtil; import de.erethon.commons.misc.BlockUtil;
import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.dungeon.Dungeon; import de.erethon.dungeonsxl.dungeon.Dungeon;
import de.erethon.dungeonsxl.util.LWCUtil;
import de.erethon.dungeonsxl.world.DResourceWorld; import de.erethon.dungeonsxl.world.DResourceWorld;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.material.Attachable;
/** /**
* @author Daniel Saukel * @author Daniel Saukel
@ -206,4 +211,31 @@ public class JoinSign extends GlobalProtection {
} }
} }
protected static void onCreation(DungeonsXL plugin, Block startSign, String identifier, int maxElements, int startIfElementsAtLeast) {
// TODO: Replace as soon as versions older than 1.13 are dropped
World world = startSign.getWorld();
BlockFace facing = ((Attachable) startSign.getState().getData()).getAttachedFace().getOppositeFace();
//BlockFace facing = ((Directional) startSign.getBlockData()).getFacing().getOppositeFace();
int x = startSign.getX(), y = startSign.getY(), z = startSign.getZ();
int verticalSigns = (int) Math.ceil((float) (1 + maxElements) / 4);
while (verticalSigns > 1) {
Block block = world.getBlockAt(x, y - verticalSigns + 1, z);
block.setType(VanillaItem.WALL_SIGN.getMaterial(), false);
BlockState state = block.getState();
org.bukkit.material.Sign signData = (org.bukkit.material.Sign) state.getData();
signData.setFacingDirection(facing);
state.setData(signData);
state.update(true, false);
// Directional directional = (Directional) block.getBlockData();
// directional.setFacing(facing);
// block.setBlockData(directional, false);
verticalSigns--;
}
LWCUtil.removeProtection(startSign);
}
} }