Special Signs Improvements

This commit is contained in:
Olof Larsson 2015-12-01 10:18:10 +01:00
parent 603db8079b
commit 4e6fdd9df4

View File

@ -3,7 +3,9 @@ package com.massivecraft.massivecore.util;
import java.security.InvalidParameterException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;
import org.bukkit.ChatColor;
import org.bukkit.Material;
@ -12,6 +14,7 @@ import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.player.PlayerInteractEvent;
@ -201,17 +204,35 @@ public class SignUtil
return lines;
}
protected final static Set<Action> VALID_INTERACT_ACTIONS = EnumSet.of(
// Action.LEFT_CLICK_BLOCK, // We must allow breaking the sign.
Action.RIGHT_CLICK_BLOCK
);
public static List<String> getSpecialPillarLines(PlayerInteractEvent event, String title)
{
// Arguments
if (event == null) throw new NullPointerException("event");
if (title == null) throw new NullPointerException("title");
// Player
final Player player = event.getPlayer();
if (MUtil.isntPlayer(player)) return null;
// Action
if ( ! VALID_INTERACT_ACTIONS.contains(event.getAction())) return null;
// Block
Block block = event.getClickedBlock();
if (block == null) return null;
// Lines
List<String> lines = getSpecialPillarLines(block, title);
if (lines == null) return null;
// Cancel
event.setCancelled(true);
// Return
return lines;
}
@ -287,5 +308,4 @@ public class SignUtil
return new ArrayList<String>(Arrays.asList(sign.getLines()));
}
}