Skip to content

Commit

Permalink
修复bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Iseason committed Oct 23, 2020
1 parent 55cc039 commit 67f8a08
Show file tree
Hide file tree
Showing 17 changed files with 39 additions and 48 deletions.
Binary file modified .gradle/6.1/executionHistory/executionHistory.bin
Binary file not shown.
Binary file modified .gradle/6.1/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified .gradle/6.1/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/6.1/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified .gradle/6.1/javaCompile/classAnalysis.bin
Binary file not shown.
Binary file modified .gradle/6.1/javaCompile/javaCompile.lock
Binary file not shown.
Binary file modified .gradle/6.1/javaCompile/taskHistory.bin
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file modified .gradle/checksums/checksums.lock
Binary file not shown.
Binary file modified .gradle/checksums/sha1-checksums.bin
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockBurnEvent;
import org.bukkit.event.block.BlockExplodeEvent;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
Expand Down
28 changes: 7 additions & 21 deletions src/main/java/top/iseason/steelSafe/CreateCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,13 @@
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;


import org.bukkit.util.BlockIterator;

import org.bukkit.entity.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import static org.bukkit.Material.*;
import static top.iseason.steelSafe.OpenWithKey.isLocked;
import static top.iseason.steelSafe.OpenWithKey.targetCheck;


