Skip to content

Commit

Permalink
finally fix dropping
Browse files Browse the repository at this point in the history
  • Loading branch information
boonsboos committed Oct 3, 2021
1 parent c863a01 commit 42967d3
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dependencies {
}

shadowJar {
version '1.0'
version '1.0.1'
archiveBaseName.set('ShogiCraft')
archiveClassifier.set("")
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void movePiece(PlayerInteractEvent event) {
//if a player is not sneaking, run normal moves or drops
if (!event.getPlayer().isSneaking()) {
if (checker.getClickedTileWithinBoard(event.getClickedBlock().getLocation(), CommandHandler.boardList.get(event.getPlayer().getUniqueId()).getBoard()) != null && !isInList(event.getPlayer().getUniqueId()+"1")) {
if (event.getPlayer().getInventory().getItemInMainHand().getType() == Material.PAPER && customModelDataInfo.contains(event.getPlayer().getActiveItem().getItemMeta().getCustomModelData())) {
if (event.getPlayer().getInventory().getItemInMainHand().getType() == Material.PAPER && customModelDataInfo.contains(event.getPlayer().getInventory().getItemInMainHand().getItemMeta().getCustomModelData())) {

game.drop(
checker.getClickedTileWithinBoard(
Expand All @@ -66,8 +66,6 @@ public void movePiece(PlayerInteractEvent event) {
event.getPlayer().getUniqueId()
);

event.getPlayer().getInventory().getItemInMainHand().subtract();

} else {

clickedTileList.put(event.getPlayer().getUniqueId() + "1", checker.getClickedTileWithinBoard(event.getClickedBlock().getLocation(), CommandHandler.boardList.get(event.getPlayer().getUniqueId()).getBoard()));
Expand Down
27 changes: 21 additions & 6 deletions src/main/java/xyz/mrsherobrine/ShogiCraft/shogi/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ public void move(Player player, boolean sneaking, Tile[][] board) {
&& canPromote(from, to, board, player)) {

//check if piece belongs to player who's moving
if (to.getPiece() != null && to.getPiece().getEntity().getPersistentDataContainer().get(ArmorStandCreator.ownerKey, PersistentDataType.STRING).equals(from.getPiece().getEntity().getPersistentDataContainer().get(ArmorStandCreator.ownerKey, PersistentDataType.STRING))) {
/*if (to.getPiece() != null && to.getPiece().getEntity().getPersistentDataContainer().get(ArmorStandCreator.ownerKey, PersistentDataType.STRING).equals(from.getPiece().getEntity().getPersistentDataContainer().get(ArmorStandCreator.ownerKey, PersistentDataType.STRING))) {
player.sendMessage(Component.text("You can't take your own pieces!", NamedTextColor.RED));
return;
}
}*/

if (to.getPiece() != null) {
capture(to.getPiece().getType(), player.getUniqueId());
Expand Down Expand Up @@ -91,10 +91,10 @@ && canPromote(from, to, board, player)) {
&& from.getPiece().canMove(from, to, player.getUniqueId())
&& CommandHandler.turns.get(player.getUniqueId())) {

if (to.getPiece() != null && to.getPiece().getEntity().getPersistentDataContainer().get(ArmorStandCreator.ownerKey, PersistentDataType.STRING).equals(from.getPiece().getEntity().getPersistentDataContainer().get(ArmorStandCreator.ownerKey, PersistentDataType.STRING))) {
/*if (to.getPiece() != null && to.getPiece().getEntity().getPersistentDataContainer().get(ArmorStandCreator.ownerKey, PersistentDataType.STRING).equals(from.getPiece().getEntity().getPersistentDataContainer().get(ArmorStandCreator.ownerKey, PersistentDataType.STRING))) {
player.sendMessage(Component.text("You can't take your own pieces!", NamedTextColor.RED));
return;
}
}*/

if (to.getPiece() != null) {
capture(to.getPiece().getType(), player.getUniqueId());
Expand Down Expand Up @@ -146,14 +146,29 @@ public void capture(PieceType type, UUID uuid) {
Component.text(" wins against " + Bukkit.getPlayer(CommandHandler.challenges.get(p.getUniqueId())).getName() + "!", NamedTextColor.GREEN).decoration(TextDecoration.BOLD, false)
), Server.BROADCAST_CHANNEL_USERS
);

p.sendMessage(Component.text("Boards have been cleared!"));

CommandHandler.boardList.remove(uuid);
CommandHandler.boardList.remove(CommandHandler.challenges.get(uuid));
CommandHandler.turns.remove(CommandHandler.challenges.get(uuid));
CommandHandler.turns.remove(uuid);
CommandHandler.players.remove(uuid);
CommandHandler.players.remove(CommandHandler.challenges.get(uuid));
CommandHandler.challenges.remove(CommandHandler.challenges.get(uuid));
CommandHandler.challenges.remove(uuid);
}

}

public void drop(Tile destination, int customModelData, UUID uuid) {

if (destination.getPiece() != null) {
CommandHandler.turns.replace(uuid, false);
CommandHandler.turns.replace(CommandHandler.challenges.get(uuid), true);

if (destination.getPiece() == null) {
destination.setPiece(creator.createPiece(getTypeFromTexture(customModelData), destination, uuid, CommandHandler.players.get(uuid).get()));
Bukkit.getPlayer(uuid).getInventory().getItemInMainHand().subtract();
} else {
Bukkit.getPlayer(uuid).sendMessage(Component.text("Can't drop that there!", NamedTextColor.RED));
}
Expand Down Expand Up @@ -270,7 +285,7 @@ public boolean canPromote(Tile from, Tile to, Tile[][] board, Player player) {

List<Location> l = new ArrayList<>();

if (CommandHandler.players.get(player.getUniqueId()) == Side.SENTE) {
if (CommandHandler.players.get(player.getUniqueId()) == Side.GOTE) {

for(int i = 0; i<3; i++) {
for (Tile tile : board[i]) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
main: 'xyz.mrsherobrine.ShogiCraft.ShogiCraft'
name: 'ShogiCraft'
description: "Allows you to play traditional Japanese shogi in Minecraft!"
version: '1.0'
version: '1.0.1'
author: 'Mrs_Herobrine_'
api-version: '1.17'
commands:
Expand All @@ -13,7 +13,7 @@ commands:
/shogi remove
/shogi challenge <player>
/shogi challenge <accept|deny>
/shogi surrender
/shogi <surrender|resign>
/shogi clear
permissions:
shogicraft.shogi:
Expand Down

0 comments on commit 42967d3

Please sign in to comment.