Hotfix: Fixed variables in messages.
This commit is contained in:
parent
7e5072ef3e
commit
0a57539d50
2 changed files with 46 additions and 4 deletions
|
@ -5,6 +5,7 @@ import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
|
@ -55,6 +56,11 @@ public class ConfigUtil {
|
||||||
throw new NullPointerException("Message " + path + " not found in messages.yml!");
|
throw new NullPointerException("Message " + path + " not found in messages.yml!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Map<String, String> fixedMap = new HashMap<>();
|
||||||
|
for (Map.Entry<String, String> ent : replacement.entrySet()) {
|
||||||
|
fixedMap.put(ent.getKey().replaceAll("%", ""), ent.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
String[] messages = fileMessage.split("\n");
|
String[] messages = fileMessage.split("\n");
|
||||||
for (String message : messages) {
|
for (String message : messages) {
|
||||||
Pattern pattern = Pattern.compile("%(.*?)%");
|
Pattern pattern = Pattern.compile("%(.*?)%");
|
||||||
|
@ -62,7 +68,7 @@ public class ConfigUtil {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (matcher.find()) {
|
while (matcher.find()) {
|
||||||
String repl = replacement.get(matcher.group(1));
|
String repl = fixedMap.get(matcher.group(1));
|
||||||
builder.append(message, i, matcher.start());
|
builder.append(message, i, matcher.start());
|
||||||
if (repl == null)
|
if (repl == null)
|
||||||
builder.append(matcher.group(0));
|
builder.append(matcher.group(0));
|
||||||
|
|
|
@ -7,14 +7,20 @@ import org.bukkit.block.data.Bisected;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
/* Openable codes sponsored by MrWouter <3 */
|
||||||
public class DoorUtil {
|
public class DoorUtil {
|
||||||
|
|
||||||
/* Gate codes sponsored by MrWouter <3 */
|
/**
|
||||||
|
* Open a door, with 1.12.x < and 1.13.x > support
|
||||||
|
* @param b The block (door)
|
||||||
|
* @return true if opened, false if not opened
|
||||||
|
*/
|
||||||
public static boolean openDoor(@Nonnull Block b) {
|
public static boolean openDoor(@Nonnull Block b) {
|
||||||
if (b.getType() == XMaterial.IRON_DOOR.parseMaterial()) XSound.BLOCK_IRON_DOOR_OPEN.playSound(b.getLocation());
|
if (b.getType() == XMaterial.IRON_DOOR.parseMaterial()) XSound.BLOCK_IRON_DOOR_OPEN.playSound(b.getLocation());
|
||||||
if (b.getType().toString().contains("DOOR") && b.getType() != XMaterial.IRON_DOOR.parseMaterial()) XSound.BLOCK_WOODEN_DOOR_OPEN.playSound(b.getLocation());
|
if (b.getType().toString().contains("DOOR") && b.getType() != XMaterial.IRON_DOOR.parseMaterial()) XSound.BLOCK_WOODEN_DOOR_OPEN.playSound(b.getLocation());
|
||||||
if (b.getType().toString().contains("GATE")) XSound.BLOCK_FENCE_GATE_OPEN.playSound(b.getLocation());
|
if (b.getType().toString().contains("GATE")) XSound.BLOCK_FENCE_GATE_OPEN.playSound(b.getLocation());
|
||||||
if (XMaterial.isNewVersion()) {
|
if (XMaterial.isNewVersion()) {
|
||||||
|
//1.13+
|
||||||
org.bukkit.block.data.BlockData blockData = b.getBlockData();
|
org.bukkit.block.data.BlockData blockData = b.getBlockData();
|
||||||
if (isOpenable(b)) {
|
if (isOpenable(b)) {
|
||||||
org.bukkit.block.data.Openable op = (org.bukkit.block.data.Openable) blockData;
|
org.bukkit.block.data.Openable op = (org.bukkit.block.data.Openable) blockData;
|
||||||
|
@ -26,6 +32,7 @@ public class DoorUtil {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
//1.12-
|
||||||
BlockState state = b.getState();
|
BlockState state = b.getState();
|
||||||
if (isOpenable(b)) {
|
if (isOpenable(b)) {
|
||||||
org.bukkit.material.Openable openable = (org.bukkit.material.Openable) state.getData();
|
org.bukkit.material.Openable openable = (org.bukkit.material.Openable) state.getData();
|
||||||
|
@ -41,12 +48,17 @@ public class DoorUtil {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Gate codes sponsored by MrWouter <3 */
|
/**
|
||||||
|
* Close a door, with 1.12.x < and 1.13.x > support
|
||||||
|
* @param b The block (door)
|
||||||
|
* @return true if opened, false if not opened
|
||||||
|
*/
|
||||||
public static boolean closeDoor(@Nonnull Block b) {
|
public static boolean closeDoor(@Nonnull Block b) {
|
||||||
if (b.getType() == XMaterial.IRON_DOOR.parseMaterial()) XSound.BLOCK_IRON_DOOR_CLOSE.playSound(b.getLocation());
|
if (b.getType() == XMaterial.IRON_DOOR.parseMaterial()) XSound.BLOCK_IRON_DOOR_CLOSE.playSound(b.getLocation());
|
||||||
if (b.getType().toString().contains("DOOR") && b.getType() != XMaterial.IRON_DOOR.parseMaterial()) XSound.BLOCK_WOODEN_DOOR_CLOSE.playSound(b.getLocation());
|
if (b.getType().toString().contains("DOOR") && b.getType() != XMaterial.IRON_DOOR.parseMaterial()) XSound.BLOCK_WOODEN_DOOR_CLOSE.playSound(b.getLocation());
|
||||||
if (b.getType().toString().contains("GATE")) XSound.BLOCK_FENCE_GATE_CLOSE.playSound(b.getLocation());
|
if (b.getType().toString().contains("GATE")) XSound.BLOCK_FENCE_GATE_CLOSE.playSound(b.getLocation());
|
||||||
if (XMaterial.isNewVersion()) {
|
if (XMaterial.isNewVersion()) {
|
||||||
|
//1.13+
|
||||||
org.bukkit.block.data.BlockData blockData = b.getBlockData();
|
org.bukkit.block.data.BlockData blockData = b.getBlockData();
|
||||||
if (isOpenable(b)) {
|
if (isOpenable(b)) {
|
||||||
org.bukkit.block.data.Openable op = (org.bukkit.block.data.Openable) blockData;
|
org.bukkit.block.data.Openable op = (org.bukkit.block.data.Openable) blockData;
|
||||||
|
@ -58,6 +70,7 @@ public class DoorUtil {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
//1.12-
|
||||||
BlockState state = b.getState();
|
BlockState state = b.getState();
|
||||||
if (isOpenable(b)) {
|
if (isOpenable(b)) {
|
||||||
org.bukkit.material.Openable openable = (org.bukkit.material.Openable) state.getData();
|
org.bukkit.material.Openable openable = (org.bukkit.material.Openable) state.getData();
|
||||||
|
@ -73,22 +86,36 @@ public class DoorUtil {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Gate codes sponsored by MrWouter <3 */
|
/**
|
||||||
|
* Check if a block instanceof Openable
|
||||||
|
*
|
||||||
|
* @param b The block
|
||||||
|
* @return true if Openable, false if not
|
||||||
|
*/
|
||||||
public static boolean isOpenable(Block b) {
|
public static boolean isOpenable(Block b) {
|
||||||
if (b == null) {
|
if (b == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (XMaterial.isNewVersion()) {
|
if (XMaterial.isNewVersion()) {
|
||||||
|
//1.13+
|
||||||
return b.getBlockData() instanceof org.bukkit.block.data.Openable;
|
return b.getBlockData() instanceof org.bukkit.block.data.Openable;
|
||||||
} else {
|
} else {
|
||||||
|
//1.12-
|
||||||
return b.getState().getData() instanceof org.bukkit.material.Openable;
|
return b.getState().getData() instanceof org.bukkit.material.Openable;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the lower location of a door
|
||||||
|
*
|
||||||
|
* @param block The location of a door
|
||||||
|
* @return The lower location of a door
|
||||||
|
*/
|
||||||
public static Location getLowerLocationOfDoor(@Nonnull Block block) {
|
public static Location getLowerLocationOfDoor(@Nonnull Block block) {
|
||||||
if (!isDoor(block)) return block.getLocation();
|
if (!isDoor(block)) return block.getLocation();
|
||||||
|
|
||||||
if (XMaterial.isNewVersion()) {
|
if (XMaterial.isNewVersion()) {
|
||||||
|
//1.13+
|
||||||
org.bukkit.block.data.type.Door door = (org.bukkit.block.data.type.Door) block.getBlockData();
|
org.bukkit.block.data.type.Door door = (org.bukkit.block.data.type.Door) block.getBlockData();
|
||||||
Location lower;
|
Location lower;
|
||||||
if (door.getHalf() == Bisected.Half.TOP) {
|
if (door.getHalf() == Bisected.Half.TOP) {
|
||||||
|
@ -104,6 +131,7 @@ public class DoorUtil {
|
||||||
}
|
}
|
||||||
return lower;
|
return lower;
|
||||||
} else {
|
} else {
|
||||||
|
//1.12-
|
||||||
org.bukkit.material.Door door = (org.bukkit.material.Door) block.getState().getData();
|
org.bukkit.material.Door door = (org.bukkit.material.Door) block.getState().getData();
|
||||||
Location lower;
|
Location lower;
|
||||||
if (door.isTopHalf()) {
|
if (door.isTopHalf()) {
|
||||||
|
@ -121,13 +149,21 @@ public class DoorUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a block instanceof Door
|
||||||
|
*
|
||||||
|
* @param b The block
|
||||||
|
* @return true if a Door, false if not
|
||||||
|
*/
|
||||||
public static boolean isDoor(Block b) {
|
public static boolean isDoor(Block b) {
|
||||||
if (b == null) {
|
if (b == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (XMaterial.isNewVersion()) {
|
if (XMaterial.isNewVersion()) {
|
||||||
|
//1.13+
|
||||||
return b.getBlockData() instanceof org.bukkit.block.data.type.Door;
|
return b.getBlockData() instanceof org.bukkit.block.data.type.Door;
|
||||||
} else {
|
} else {
|
||||||
|
//1.12-
|
||||||
return b.getState().getData() instanceof org.bukkit.material.Door;
|
return b.getState().getData() instanceof org.bukkit.material.Door;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue