Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions src/me/crafter/mc/lockettepro/BlockPlayerListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,94 @@
import org.bukkit.material.Openable;

public class BlockPlayerListener implements Listener {

// Quick protect for chests v2

@EventHandler(priority = EventPriority.HIGH)
public void onPlayerQuickLockChest2(BlockPlaceEvent event){
// Fallback check
if (Config.useOldInteractHandle()) return;

if (event.isCancelled()) return;

Bukkit.broadcastMessage(System.currentTimeMillis() + " " + event.getPlayer().getName() + " " + event.getBlock().getType() + " Sneak:" + event.getPlayer().isSneaking() );
// Check quick-protect is enabled
if (Config.getQuickProtectAction() == (byte)0) return;
Bukkit.broadcastMessage("Pass - quick protect");

// Check block correctness
Block block = event.getBlock();
if (block == null || block.getType() != Material.WALL_SIGN) return;
Bukkit.broadcastMessage("Pass - correctness");

// Check action correctness
Player player = event.getPlayer();
if (!((player.isSneaking() && Config.getQuickProtectAction() == (byte)2) ||
(!player.isSneaking() && Config.getQuickProtectAction() == (byte)1))) return;
Bukkit.broadcastMessage("Pass - action");

// Check permission
if (!player.hasPermission("lockettepro.lock")) return;
Bukkit.broadcastMessage("Pass - perms");


// Check permission on block
// Ignored for now because other plugin will handle this
// Check permission on relative block
Block target = LocketteProAPI.getAttachedBlock(block);
if (Dependency.isProtectedFrom(target, player)) return;
Bukkit.broadcastMessage("Pass - target");

// Check whether this block is lockable
if (!LocketteProAPI.isLockable(block)) return;
Bukkit.broadcastMessage("Pass - lockable");

// Start trying to lock the block
boolean locked = LocketteProAPI.isLocked(target);
if (!locked && !LocketteProAPI.isUpDownLockedDoor(block)){
// Not locked, not a locked door nearby
// Send message
Utils.sendMessages(player, Config.getLang("locked-quick"));
// Set sign lines
Utils.setSignLine(block, 0, Config.getDefaultPrivateString());
Utils.setSignLine(block, 1, player.getName());
Utils.resetCache(block); Utils.resetCache(target);
// Cleanups - UUID
if (Config.isUuidEnabled()){
Utils.updateLineByPlayer(block, 1, player);
}
// Cleanups - Expiracy
if (Config.isLockExpire()){
if (player.hasPermission("lockettepro.noexpire")){
Utils.updateLineWithTime(block, true); // set created to -1 (no expire)
} else {
Utils.updateLineWithTime(block, false); // set created to now
}
}
} else if (!locked && LocketteProAPI.isOwnerUpDownLockedDoor(block, player)){
// Not locked, (is locked door nearby), is owner of locked door nearby
Utils.sendMessages(player, Config.getLang("additional-sign-added-quick"));
// Set sign lines
Utils.setSignLine(block, 0, Config.getDefaultAdditionalString());
} else if (LocketteProAPI.isOwner(block, player)){
// Locked, (not locked door nearby), is owner of locked block
Utils.sendMessages(player, Config.getLang("additional-sign-added-quick"));
// Set sign lines
Utils.setSignLine(block, 0, Config.getDefaultAdditionalString());
} else {
// Cannot lock this block
Utils.sendMessages(player, Config.getLang("cannot-lock-quick"));
}
}

// Quick protect for chests
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerQuickLockChest(PlayerInteractEvent event){
// Fallback check
if (!Config.useOldInteractHandle()) return;

if (event.isCancelled()) return;

// Check quick lock enabled
if (Config.getQuickProtectAction() == (byte)0) return;
// Get player and action info
Expand Down
6 changes: 6 additions & 0 deletions src/me/crafter/mc/lockettepro/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public class Config {
private static String lockexpirestring = "";
private static Set<String> protectionexempt = new HashSet<String>();

private static boolean oldinteracthandle = false;

public Config(Plugin _plugin){
plugin = _plugin;
reload();
Expand Down Expand Up @@ -287,4 +289,8 @@ public static boolean isProtectionExempted(String against){
return protectionexempt.contains(against);
}

public static boolean useOldInteractHandle(){
return oldinteracthandle;
}

}
17 changes: 17 additions & 0 deletions src/me/crafter/mc/lockettepro/DependencyProtocolLib.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package me.crafter.mc.lockettepro;

import java.util.ArrayList;
import java.util.List;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;

import com.comphenix.protocol.PacketType;
Expand All @@ -16,8 +18,11 @@
import com.comphenix.protocol.wrappers.nbt.NbtFactory;

public class DependencyProtocolLib {

public static List<Player> signqueue = new ArrayList<Player>();

public static void setUpProtocolLib(Plugin plugin){
addOpenSignEditorListener(plugin);
switch (LockettePro.getBukkitVersion()){
case v1_8_R1:
case v1_8_R2:
Expand Down Expand Up @@ -63,6 +68,18 @@ public static void cleanUpProtocolLib(Plugin plugin){
}
}

public static void addOpenSignEditorListener(Plugin plugin){
ProtocolLibrary.getProtocolManager().getAsynchronousManager().registerAsyncHandler(new PacketAdapter(plugin, ListenerPriority.LOW, PacketType.Play.Server.OPEN_SIGN_EDITOR) {
@Override
public void onPacketSending(PacketEvent event) {
Player player = event.getPlayer();
signqueue.add(player);
try {Thread.sleep(25);} catch (Exception e) {e.printStackTrace();}
if (signqueue.remove(player) == false) event.setCancelled(true);
}
}).start();
}

public static void addUpdateSignListener(Plugin plugin){
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(plugin, ListenerPriority.LOW, PacketType.Play.Server.UPDATE_SIGN) {
@Override
Expand Down
7 changes: 5 additions & 2 deletions src/me/crafter/mc/lockettepro/LockettePro.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class LockettePro extends JavaPlugin {
private boolean debug = false;
private static Version version = Version.UNKNOWN;
private static boolean needcheckhand = false;
public static boolean protocollib = false;

public void onEnable(){
plugin = this;
Expand Down Expand Up @@ -53,13 +54,15 @@ public void onEnable(){
break;
}
// If UUID is not enabled, UUID listener won't register
if (Config.isUuidEnabled() || Config.isLockExpire()){
if (Config.getQuickProtectAction() != (byte)0 || Config.isUuidEnabled() || Config.isLockExpire()){
if (Bukkit.getPluginManager().getPlugin("ProtocolLib") != null){
DependencyProtocolLib.setUpProtocolLib(this);
getServer().getPluginManager().registerEvents(new SignSendListener(), this);
protocollib = true;
} else {
plugin.getLogger().info("ProtocolLib is not found!");
plugin.getLogger().info("UUID & expiracy support requires ProtocolLib, or else signs will be ugly!");
plugin.getLogger().info("It is recommended to use ProtocolLib if you have quick-protect, UUID support or sign expiry enabled.");
protocollib = false;
}
}
// Metrics
Expand Down