Skip to content

Commit

Permalink
update to 1.14-pre5
Browse files Browse the repository at this point in the history
  • Loading branch information
cyilin committed Apr 24, 2019
1 parent d7abd80 commit 48fc7c3
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ deploy:
provider: releases
api_key: $GITHUB_KEY
file:
- build/libs/LockettePro-2.9.${TRAVIS_BUILD_NUMBER}-1.13.2.jar
- build/libs/LockettePro-2.9.${TRAVIS_BUILD_NUMBER}-1.14-pre5.jar
on:
tags: false
skip_cleanup: true
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apply plugin: 'java'
sourceCompatibility = 1.8
targetCompatibility = 1.8

version = "2.9.%s-1.13.2"
version = "2.9.%s-1.14-pre5"

if (System.getenv("TRAVIS_BUILD_NUMBER") != null) {
project.version = String.format(project.version, System.getenv("TRAVIS_BUILD_NUMBER"))
Expand Down Expand Up @@ -41,7 +41,7 @@ repositories {
}

dependencies {
compile 'org.bukkit:bukkit:1.13.2-R0.1-SNAPSHOT'
compile 'org.bukkit:bukkit:1.14-pre5-SNAPSHOT'
compile('net.milkbowl.vault:VaultAPI:1.7') {
transitive = false
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package me.crafter.mc.lockettepro;

import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.Tag;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -36,7 +36,7 @@ public void onDebugClick(PlayerInteractEvent event){

p.sendMessage("Block: " + b.getType().toString() + " " + b.getData());

if (b.getType() == Material.WALL_SIGN){
if (Tag.WALL_SIGNS.isTagged(b.getType())){
for (String line : ((Sign)b.getState()).getLines()){
p.sendMessage(ChatColor.GREEN + line);
}
Expand Down
19 changes: 10 additions & 9 deletions src/main/java/me/crafter/mc/lockettepro/BlockPlayerListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.Tag;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -35,7 +36,7 @@ public void onPlayerQuickLockChest(PlayerInteractEvent event){
Action action = event.getAction();
Player player = event.getPlayer();
// Check action correctness
if (action == Action.RIGHT_CLICK_BLOCK && player.getInventory().getItemInMainHand().getType() == Material.SIGN){
if (action == Action.RIGHT_CLICK_BLOCK && Tag.SIGNS.isTagged(player.getInventory().getItemInMainHand().getType())) {
if (player.getGameMode().equals(GameMode.SPECTATOR)) {
return;
}
Expand Down Expand Up @@ -67,15 +68,15 @@ public void onPlayerQuickLockChest(PlayerInteractEvent event){
// Send message
Utils.sendMessages(player, Config.getLang("locked-quick"));
// Put sign on
Block newsign = Utils.putSignOn(block, blockface, Config.getDefaultPrivateString(), player.getName());
Block newsign = Utils.putSignOn(block, blockface, Config.getDefaultPrivateString(), player.getName(), player.getInventory().getItemInMainHand().getType());
Utils.resetCache(block);
// Cleanups - UUID
if (Config.isUuidEnabled()){
Utils.updateLineByPlayer(newsign, 1, player);
}
// Cleanups - Expiracy
if (Config.isLockExpire()){
if (player.hasPermission("lockettepro.noexpire")){
if (Config.isLockExpire()) {
if (player.hasPermission("lockettepro.noexpire")) {
Utils.updateLineWithTime(newsign, true); // set created to -1 (no expire)
} else {
Utils.updateLineWithTime(newsign, false); // set created to now
Expand All @@ -86,12 +87,12 @@ public void onPlayerQuickLockChest(PlayerInteractEvent event){
// Not locked, (is locked door nearby), is owner of locked door nearby
Utils.removeASign(player);
Utils.sendMessages(player, Config.getLang("additional-sign-added-quick"));
Utils.putSignOn(block, blockface, Config.getDefaultAdditionalString(), "");
Utils.putSignOn(block, blockface, Config.getDefaultAdditionalString(), "", player.getInventory().getItemInMainHand().getType());
Dependency.logPlacement(player, block.getRelative(blockface));
} else if (LocketteProAPI.isOwner(block, player)){
} else if (LocketteProAPI.isOwner(block, player)) {
// Locked, (not locked door nearby), is owner of locked block
Utils.removeASign(player);
Utils.putSignOn(block, blockface, Config.getDefaultAdditionalString(), "");
Utils.putSignOn(block, blockface, Config.getDefaultAdditionalString(), "", player.getInventory().getItemInMainHand().getType());
Utils.sendMessages(player, Config.getLang("additional-sign-added-quick"));
Dependency.logPlacement(player, block.getRelative(blockface));
} else {
Expand All @@ -106,7 +107,7 @@ public void onPlayerQuickLockChest(PlayerInteractEvent event){
// Manual protection
@EventHandler(priority = EventPriority.NORMAL)
public void onManualLock(SignChangeEvent event){
if (event.getBlock().getType() != Material.WALL_SIGN) return;
if (!Tag.WALL_SIGNS.isTagged(event.getBlock().getType())) return;
String topline = event.getLine(0);
Player player = event.getPlayer();
/* Issue #46 - Old version of Minecraft trim signs in unexpected way.
Expand Down Expand Up @@ -177,7 +178,7 @@ public void onManualLock(SignChangeEvent event){
// Player select sign
@EventHandler(priority = EventPriority.LOW)
public void playerSelectSign(PlayerInteractEvent event){
if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getType() == Material.WALL_SIGN){
if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.hasBlock() && Tag.WALL_SIGNS.isTagged(event.getClickedBlock().getType())) {
Block block = event.getClickedBlock();
Player player = event.getPlayer();
if (!player.hasPermission("lockettepro.edit")) return;
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/me/crafter/mc/lockettepro/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.Tag;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin;
Expand Down Expand Up @@ -144,7 +145,8 @@ public static void reload(){
}
}
}
lockables.remove(Material.WALL_SIGN);
lockables.removeAll(Tag.SIGNS.getValues());
lockables.remove(Material.SCAFFOLDING);
}

public static void initDefaultConfig(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class DependencyProtocolLib {

public static void setUpProtocolLib(Plugin plugin){
switch (LockettePro.getBukkitVersion()){
case v1_13_R2:
case v1_14_R1:
addTileEntityDataListener(plugin);
addMapChunkListener(plugin);
break;
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/me/crafter/mc/lockettepro/LockettePro.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.Tag;
import org.bukkit.block.Block;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
Expand Down Expand Up @@ -31,8 +30,7 @@ public void onEnable(){
getLogger().warning("===================================");
getLogger().warning("Unsupported server version: " + Bukkit.getBukkitVersion());
try {
Tag.ANVIL.getValues();
Material.TRIDENT.isItem();
Material.BARREL.isItem();
} catch (Exception e) {
setEnabled(false);
getLogger().warning("This plugin is not compatible with your server version!");
Expand Down
20 changes: 9 additions & 11 deletions src/main/java/me/crafter/mc/lockettepro/LocketteProAPI.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package me.crafter.mc.lockettepro;

import org.bukkit.Effect;
import org.bukkit.Material;
import org.bukkit.Tag;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.Container;
Expand Down Expand Up @@ -210,12 +208,8 @@ public static boolean isOwnerOfSign(Block block, Player player){ // Requires isS
public static boolean isLockable(Block block){
Material material = block.getType();
//Bad blocks
switch (material){
case SIGN:
case WALL_SIGN:
if(Tag.SIGNS.isTagged(material)){
return false;
default:
break;
}
if (Config.isLockable(material)){ // Directly lockable
return true;
Expand Down Expand Up @@ -313,8 +307,12 @@ public static boolean mayInterfere(Block block, Player player){
// End temp workaround bad code for checking up and down signs
case CHEST:
case TRAPPED_CHEST:
case WALL_SIGN:
case SIGN:
case OAK_WALL_SIGN:
case SPRUCE_SIGN:
case BIRCH_SIGN:
case JUNGLE_SIGN:
case ACACIA_SIGN:
case DARK_OAK_SIGN:
for (BlockFace blockface : allfaces){
Block newblock = block.getRelative(blockface);
switch (newblock.getType()){
Expand Down Expand Up @@ -356,7 +354,7 @@ public static boolean mayInterfere(Block block, Player player){
}

public static boolean isSign(Block block){
return block.getType() == Material.WALL_SIGN;
return Tag.WALL_SIGNS.isTagged(block.getType());
}

public static boolean isLockSign(Block block){
Expand Down
51 changes: 37 additions & 14 deletions src/main/java/me/crafter/mc/lockettepro/Utils.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package me.crafter.mc.lockettepro;

import com.comphenix.protocol.wrappers.WrappedChatComponent;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.Tag;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.Sign;
Expand All @@ -21,19 +25,33 @@
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.*;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

public class Utils {

public static final String usernamepattern = "^[a-zA-Z0-9_]*$";

private static Map<Player, Block> selectedsign = new HashMap<Player, Block>();
private static Set<Player> notified = new HashSet<Player>();

private static LoadingCache<UUID, Block> selectedsign = CacheBuilder.newBuilder()
.expireAfterAccess(30, TimeUnit.SECONDS)
.build(new CacheLoader<UUID, Block>() {
public Block load(UUID key) {
return null;
}
});
private static Set<UUID> notified = new HashSet<>();

// Helper functions
public static Block putSignOn(Block block, BlockFace blockface, String line1, String line2){
public static Block putSignOn(Block block, BlockFace blockface, String line1, String line2, Material material) {
Block newsign = block.getRelative(blockface);
newsign.setType(Material.WALL_SIGN);
Material blockType = Material.getMaterial(material.name().replace("_SIGN", "_WALL_SIGN"));
if (blockType != null && Tag.WALL_SIGNS.isTagged(blockType)) {
newsign.setType(blockType);
} else {
newsign.setType(Material.OAK_WALL_SIGN);
}
BlockData data = newsign.getBlockData();
if(data instanceof Directional){
((Directional) data).setFacing(blockface);
Expand Down Expand Up @@ -65,13 +83,18 @@ public static void removeASign(Player player){
public static void updateSign(Block block){
((Sign)block.getState()).update();
}

public static Block getSelectedSign(Player player){
return selectedsign.get(player);

public static Block getSelectedSign(Player player) {
Block b = selectedsign.getIfPresent(player.getUniqueId());
if (b != null && !player.getWorld().getName().equals(b.getWorld().getName())) {
selectedsign.invalidate(player.getUniqueId());
return null;
}
return b;
}

public static void selectSign(Player player, Block block){
selectedsign.put(player, block);
selectedsign.put(player.getUniqueId(), block);
}

public static void playLockEffect(Player player, Block block){
Expand All @@ -90,10 +113,10 @@ public static void sendMessages(CommandSender sender, String messages){
}

public static boolean shouldNotify(Player player){
if (notified.contains(player)){
if (notified.contains(player.getUniqueId())){
return false;
} else {
notified.add(player);
notified.add(player.getUniqueId());
return true;
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/me/crafter/mc/lockettepro/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

public enum Version {

v1_13_R2,
LEGACY, UNKNOWN;

v1_14_R1, UNKNOWN;

}
3 changes: 3 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ timer-signs:
lockables:
- CHEST
- TRAPPED_CHEST
- BARREL
- FURNACE
- SMOKER
- BLAST_FURNACE
- HOPPER
- BREWING_STAND
- DIAMOND_BLOCK
Expand Down

0 comments on commit 48fc7c3

Please sign in to comment.