public class CreateCommand implements CommandExecutor, TabExecutor {
Expand All @@ -46,22 +41,13 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
sender.sendMessage(ChatColor.DARK_RED + "获取玩家" + Name + "失败,请确认玩家是否在线!");
return false;
}
Block targetBlock = getLookingAtBlock((Player) sender);
if (targetBlock.getType() != CHEST && targetBlock.getType() != TRAPPED_CHEST) {
String message = Main.getInstance().getConfig().getString("NotChest");
sender.sendMessage(ChatColor.translateAlternateColorCodes('&',message));
return true;
}
if (!Dependency.pluginCheck(targetBlock, ((Player) sender).getPlayer())) {
String Message = Main.getInstance().getConfig().getString("HaveNoPermission");
sender.sendMessage(ChatColor.translateAlternateColorCodes('&',Message));
Block targetBlock = ((Player) sender).getTargetBlock(null,5);
if(targetCheck(targetBlock,(Player)sender)){
return true;
}
String World = targetBlock.getWorld().getName();
BlockFace chestface = OpenCheck.getRelativeChestFace(targetBlock);
FileConfiguration steelSafeList = Main.getSteelSafesList();


if (chestface != null) {
Block relativechest = targetBlock.getRelative(chestface);
String data1 = World + "," + targetBlock.getLocation().getBlockX() + "," + targetBlock.getLocation().getBlockY() + "," + targetBlock.getLocation().getBlockZ();
Expand Down Expand Up @@ -188,7 +174,7 @@ private boolean createCheck(CommandSender sender, String arg, String data, Strin
return true;
}


/*todo:检查可用性,如果必须则启用。
public static Block getLookingAtBlock(Player event) { //获取玩家所看的方块
BlockIterator iter = new BlockIterator(event, 5);
Block lastBlock = iter.next();
Expand All @@ -197,9 +183,9 @@ public static Block getLookingAtBlock(Player event) { //获取玩家所看的
if (lastBlock.getType() == AIR || lastBlock.isLiquid()) //忽略空气和液体
continue;
break;
}
};
return lastBlock;
}
}*/

}

3 changes: 2 additions & 1 deletion src/main/java/top/iseason/steelSafe/Dependency.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import com.sk89q.worldguard.bukkit.WorldGuardPlugin;


import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -62,6 +61,8 @@ public static boolean pluginCheck(Block block, Player player) {
if (!(plot.isOwner(uuid) || plot.getTrusted().contains(uuid) || plot.getMembers().contains(uuid))) {
return false;
}
}else{
return false;
}
}
if (worldguard != null) {
Expand Down
1 change: 0 additions & 1 deletion src/main/java/top/iseason/steelSafe/Main.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package top.iseason.steelSafe;

import com.plotsquared.core.command.Chat;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.configuration.file.FileConfiguration;
Expand Down
16 changes: 7 additions & 9 deletions src/main/java/top/iseason/steelSafe/OpenCheck.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,18 @@
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEvent;


import static org.bukkit.Material.CHEST;
import static org.bukkit.Material.TRAPPED_CHEST;
import static org.bukkit.event.block.Action.RIGHT_CLICK_BLOCK;
import static top.iseason.steelSafe.OpenWithKey.isLocked;
import static top.iseason.steelSafe.CreateCommand.getLookingAtBlock;


public class OpenCheck implements Listener {
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void openChestCheck(PlayerInteractEvent e) { //todo:在打开的瞬间移开可能会绕过取消事件,待解决。
if (e.getAction() == RIGHT_CLICK_BLOCK && ((e.getClickedBlock().getType() == CHEST) || (e.getClickedBlock().getType() == TRAPPED_CHEST))) {
FileConfiguration steelSafeList = Main.getSteelSafesList();
Block targetBlock = getLookingAtBlock(e.getPlayer());
Block targetBlock = e.getClickedBlock();
if (targetBlock.getType() != CHEST && targetBlock.getType() != TRAPPED_CHEST) {
e.getPlayer().closeInventory();
e.setCancelled(true);
Expand All @@ -41,8 +39,8 @@ public void openChestCheck(PlayerInteractEvent e) { //todo:在打开的瞬间
}
e.getPlayer().closeInventory();
e.setCancelled(true);
String message = Message.replace(Main.getInstance().getConfig().getString("TryToOpen"),"%player%",steelSafeList.getString(data1.concat(".owner"))) ;
e.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&',message));
String message = Message.replace(Main.getInstance().getConfig().getString("TryToOpen"), "%player%", steelSafeList.getString(data1.concat(".owner")));
e.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', message));
return;
}
return;
Expand All @@ -54,8 +52,8 @@ public void openChestCheck(PlayerInteractEvent e) { //todo:在打开的瞬间
}
e.getPlayer().closeInventory();
e.setCancelled(true);
String message = Message.replace(Main.getInstance().getConfig().getString("TryToOpen"),"%player%",steelSafeList.getString(data1.concat(".owner"))) ;
e.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&',message));
String message = Message.replace(Main.getInstance().getConfig().getString("TryToOpen"), "%player%", steelSafeList.getString(data1.concat(".owner")));
e.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', message));
return;
} else if (isLocked(relativechest)) {
if (Main.getInstance().getConfig().getBoolean("OpOpen")) {
Expand All @@ -64,8 +62,8 @@ public void openChestCheck(PlayerInteractEvent e) { //todo:在打开的瞬间
e.getPlayer().closeInventory();
e.setCancelled(true);
String data2 = World + "," + relativechest.getLocation().getBlockX() + "," + relativechest.getLocation().getBlockY() + "," + relativechest.getLocation().getBlockZ();
String message = Message.replace(Main.getInstance().getConfig().getString("TryToOpen"),"%player%",steelSafeList.getString(data2.concat(".owner"))) ;
e.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&',message));
String message = Message.replace(Main.getInstance().getConfig().getString("TryToOpen"), "%player%", steelSafeList.getString(data2.concat(".owner")));
e.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', message));
return;
}
}
Expand Down
35 changes: 21 additions & 14 deletions src/main/java/top/iseason/steelSafe/OpenWithKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,13 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
if (args.length != 1) {
return false;
}
Block targetBlock = CreateCommand.getLookingAtBlock((Player) sender);
if (targetBlock.getType() != CHEST && targetBlock.getType() != TRAPPED_CHEST) {
String message = Main.getInstance().getConfig().getString("NotChest");
sender.sendMessage(ChatColor.translateAlternateColorCodes('&',message));
return true;
}
if (!Dependency.pluginCheck(targetBlock, ((Player) sender).getPlayer())) {
String message = Main.getInstance().getConfig().getString("HaveNoPermission");
sender.sendMessage(ChatColor.translateAlternateColorCodes('&',message));

Block targetBlock = ((Player) sender).getTargetBlock(null, 5);
if (targetCheck(targetBlock, (Player) sender)) {
return true;
}
BlockFace chestface = OpenCheck.getRelativeChestFace(targetBlock);
if (!isLocked(targetBlock)) {
String unLocked = ChatColor.translateAlternateColorCodes('&',Main.getInstance().getConfig().getString("UnLocked"));
String unLocked = ChatColor.translateAlternateColorCodes('&', Main.getInstance().getConfig().getString("UnLocked"));

if (chestface == null) {
sender.sendMessage(unLocked);
Expand All @@ -53,7 +45,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
return removeChestWithCommand(sender, relative);
} else {
String message = Main.getInstance().getConfig().getString("PassWordError");
sender.sendMessage(ChatColor.translateAlternateColorCodes('&',message));
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', message));
return true;
}
}
Expand All @@ -62,7 +54,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
return removeChestWithCommand(sender, targetBlock);
} else {
String message = Main.getInstance().getConfig().getString("PassWordError");
sender.sendMessage(ChatColor.translateAlternateColorCodes('&',message));
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', message));
return true;
}
}
Expand All @@ -76,7 +68,7 @@ public static boolean removeChestWithCommand(CommandSender sender, Block targetB
return true;
}
String message = Main.getInstance().getConfig().getString("PassWordCorrect");
sender.sendMessage(ChatColor.translateAlternateColorCodes('&',message));
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', message));
return true;
}

Expand Down Expand Up @@ -120,4 +112,19 @@ public static boolean isLocked(Block block) {
return steelSafeList.contains(key);

}

public static boolean targetCheck(Block targetBlock, Player player) {//检查是否具有目标的权限
if (targetBlock.getType() != CHEST && targetBlock.getType() != TRAPPED_CHEST) {
String message = Main.getInstance().getConfig().getString("NotChest");
player.sendMessage(ChatColor.translateAlternateColorCodes('&', message));
return true;
}
if (!Dependency.pluginCheck(targetBlock, player)) {
String message = Main.getInstance().getConfig().getString("HaveNoPermission");
player.sendMessage(ChatColor.translateAlternateColorCodes('&', message));

return true;
}
return false;
}
}
3 changes: 2 additions & 1 deletion src/main/java/top/iseason/steelSafe/RemoveCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class RemoveCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender.isOp() | sender.hasPermission("steelsafe.admin")) {
Block targetBlock = CreateCommand.getLookingAtBlock((Player) sender);
Block targetBlock = ((Player) sender).getTargetBlock(null,5);
if (targetBlock.getType() == CHEST || targetBlock.getType() == TRAPPED_CHEST) {
if (isLocked(targetBlock)) {
return removeChestWithCommand(sender, targetBlock);
Expand Down Expand Up @@ -51,4 +51,5 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
return true;
}
}

}

0 comments on commit 67f8a08

Please sign in to comment.