Special Signs Improvements
This commit is contained in:
parent
603db8079b
commit
4e6fdd9df4
@ -3,7 +3,9 @@ package com.massivecraft.massivecore.util;
|
|||||||
import java.security.InvalidParameterException;
|
import java.security.InvalidParameterException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.EnumSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -12,6 +14,7 @@ import org.bukkit.block.Block;
|
|||||||
import org.bukkit.block.BlockState;
|
import org.bukkit.block.BlockState;
|
||||||
import org.bukkit.block.Sign;
|
import org.bukkit.block.Sign;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.block.Action;
|
||||||
import org.bukkit.event.block.SignChangeEvent;
|
import org.bukkit.event.block.SignChangeEvent;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
|
||||||
@ -121,10 +124,10 @@ public class SignUtil
|
|||||||
if (lenientTitle == null) return false;
|
if (lenientTitle == null) return false;
|
||||||
|
|
||||||
// ... of the type we seek ...
|
// ... of the type we seek ...
|
||||||
if (!title.equalsIgnoreCase(lenientTitle)) return false;
|
if ( ! title.equalsIgnoreCase(lenientTitle)) return false;
|
||||||
|
|
||||||
// ... verify that the player has permission to create that type of sign ...
|
// ... verify that the player has permission to create that type of sign ...
|
||||||
if (!PermUtil.has(player, permissionNode, true))
|
if ( ! PermUtil.has(player, permissionNode, true))
|
||||||
{
|
{
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return false;
|
return false;
|
||||||
@ -201,17 +204,35 @@ public class SignUtil
|
|||||||
return lines;
|
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)
|
public static List<String> getSpecialPillarLines(PlayerInteractEvent event, String title)
|
||||||
{
|
{
|
||||||
|
// Arguments
|
||||||
if (event == null) throw new NullPointerException("event");
|
if (event == null) throw new NullPointerException("event");
|
||||||
if (title == null) throw new NullPointerException("title");
|
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();
|
Block block = event.getClickedBlock();
|
||||||
if (block == null) return null;
|
if (block == null) return null;
|
||||||
|
|
||||||
|
// Lines
|
||||||
List<String> lines = getSpecialPillarLines(block, title);
|
List<String> lines = getSpecialPillarLines(block, title);
|
||||||
if (lines == null) return null;
|
if (lines == null) return null;
|
||||||
|
|
||||||
|
// Cancel
|
||||||
|
event.setCancelled(true);
|
||||||
|
|
||||||
|
// Return
|
||||||
return lines;
|
return lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -244,7 +265,7 @@ public class SignUtil
|
|||||||
public static Sign getSign(Block block)
|
public static Sign getSign(Block block)
|
||||||
{
|
{
|
||||||
BlockState blockState = block.getState();
|
BlockState blockState = block.getState();
|
||||||
if (!(blockState instanceof Sign)) return null;
|
if ( ! (blockState instanceof Sign)) return null;
|
||||||
return (Sign)blockState;
|
return (Sign)blockState;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -286,6 +307,5 @@ public class SignUtil
|
|||||||
|
|
||||||
return new ArrayList<String>(Arrays.asList(sign.getLines()));
|
return new ArrayList<String>(Arrays.asList(sign.getLines()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user